Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống
1
/ 61 trang
THÔNG TIN TÀI LIỆU
Thông tin cơ bản
Định dạng
Số trang
61
Dung lượng
1,84 MB
Nội dung
HO CHI MINH UNIVERSITY OF INDUSTRY 1 API 1 Networking APIs 2 Multimedia APIs HO CHI MINH UNIVERSITY OF INDUSTRY 2 1. Networking APIs 1.1 Understanding Mobile Networking 1.2 Strict Mode with Networking 1.3 Accessing the Internet (HTTP) HO CHI MINH UNIVERSITY OF INDUSTRY 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 HO CHI MINH UNIVERSITY OF INDUSTRY 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 HO CHI MINH UNIVERSITY OF INDUSTRY 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 HO CHI MINH UNIVERSITY OF INDUSTRY 6 1.2 Strict Mode with Networking 1 - If not, you must write coding on a Thread other At first, this code seems to be a good solution to your problem, as it does not block the UI thread. Unfortunately, it violates the single thread model: the Android UI toolkit is not thread-safe and must always be manipulated on the UI thread. In this piece of code, the ImageView is manipulated on a worker thread, which can cause really weird problems. Tracking down and fixing such bugs can be difficult and time-consuming. HO CHI MINH UNIVERSITY OF INDUSTRY 7 1.2 Strict Mode with Networking 2 - If not, you must write coding on a Thread other Unfortunately, these classes and methods also tend to make your code more complicated and more difficult to read. It becomes even worse when your implement complex operations that require frequent UI updates. HO CHI MINH UNIVERSITY OF INDUSTRY 8 1.2 Strict Mode with Networking 3 - If not, you must write coding on a Thread other Android 1.5 offers a new utility class, called AsyncTask, that simplifies the creation of long-running tasks that need to communicate with the user interface. The goal of AsyncTask is to take care of thread management for you. HO CHI MINH UNIVERSITY OF INDUSTRY 9 1.3 Accessing the Internet (HTTP) The most common way to transfer data to and from the network is to use HTTP. You can use HTTP to encapsulate almost any type of data and to secure the data with Secure Sockets Layer (SSL) Reading Data from the Web Using HttpURLConnection Displaying Images from a Network Resource Retrieving Android Network Status Objectives: HO CHI MINH UNIVERSITY OF INDUSTRY 10 1.3 Accessing the Internet (HTTP) Reading Data from the Web <uses-permission android:name="android.permission. INTERNET"/> [...]... UNIVERSITY OF INDUSTRY 2 Multimedia APIs 2.1 Working with Multimedia 2.2 Working with the Camera 2.3 Working with Video 2.4 Working with Audio 22 HO CHI MINH UNIVERSITY OF INDUSTRY 2.1 Working with Multimedia The Android SDK provides a variety of methods for applications to incorporate audio and visual media, including support for many different media types and formats The multimedia features of the... microphone, played back with speakers or audio output) Video (recorded with the camera and microphone, played back with speakers or video output) 23 HO CHI MINH UNIVERSITY OF INDUSTRY 2.2 Working with the Camera Many Android devices... UNIVERSITY OF INDUSTRY 2.2 Working with the Camera Capturing Still Images Using the Camera You must test on Physical Mobile Device 29 HO CHI MINH UNIVERSITY OF INDUSTRY 2.2 Working with the Camera... HO CHI MINH UNIVERSITY OF INDUSTRY 1.3 Accessing the Internet (HTTP) Retrieving Android Network Status Only physical device testing can truly reveal these results 18 HO CHI MINH UNIVERSITY OF INDUSTRY 1.3 Accessing the Internet (HTTP) Retrieving Android Network... CHI MINH UNIVERSITY OF INDUSTRY 1.3 Accessing the Internet (HTTP) Displaying Images from a Network Resource 14 HO CHI MINH UNIVERSITY OF INDUSTRY 1.3 Accessing the Internet (HTTP) Displaying Images from a Network Resource 15 HO CHI MINH UNIVERSITY OF INDUSTRY 1.3 Accessing the Internet (HTTP) Displaying Images from a Network Resource... (fixed point, depth of field, infinity, …) White balance settings (fluorescent, incandescent, …) Scene modes (snow, beach, fireworks, …) Effects (photo negative, sepia, …) Anti-banding settings (noise reduction) 35 HO CHI MINH UNIVERSITY OF INDUSTRY 2.2 Working with the Camera Zooming the Camera The camera zoom setting is controlled using the startSmoothZoom() and stopSmoothZoom() methods... Objectives: Capturing Still Images Using the Camera Configuring Camera Mode Settings Working with Common Camera Parameters Zooming the Camera Sharing Images Assigning Images as Wallpapers 25 HO CHI MINH UNIVERSITY OF INDUSTRY 2.2 Working with the Camera Capturing Still Images Using the Camera The Camera object controls the camera on devices that have camera support enabled The preview... instance of the Camera object 3 In the surfaceChanged() method, configure and apply the Camera.Parameters; then call the startPreview() method 4 Add a method in CameraSurfaceView for capturing images 5 Add the CameraSurfaceView to an appropriate layout 27 HO CHI MINH UNIVERSITY OF INDUSTRY 2.2 Working with the Camera Capturing Still Images Using the Camera 6 Include some way, such as a button, for . UNIVERSITY OF INDUSTRY 1 API 1 Networking APIs 2 Multimedia APIs HO CHI MINH UNIVERSITY OF INDUSTRY 2 1. Networking APIs 1.1 Understanding Mobile Networking 1.2 Strict Mode with Networking 1.3 Accessing. for networking, to see details please click the link below: http://android-developers.blogspot.com/2009/ 05/ painless-threading.html HO CHI MINH UNIVERSITY OF INDUSTRY 6 1.2 Strict Mode with Networking 1. Strict Mode with Networking 3 - If not, you must write coding on a Thread other Android 1 .5 offers a new utility class, called AsyncTask, that simplifies the creation of long-running tasks