Android根据Data匹配隐式Intent的实例
来源:互联网 发布:js获取当前触发事件 编辑:程序博客网 时间:2024/06/18 17:28
在 AndroidManifest.xml中我们这样设置:
- <?xml version="1.0" encoding="utf-8"?>
- <manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.hebaijun.intenttest"
- android:versionCode="1"
- android:versionName="1.0" >
- <uses-sdk android:minSdkVersion="10" />
- <application
- android:icon="@drawable/ic_launcher"
- android:label="@string/app_name" >
- <activity
- android:label="@string/app_name"
- android:name=".IntentTestActivity" >
- <intent-filter >
- <action android:name="android.intent.action.MAIN" />
- <category android:name="android.intent.category.LAUNCHER" />
- </intent-filter>
- </activity>
- <activity
- android:name=".OtherActivity"
- android:label="Other Activity">
- <intent-filter >
- <action android:name="com.hebaijun.intenttest.OTHER"/>
- <category android:name="android.intent.category.DEFAULT"/>
- <data android:scheme="test" android:host="www.google.com" android:port="80"/>
- <data android:scheme="test2"/>
- <data android:mimeType="text/*" />
- </intent-filter>
- </activity>
- <activity
- android:name=".OtherActivity2"
- android:label="Other Activity 2">
- <intent-filter >
- <action android:name="com.hebaijun.intenttest.OTHER"/>
- <category android:name="android.intent.category.DEFAULT"/>
- </intent-filter>
- </activity>
- </application>
- </manifest>
调用的代码是:
- Intent intent = new Intent();
- intent.setAction("com.hebaijun.intenttest.OTHER");
- Uri data = Uri.parse("test://www.google.com:80");
- //intent.setData(data);
- intent.setDataAndType(data, "text/*");
- startActivity(intent);
- 如果设置了多个data,只要匹配一个就可以启动这个activity。
- 如果设置了 <data android:scheme="test" android:host="www.google.com" android:port="80"/>,必须完全匹配 Uri data = Uri.parse("test://www.google.com:80");才能启动。
- 如果 <data android:scheme="test" android:host="www.google.com"/>,那么 Uri data = Uri.parse("test://www.google.com:80"),Uri data = Uri.parse("test://www.google.com:88"), Uri data = Uri.parse("test://www.google.com")都可以匹配。
- 如果只设置了 <data android:scheme="test"/>,那么 Uri data = Uri.parse("test://")就可以匹配,后面也可以加其他参数。
- 如果设置了mimeType,那么必须使用 intent.setDataAndType(data, "text/*");启动activity。
0 0
- Android根据Data匹配隐式Intent的实例
- Android根据Data匹配隐式Intent的实例
- Android根据Action匹配隐式Intent的实例
- android Intent匹配,自定义action data category
- 【Android】intent-filter里data匹配分析
- Android之隐式意图(Intent)如何查找匹配的组件
- Android之隐式意图(Intent)如何查找匹配的组件
- Android之隐式意图(Intent)如何查找匹配的组件
- Android Intent隐式调用之intent-filter匹配规则
- Android如何匹配隐式Intent
- Android的Intent Action Data
- Android的Intent匹配(二)
- Android基础总结十一:intent-filter的action,category,data匹配规则
- intent-filter的action,category,data匹配规则
- intent-filter的action,category,data匹配规则
- android的Intent用法实例
- android的Intent用法实例
- Android Intent匹配解析
- Android生成圆形缩略图的一种方法
- Android服务之Service
- Android中Service(服务)详解
- Android Intent 总结
- poj 1679 The Unique MST
- Android根据Data匹配隐式Intent的实例
- 利用POI读取Excel文件
- Android SQLite总结(一)
- HDU4638——Group(树状数组+离线操作)
- ANDROID开发之SQLite详解
- Android:文件下载和写入SD卡学习小结
- N皇后问题
- Android文件下载进度条的实现
- Android解析XML