【Android 开发教程】添加Category
来源:互联网 发布:雨林木风xp优化工具 编辑:程序博客网 时间:2024/06/01 16:14
- <?xml version="1.0" encoding="utf-8"?>
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.manoel.Intents"
- android:versionCode="1"
- android:versionName="1.0" >
- <uses-sdk android:minSdkVersion="14" />
- <uses-permission android:name="android.permission.CALL_PHONE" />
- <uses-permission android:name="android.permission.INTERNET" />
- <application
- android:icon="@drawable/ic_launcher"
- android:label="@string/app_name" >
- <activity
- android:name=".IntentsActivity"
- android:label="@string/app_name" >
- <intent-filter>
- <action android:name="android.intent.action.MAIN" />
- <category android:name="android.intent.category.LAUNCHER" />
- </intent-filter>
- </activity>
- <activity
- android:name=".MyBrowserActivity"
- android:label="@string/app_name" >
- <intent-filter>
- <action android:name="android.intent.action.VIEW" />
- <action android:name="net.learn2develop.MyBrowser" />
- <category android:name="android.intent.category.DEFAULT" />
- <category android:name="com.manoel.Apps" />
- <data android:scheme="http" />
- </intent-filter>
- </activity>
- </application>
- </manifest>
- Intent i = new
- Intent(android.content.Intent.ACTION_VIEW,
- Uri.parse("http://www.amazon.com"));
- nbsp;// 注意这句代码
- i.addCategory("com.manoel.Apps");
- startActivity(Intent.createChooser(i, "Open URL using..."));
但是,如果指定了一个并没有在Intent-Filter中定义的Category,那么,将不会有Activity被调用:
- Intent i = new
- Intent(android.content.Intent.ACTION_VIEW,
- Uri.parse("http://www.amazon.com"));
- // i.addCategory("net.learn2develop.Apps");
- // 这个category不匹配Intent-Filter中的任何category
- i.addCategory("net.learn2develop.OtherApps");
- startActivity(Intent.createChooser(i, "Open URL using..."));
但是,如果在AndroidManifest.xml中添加如下代码,之前的代码就可以运行了:
- <activity android:name=".MyBrowserActivity"
- android:label="@string/app_name">
- <intent-filter>
- <action android:name="android.intent.action.VIEW" />
- <action android:name="net.learn2develop.MyBrowser" />
- <category android:name="android.intent.category.DEFAULT" />
- <category android:name="net.learn2develop.Apps" />
- <!-- 添加这句代码 -->
- <category android:name="net.learn2develop.OtherApps" />
- <data android:scheme="http" />
- </intent-filter>
- </activity>
也可以为Intent对象添加多重Category属性,举个例子:
- Intent i = new
- Intent(android.content.Intent.ACTION_VIEW,
- Uri.parse("http://www.amazon.com"));
- // 多重的Category
- i.addCategory("com.manoel.Apps");
- i.addCategory("com.manoel.OtherApps");
- i.addCategory("com.manoel.SomeOtherApps");
- startActivity(Intent.createChooser(i, "Open URL using..."));
0 0
- 【Android 开发教程】添加Category
- 【Android 开发教程】添加Category
- Android 程式开发:(四)使用Intent调用“内置”应用 —— 4.4添加Category属性
- 【Android 开发教程】动态添加Fragments
- 【Android 开发教程】添加ActionBar物件
- 【Android 开发教程】动态添加Fragments
- iOS开发之category动态添加属性的方法------关联
- iOS开发-在分类(Category)文件中添加属性
- IOS开发中Category中动态添加属性
- Android OpenGL ES 简明开发教程五:添加颜色
- Android OpenGL ES 简明开发教程五:添加颜色
- Android OpenGL ES 简明开发教程五:添加颜色
- Android OpenGL ES 简明开发教程 05 <添加颜色>
- Android开发教程:向模拟器的sdcard中添加文件
- Android OpenGL ES 简明开发教程五:添加颜色
- Android OpenGL ES 简明开发教程_添加颜色
- Android原生APP中添加ReactNative 进行混合开发教程
- Android原生APP中添加ReactNative 进行混合开发教程
- 装饰器模式
- PHP header函数设置HTTP头的示例
- 自己电脑上同时配置两个 tomcat 方法
- Convert QWERTY to Dvorak
- 如何打包swt,亲手实验过,成功
- 【Android 开发教程】添加Category
- 浩易南:谈谈流氓性格和流氓思维
- mysqlhotcopy 只能用于MyISAM表不能用户InnoDB表
- Shell基础-概述
- TPService 编译过程
- Unity NGUI——3.8.2版本更新说明
- Java学习 - synchronized同步机制
- 解题报告 之 ZOJ2332 Gems
- Linux学习之CentOS(十三)--CentOS6.4下Mysql数据库的安装与配置