One of the four Android components #3-using Intent's implicit Intent to access the system app

Source: Internet
Author: User

Last introduced to you how to achieve a jump Method of the A-B in the app, this time I will introduce you to how to use the explicit intent of intent to access the system app.

1: Intent Introduction

Intent data transmission can be divided into explicit and implicit intent. explicit means that a specific Activity can jump, while implicit intent means that there is no specific Activity. You need to set the action string to jump, each app in the system has a different string. Before accessing the system app, let's give an example to understand the principle.

2: first create two Android projects and configure a filter for one Activity in the list file in Project 2. The Code is as follows:

<Activity android: name = "com. example. activity02.MainActivity "android: label =" @ string/app_name "> <intent-filter> <action android: name =" android. intent. action. MAIN "/> <category android: name =" android. intent. category. LAUNCHER "/> </intent-filter> <! -- This is our own filter condition --> <intent-filter> <action android: name = "org. second. action "/> <data android: scheme =" http "/> <data android: host =" www.baidu.com "/> <data android: mimeType = "image/jpg"/> <category android: name = "android. intent. category. DEFAULT "/> </intent-filter> </activity>

The intent-filter below is our own defined filter condition. Here we use the website as an example)

The first is name, which can be written at will. Then there is scheme. This is the beginning of the http protocol for our website, and then the host is the name of our website. The last one is type. Note that the Type format must be xxx/xxx. I define the type as jpg. Note that only one filter is written, so all the filter conditions must be met (four conditions exist here). Otherwise, the second app cannot be accessed, <categoryandroid: name = "android. intent. category. DEFAULT "/> As shown in the above Code

3: after the second app condition is written, we return to the first app, place a button in the layout, and set the button clicking event. Write all the filtering conditions and execute the jump. The specific code is as follows:

Public void onClick (View v) {// create an intent object. Because it is passed implicitly, you do not need to specify the input parameter Intent intent = new Intent (); // set intent. setAction ("org. second. action "); // If the filter condition does not have a Type, you can use the following method // intent. setData (Uri. parse ("http://www.baidu.com"); // If the filter condition has type, you must use the following method to pass in the corresponding Scheme, host and Type intent respectively. setDataAndType (Uri. parse ("http://www.baidu.com"), "image/jpg"); startActivity (intent );}

In this way, you can use an implicit intent to access the second app from the first app

4: You can search for the Android app package online. The package cannot be uploaded because the package is too large.) The package contains the filter conditions for all Android apps (find in the list file ), here I found a system app filter on the dialing interface, as shown in figure

<Intent-filter>

<Action android: name = "android. intent. action. CALL"/>

<Category android: name = "android. intent. category. DEFAULT"/>

<Data android: scheme = "tel"/>

</Intent-filter>

<Intent-filter android: icon = "@ drawable/ic_launcher_sip_call">

<Action android: name = "android. intent. action. CALL"/>

<Category android: name = "android. intent. category. DEFAULT"/>

<Data android: scheme = "sip"/>

</Intent-filter>

<Intent-filter>

<Action android: name = "android. intent. action. CALL"/>

<Category android: name = "android. intent. category. DEFAULT"/>

<Data android: scheme = "voicemail"/>

</Intent-filter>

<Intent-filter>

<Action android: name = "android. intent. action. CALL"/>

<Category android: name = "android. intent. category. DEFAULT"/>

<Data android: mimeType = "vnd. android. cursor. item/phone"/>

<Data android: mimeType = "vnd. android. cursor. item/phone_v2"/>

<Data android: mimeType = "vnd. android. cursor. item/person"/>

</Intent-filter>

Here there are four filters, and the relationship between the filters is or, so you only need to satisfy one of them. Here I am creating a project, add the top filter conditions to the intent class to access the phone interface. The specific code is as follows (here, the Action is used because the system has this constant. The above code name can also be used)

public void onClick(View v) {        Intent intent = new Intent();        intent.setAction(Intent.ACTION_DIAL);        intent.setData(Uri.parse("tel:12345"));        startActivity(intent);}

Because it is used to access the system app, do not forget to add permissions.

<Uses-permission android: name = "android. permission. CALL_PHONE"/>

5: The result of the work report is as follows:

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/1045132595-0.jpg "title =" wessaxd1_eopgquzvpj_8@bk.jpg "/>

Click the button to go to the phone page. The phone number is directly set and you can call it.

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/1045131130-1.jpg "title =" ad'r3ubn%l01f%]y'l4svxr.jpg "/>

The above is the use of intent implicit intent to access other app methods, next time I will introduce you to the android 2nd big component-Service, this program source code will be uploaded to my upload name for blog title


Related Article

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.