Bài giảng Lập trình cho thiết bị di động - Bài 4: Xử lý tiến trình và dịch vụ

1. Multi - Threading

2. Intent filter

3. Broadcast Receiver

4. Android Services

5. Webservice .Net

 

 

pptx146 trang | Chuyên mục: Android | Chia sẻ: dkS00TYs | Lượt xem: 2373 | Lượt tải: 5download
Tóm tắt nội dung Bài giảng Lập trình cho thiết bị di động - Bài 4: Xử lý tiến trình và dịch vụ, để xem tài liệu hoàn chỉnh bạn click vào nút "TẢI VỀ" ở trên
nager Example 1: cont 88 1.3 AlarmManager Example 1: cont 89 1.3 AlarmManager Example 2: PendingIntent.getService 90 1.3 AlarmManager Example 2: PendingIntent.getService 91 1.4 NotificationManager 92 1.4 NotificationManager System service alerting a user about an event Notification on Android can be done in any of the following ways: Status Bar Notification Vibrate Flash lights Play a sound We need: Notification defines the properties of the status bar notification like the icon to display, the test to display when the notification first appears on the status bar and the time to display NotificationManager android system service that executes and manages all notifications. 93 1.4 NotificationManager NotificationManager NotificationManager nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE) Create a new Notification object with an icon, a title and the time (probably System.currentTimeMillis()) Set some flags notification.defaults |= Notification.DEFAULT_SOUND; notification.defaults |= Notification.DEFAULT_VIBRATE; Use setLatestEventInfo method to set another PendingIntent into the notification. The Activity in this intent will be called when the user clicks the notification. 94 1.4 NotificationManager Step 1: Procure a handle to the NotificationManager: private NotificationManager mNotificationManager; mNotificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); Step 2: Create a notification object along with properties to display on the status bar final Notification notifyDetails = new Notification(R.drawable.android,"New Alert, Click Me!",System.currentTimeMillis()); 95 1.4 NotificationManager Step 3: Add the details that need to get displayed when the user clicks on the notification. Context context = getApplicationContext(); CharSequence contentTitle = "Notification Details..."; CharSequence contentText = "Browse Android Official Site by clicking me"; Intent notifyIntent = new Intent(Intent.ACTION_VIEW, 	Uri.parse("")); PendingIntent pintent = PendingIntent.getActivity(SimpleNotification.this, 0, notifyIntent, 	Intent.FLAG_ACTIVITY_NEW_TASK); notifyDetails.setLatestEventInfo 	(context, contentTitle, contentText, pintent); 96 1.4 NotificationManager Step 4: Now the stage is set. Notify. mNotificationManager.notify 	(SIMPLE_NOTFICATION_ID, notifyDetails); mNotificationManager.cancel 	(SIMPLE_NOTFICATION_ID); 97 1.4 NotificationManager Example : Show notification 98 1.4 NotificationManager Example : cont 99 1.4 NotificationManager Example : cont 100 5. Webservice .Net 5.1 Introduction Webservice 5.2 How to create .Net Webservice 5.3 How to config IIS 5.4 KSOAP API 5.5 Android to .Net Webservice 101 5.1 Introduction Webservice Support machine-to-machine collaboration. They can be described, published, located, and invoked over a data network. Web services are used to implement the notion of a service-oriented architecture (SOA). SOA applications are independent of specific programming languages or operating systems. Web services rely on existing transport technologies, such as HTTP, and XML, for invoking the implementation. 102 5.1 Introduction Webservice The interface describing the format of services can be done using the Web Services Description Language (WSDL). According to W3C there are two major types of web services REST-compliant which use XML to represent its Web resources, and offers a "stateless" set of operations; and Arbitrary solutions, in which the service may expose a heterogeneous set of operations. 103 5.1 Introduction Webservice Two widely used architectures supporting Web services are Representational State Transfer (REST) Closely tie to the HTTP protocol by associating its operation to the common GET, POST, PUT, DELETE for HTTP. Remote Procedure Call (RPC). Web services are directly implemented as language-specific functions or method calls. In this category we find 1.Object Management Group's (OMG) Common Object Request Broker Architecture (CORBA), 2.Microsoft's Distributed Component Object Model (DCOM) and 3.Sun Microsystems's Java/Remote Method Invocation (RMI). 104 5.1 Introduction Webservice IIS webserver (RPC discrete function oriented approach) 105 5.1 Introduction Webservice Services are passive server-side pieces of code waiting for incoming messages to do some work. Clients initiate the interaction by sending a message to server-services requesting action. Services expose one or more endpoints where messages can be sent. Each endpoint consists of address (where to send messages) binding (how to send messages ) contract (what messages contain) Clients can use WSDL to know this information before accessing a service. 106 5.1 Introduction Webservice Windows Communication Foundation (WCF) uses the information found in the service contract to perform dispatching and serialization. Dispatching is the process of deciding which method to call for an incoming SOAP message. Serialization is the process of mapping between the data found in a SOAP message and the corresponding .NET objects used in the method 107 5.2 How to create .Net Webservice 1. Create a database in SQL Server with name dbProductManager The Table Structer as below: 2. Computer Server will support some services: Get number of catalog Get list Catalog Get list product by Catalog id 3. Android application will connect to the computer Server and get information via service method (The Android Mobile will connect to Laptop by Wireless – must Win 7, Win 8) 108 5.2 How to create .Net Webservice 1- Create Webservice project with name MyProductService as below: 109 5.2 How to create .Net Webservice 2- Create Webservice class with name ProductWebService: - Right click on Project/ Add/ Web Service 110 5.2 How to create .Net Webservice 3- Write coding : For Product table For Catalog table Must use Serializable 111 5.2 How to create .Net Webservice 3- Write coding : For connection 112 5.2 How to create .Net Webservice 3- Write coding : For connection 113 5.2 How to create .Net Webservice 3- Write coding : For Webservice Namespace  will use in Android Coding 114 5.2 How to create .Net Webservice 3- Write coding : For Webservice 115 5.2 How to create .Net Webservice 3- Write coding : For Webservice 116 5.3 How to config IIS 1. In control Panel/ Click Turn Windows features on or off 2. Enable Internet Information Service (with sub configuration) then click OK 117 5.3 How to config IIS 3. Administrator tools: choose IIS 4. Add application: - Right click on Default Website Then click Add Application… 118 5.3 How to config IIS 4. Add application: Type Alias name and choose Physical path, then click OK to create 119 5.3 How to config IIS 4. Add application: See the result 120 5.3 How to config IIS 5. Config directory Browsing Double click on Directory Browsing 121 5.3 How to config IIS 5. Config directory Browsing Click Enable 122 5.3 How to config IIS 6. Test IIS Type localhost on Address bar then press enter The figure It is ok for IIS 123 5.3 How to config IIS 6. Test IIS: Now, test your ProductWebService in IIS. You could use localhost or get your computer IP. Click to Test this method 192.168.3.102 : My computer IP productwebservice : alias that I defined in IIS Productwebservice.asmx: webservice 124 5.3 How to config IIS 6. Test IIS The result are OK 125 5.4 KSOAP API KSOAP is a webservice client library for constrained Java environments. SOAP protocol is widely used for machine-to-machine interaction, it is strong-typed and supports synchronous, asynchronous, and complex-routing communication schemes. Full download:  126 5.5 Android to .Net Webservice Example 1: Get Primite Data from Computer Server Use the getNumberOfCatalog() method in Webservice 127 5.5 Android to .Net Webservice Example 1: cont 128 5.5 Android to .Net Webservice Example 1: cont 129 5.5 Android to .Net Webservice Example 2: Input Parameter, Add to PropertyInfo into SoapObject request . Use the getMoney() method in Webservice 130 5.5 Android to .Net Webservice Example 2: cont 131 5.5 Android to .Net Webservice Example 2: cont 132 5.5 Android to .Net Webservice Example 2: cont 133 5.5 Android to .Net Webservice Example 3: get complex data. Use the getListCatalog() method in Webservice 134 5.5 Android to .Net Webservice Example 3: cont 135 5.5 Android to .Net Webservice Example 3: cont 136 5.5 Android to .Net Webservice Example 3: cont 137 5.5 Android to .Net Webservice Example 4: get complex data. Use the getListProductbyCateId () method in Webservice Take yourself (exercise) 138 5.5 Android to .Net Webservice Example 5: Insert SoabObject to webservice Now in .Net, I add a new method with name insertCatalog, parameter is a catalog object 139 5.5 Android to .Net Webservice Example 5: cont Also, add execNonquery method for Connectionfactory class 140 5.5 Android to .Net Webservice Example 5: cont Please see the Soap description for insertCatalog method: 141 5.5 Android to .Net Webservice Example 5: cont SoapObject request=new SoapObject(NAMESPACE, METHOD_NAME); SoapObject newCate=new SoapObject(NAMESPACE, "cate"); newCate.addProperty("CateId", "cate4"); newCate.addProperty("CateName", "hoa chat"); request.addSoapObject(newCate); 142 5.5 Android to .Net Webservice Example 5: cont 143 5.5 Android to .Net Webservice Example 5: cont Coding to insert a new catalog 144 5.5 Android to .Net Webservice Example 5: cont 145 5.5 Android to .Net Webservice Example 6: how to connect real Android mobile Device with Computer Server (by Wireless) Many ways: 1) Using Portable wifi hotspot (AndroidAp active)- android mobile device has supports (you should use this feature) 2) Connectivity software and other software (The PC must use Win7, Win8) 3) Internet global 146 5.5 Android to .Net Webservice Example 6: cont Database + webservice in My Labtop Here is my real Phone: SamSung S2 The figure I captured by Phone& Laptop Camera Insert Cate Get list Cate Exercise: You must do that END 147 

File đính kèm:

  • pptx4 - XỬ LÝ ĐA TIẾN TRÌNH VÀ DỊCH VỤ.pptx
Tài liệu liên quan