DONG NAI UNIVERSITY OF TECHNOLOGY
1
API
1
Networking
APIs
2
Multimedia
APIs
DONG NAI UNIVERSITY OF TECHNOLOGY
2
1. Networking APIs
1.1 Understanding Mobile Networking
1.2 Strict Mode with Networking
1.3 Accessing the Internet (HTTP)
DONG NAI UNIVERSITY OF TECHNOLOGY
3
1.1 Understanding Mobile Networking
ØNetworking on the Android platform is standardized, using
a combination of powerful yet familiar technologies and
libraries such as java.net.
ØNetwork implementation is generally straightforward,
but mobile application developers need to plan for less
stable connectivity than one might expect in a home or
office network setting—connectivity depends on the
location of the users and their devices.
Ødeveloper must take extra care when designing network-
enabled applications
DONG NAI UNIVERSITY OF TECHNOLOGY
4
1.2 Strict Mode with Networking
ØStrict mode is a method that developers can use to detect
operations performed on the main thread that should not
be there.
ØAPI Level 11 expanded upon strict mode in ways that
impact networking code. By default, if you perform
network operations on the main thread, your application
throws an exception, specifically
android.os.NetworkOnMainThreadException.
Ø2 ways to avoid this is to use proper coding techniques
and put all networking operations on a thread other than
the main thread (should use AsyncTask class).
ØOr call the permitAll() method to skip strict mode entirely
DONG NAI UNIVERSITY OF TECHNOLOGY
5
1.2 Strict Mode with Networking
ØIf you want to use networking in Main Thread, the coding:
if (android.os.Build.VERSION.SDK_INT > 10) {
StrictMode.ThreadPolicy policy = new
StrictMode.ThreadPolicy.Builder()
.permitAll().build();
StrictMode.setThreadPolicy(policy);
}
This is not recommended for production applications.
WHY?
The next slide you will learn 3 ways to create Thread for networking, to
see details please click the link below:
http://android-developers.blogspot.com/2009/05/painless-threading.html