Android Intent-filter Simple usage

Source: Internet
Author: User

To filter the telephone dials, the activity in the Mainfest configuration file is configured as follows:

<activity android:name= ". Testactivity "android:label=" @string/app_name ">
<intent-filter>
<action android:name= "Android.intent.action.CALL_BUTTON"/>

<category android:name= "Android.intent.category.DEFAULT"/>
</intent-filter>
</activity>
effect, click the Phone button, pop up the Select App dialog box, including our own definition of the app:




When sending a text message, call the custom app:

<activity android:name= ". Testactivity "android:label=" @string/app_name ">
<intent-filter>
<action android:name= "Android.intent.action.SENDTO"/>
<data android:scheme= "Smsto"/>
<category android:name= "Android.intent.category.DEFAULT"/>
</intent-filter>

The effect is as follows, click the Send SMS button in the friend's address book, pop up the Select App dialog box, including our custom app:



The custom program calls the Send SMS function:

Intent sendintent = new Intent (Intent.action_sendto, Uri
. Parse ("sms://"));
StartActivity (sendintent);

Also, add Intent-filter to the Mainfest configuration file to increase the intent function for sending SMS messages:

<activity android:name= ". Testactivity "android:label=" @string/app_name ">
<intent-filter>
<action android:name= "Android.intent.action.SENDTO"/>
<data android:scheme= "SMS"/>
<category android:name= "Android.intent.category.DEFAULT"/>
</intent-filter>
</activity>

The effect is as follows, click the button in your own program, call send SMS function:



Choose your own app and go to testactivity.

Intent filtering for HTTP requests:

<activity android:name= ". Testactivity "android:label=" @string/app_name ">
<intent-filter>
<action android:name= "Android.intent.action.VIEW"/>
<data android:scheme= "http"/>
<category android:name= "Android.intent.category.DEFAULT"/>
</intent-filter>
</activity>

The effect is as follows, when you click on the HTTP connection, the dialog box for selecting the app pops up:



Filter share image function to achieve:

<activity android:name= ". Testactivity "android:label=" @string/app_name ">
<intent-filter>
<action android:name= "Android.intent.action.SEND"/>
<data android:mimetype= "image/*"/>
<category android:name= "Android.intent.category.DEFAULT"/>
</intent-filter>
</activity>

This way, when you click the Share button in the photo album, the Share app selection dialog box pops up:

Android Intent-filter Simple usage

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.