标签:filter inttentfil
文章来自:http://blog.csdn.net/intbird
如果说是将一个activity有其他应用打开,或者是在webView中调用我们自己的activity,那么最好就是使用intentfilter来过滤我们需要的activity;
说明什么是uri参数
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, "匹配None", Toast.LENGTH_SHORT).show();
}
}
XML Code:
NOTE : 必须有category标签
<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>
结合一个调用网页加深理解
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>
SO:
多个匹配,弹出 Intent Chooser
android:android Intent and IntentFilter
标签:filter inttentfil
原文地址:http://blog.csdn.net/intbird/article/details/46609495