Android: android Intent and IntentFilter, intentfilter

Source: Internet
Author: User

Android: android Intent and IntentFilter, intentfilter

Article from: http://blog.csdn.net/intbird

1. intentfilter description:

If you want to open another application of an activity, or call our own activity in webView or bybird app,
You can use intentfilter to filter the activities we need;

* Uri parameter description Java Code:

final Uri uri =  Uri.parse("intbird://com.intbird.soft/testing/tested?name='Test'");        TextView textView = (TextView)findViewById(R.id.textView);        textView.setText(uri.getScheme() + "\n" //intbird                        + uri.getPort() + "\n"  //-1                        + uri.getAuthority() + "\n" //com.intbird.soft                        + uri.getHost() + "\n"  //com.intbird.soft                        + uri.getPath() + "\n" // /testing/tested                        + uri.getPathSegments() + "\n" // [tesing,tested]                        + uri.getQuery()+"\n"); // name='Text'
Public void onClick (View v) {Intent intent = new Intent (); intent. setAction ("android. intent. action. VIEW "); intent. setData (uri); PackageManager packageManager = getPackageManager (); List <ResolveInfo> activities = packageManager. queryIntentActivities (intent, 0); boolean isIntentSafe = activities. size ()> 0; if (isIntentSafe) {startActivity (intent);} else {Toast. makeText (MainActivity. this, "Match None", Toast. LENGTH_SHORT ). show ();}}

XML Code:

NOTE: The category label must exist.
<activity            android:name=".MyIntentFilter"            android:label="@string/app_name" >            <intent-filter>                <category android:name="android.intent.category.DEFAULT"></category>                <action android:name="android.intent.action.VIEW"/>                <data android:scheme="intbird" android:host="com.intbird.soft"/>            </intent-filter>        </activity>
2. Better understanding of webpage calls

Uri:
Final Uri urihttp = Uri. parse ("https://www.baidu.com/s? Wd = intbird ");
// Schma: http
// Host: www.baidu.com
// Path:/s
// Query: wd = intbird

XML

<activity            android:name=".MyIntentFilter2"            android:label="@string/app_name" >            <intent-filter>                <category android:name="android.intent.category.DEFAULT"/>                <action android:name="android.intent.action.VIEW"/>                <data android:scheme="https"  android:host="www.baidu.com" />            </intent-filter>        </activity>

Match scheme and multiple hosts. Intent Chooser is displayed.

3. Similarly, if we have multiple activities;

If both are the same:

<activity            android:name=".MyIntentFilter"            android:label="@string/app_name" >            <intent-filter>                <category android:name="android.intent.category.DEFAULT"></category>                <action android:name="android.intent.action.SENDTO"/>                <data android:scheme="intbird" android:host="com.intbird.soft"/>            </intent-filter>        </activity>        <activity            android:name=".MyIntentFilter2"            android:label="@string/app_name" >            <intent-filter>                <category android:name="android.intent.category.DEFAULT"/>                <action android:name="android.intent.action.SENDTO"/>                <data android:scheme="intbird"  android:host="com.intbird.soft" />            </intent-filter>        </activity>

So:

But: add path [android: path = "/testing"] to one, startActivity directly

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.