隐式 intent
- xml
- <!-- 在意图过滤器中 -->
- <intent-filter>
- <action Android:name="android.intent."/>
- <category Android:name="android.intent.category.DEFAULT"/>
- <data Android:mimeType="application/person"/>
- <data Android:scheme="" Android:host="">
- </intent-filter>
- <!--android:action
- category
- URI 和数据类型 -->
一个 Android(理解为匹配机制) 中可以定义 0-1 个 action,0-n 个 category, 0-1 个 data
一个 intent-filter 中可以定义多个 action,category,data
MainActivity 中
- 1.setAction
- Intent intent = new Intent();
- intent.setAction("abcdefg");
- startActivity(intent);
2. 构造方法直接设置
- Intent intent = new Intent("abcdefg");
- startActivity(intent);
有几点需要注意:
1, 这个 Activity 其他应用程序也可以调用, 只要使用这个 Action 字符串. 这样应用程序之间交互就很容易了, 例如手机 QQ 可以调用 QQ 空间, 可以调用腾讯微博等.
因为如此, 为了防止应用程序之间互相影响, 一般命名方式是包名 + Action 名, 例如这里命名 "abcdefg" 就很不合理了, 就应该改成 "com.example.app016.MyTest".
2, 当然, 你可以在自己的程序中调用其他程序的 Action. 例如可以在自己的应用程序中调用拨号面板:
- Intent intent = new Intent(Intent.ACTION_DIAL);
- // 或者 Intent intent = new Intent("android.intent.action.DIAL");
- // Intent.ACTION_DIAL 是内置常量, 值为 "android.intent.action.DIAL"
- startActivity(intent);
来源: http://www.bubuko.com/infodetail-2805785.html