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