这个功能到底怎么描述
将程序 标识为浏览器,告知系统程序 具有浏览器打开url的能力 ,可做为系统默认浏览器的一个候选项。简单的说就是俺就是个浏览器啦,大爷选我吧:D
语言是真的匮乏呀,想了好久,不知道咋描述这该死的,G老师都快搜烂了,后来脑袋一拍,去GayHub搜了个浏览器应用从该工程的的AndroidManifest.xml
扣了配置下来。
no picture say a xx ,就这描述水平还是上图吧
对的,要的是这个效果,舒坦了 简单的示例
Activity intent-filter 程序标识为浏览器
<activity android:name="xxxActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.APP_BROWSER" />
</intent-filter>
<!-- Matches the common case of intents with no MIME type.
Make sure to keep in sync with the next filter. -->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="googlechrome" />
<data android:scheme="http" />
<data android:scheme="https" />
<data android:scheme="about" />
<data android:scheme="javascript" />
</intent-filter>
<!-- Same filter as above but with MIME types. Intents that
do not specify a MIME type won't match. -->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="googlechrome" />
<data android:scheme="http" />
<data android:scheme="https" />
<data android:scheme="about" />
<data android:scheme="content" />
<data android:scheme="javascript" />
<data android:mimeType="text/html" />
<data android:mimeType="text/plain" />
<data android:mimeType="application/xhtml+xml" />
</intent-filter>
<!-- MHTML support, used for snapshots -->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="file" />
<data android:scheme="content" />
<data android:mimeType="multipart/related" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="file" />
<data android:scheme="content" />
<data android:host="*" />
<data android:pathPattern="/.*\\.mhtml" />
<data android:pathPattern="/.*\\.mht" />
</intent-filter>
<!-- Same filter as above but with mimeType="*/*". Used for
handling intent send by ShareIt. -->
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="file" />
<data android:scheme="content" />
<data android:host="*" />
<data android:mimeType="*/*" />
<data android:pathPattern="/.*\\.mhtml" />
<data android:pathPattern="/.*\\.mht" />
</intent-filter>
</activity>
Activity intent-filter 文本分享
<activity android:name="xxxActivity">
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>
配合文本分享 intent-filter
手动分享
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_TEXT, shareContent);
shareIntent.setType("text/plain");
//设置分享列表的标题,并且每次都显示分享列表
mContext.startActivity(Intent.createChooser(shareIntent, "分享到"));
获取数据
Intent intent = getIntent();
if (intent != null) {
String action = intent.getAction();
String type = intent.getType();
Uri uri = intent.getData();
// 文本分享 text/plain
if (Intent.ACTION_SEND.equals(action) && "text/plain".equals(type)) {
String text = intent.getStringExtra(Intent.EXTRA_TEXT);
//do something
}
//浏览器 text/html
if (Intent.ACTION_VIEW.equals(action) && uri != null) {
String url = uri.toString();
//do something
}
}