Android Communication Chapter

Source: Internet
Author: User

In Anroid, communication technology consists of several layers, which design various events (such as touch events, case events, trackball events, etc.) at the UI layer, design intent, meaage, etc. at the framework level, and involve bundles, RPC, shared memory and other technologies in the kernel layer. This chapter focuses on the communication mechanisms of the UI layer and the framework layer.

1.Intent Communication

Intent communication is actually the encapsulation of the Open-binder communication mechanism. In Linux, there are two inter-process communication mechanisms in D-bus and Open-binder, in which D-bus is applied more broadly. However, in Android, the use of Open-binder communication mechanism, D-bus only in the open-source BT protocol stack BlueZ to be applied.

Each intent message can consist of several attributes, such as component, action, data, Category,extras, flags, and so on.

According to whether there is a return value intent communication can be divided into a return value and no return value communication, by the receiving object can be divided into mass messages and individual messages.

In general, however, intent can only pass basic data types, and for complex data types, it is done with the help of Serializable, parcelable two interfaces.

(1) Common usage of intent

The following describes the common uses of intent for networks, maps, telephones, messages, e-mail, multimedia, systems, and more.

1) Network-related

In order to use network functionality, you need to have Android.permission.INTERNET permissions. Common network-related intent communications include display pages, Google Maps, search, and more.

In the method defined by HTTP that interacts with the server, there are two ways of initiating the request, namely get and post, where the Get method submits the data through Rul, the data is visible in the URL, the privacy is not guaranteed, and the submitted data can be up to 1024 bytes , and the Post method is to put the data in the HTML header to commit, and there is no limit on the length of the data, usually used to pass sensitive data.

Post submission data is not currently supported in intent, only the Get mode is supported. In order to open the URL, its action is Action_view, the method is as follows:

Uri uri=uri.parse ("http://www.163.com:);

Intent it=new inent (Intent.action_view,uri);

StartActivity (IT);

If you want to pass sensitive data, the method used in WebView is as follows:

public void PostURL (String URL, byte[] postdata);

Find the apps you want in a multitude of applications. You need to use the search function. The search method is implemented as follows:

Uri uri=uri.parse ("Market://seatch?q=pname:com.miaozl.hello");

Intent intent=new Intent (Intent.action_view, URI);

StartActivity (Intent);

To search for relevant information in the network, the following methods are implemented:

Intent intent=new Intent ();

Intent.setaction (Intent.action_web_search);

Intent.putextra (Searchmanager.query, "android123")

StartActivity (Intent);

2) Map related

In order to display Google Maps, you need to provide geographical latitude and longitude information, note that in the positioning, because of the location algorithm, the mobile terminal should be able to capture at least 3 satellite data, to provide basic positioning, according to the performance of the GPS chip and the scene of the difference, The actual GPS chip can capture a large number of satellites, the following is the way to display Google Maps:

Uri uri=uri.parse ("geo:38.899533,-77.036476");

Intent it=new Intent (Intent.action_view,uri);

StartActivity (IT);

The goal of GPS navigation is usually to find the best route between two points, the process of finding the best route is mathematically called path planning, and here's how to GoogleMap path planning:

Uri Uri=uri.parse (http://maps.google.com/maps?f=d&saddr=srartlat%20startlng&daddr=englat%20endlng& hl=en);

Intent it=new Intent (Intent.action_view,uri);

StartActivity (IT);

3) Phone-related

As the most basic function of mobile terminal, call nature is necessary, and call related to the function of telephone thin, the following is the way to enter the phone book:

Intent intent=new Intent ();

Intent.setaction (Intent.action_view);

Intent.setdata (People.content_uri);

StartActivity (Intent);

If you want to see a specific contact, you need to develop the ID of the associated contact, as follows:

Uri Personuri=contexturis.withappendedid (People.content_uri,id);

Intent intent=new Intent ();

Intent.setaction (INTENT.ACTION_VIRW);

Intent.setdata (Persionuri);

StartActivity (Intent);

Android Communication Chapter

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.