asfman
android developer
posts - 90,  comments - 213,  trackbacks - 0
1 同application调用

   <intent-filter>
    <action android:name="动作名字(随便设置)" />
    <category android:name="android.intent.category.DEFAULT" /> (这个必须得设置,否者会找不到,note A)
   </intent-filter>
A:
“Android treats all implicit intents passed to startActivity() as if they contained at least one category: "android.intent.category.DEFAULT" (the CATEGORY_DEFAULT constant). Therefore, activities that are willing to receive implicit intents must include "android.intent.category.DEFAULT" in their intent filters”

每一个通过 startActivity() 方法发出的隐式 Intent 都至少有一个 category,就是 "android.intent.category.DEFAULT",所以只要是想接收一个隐式 Intent 的 Activity 都应该包括 "android.intent.category.DEFAULT" category,不然将导致 Intent 匹配失败。
//不用隐式调用,下面两种方式都可以
intent.setClassName("com.aizheke.aizheked", bundle.getString("activity"));
intent.setComponent(new ComponentName("com.aizheke.aizheked", bundle.getString("activity")));
2 不同application调用
如果知道具体的包名,类名,那么可以直接调用
Intent intent = new Intent();
intent.setClassName("com.asfman", "com.asfman.ActivityB");
startActivity(intent);

如果知道action name那么可以通过
Intent intent = new Intent();
intent.setAction("动作名字(随便设置)" );
startActivity(intent);

   如果有设置category那么必须intent.setCategory("类别名字")。如果设置了<category android:name="android.intent.category.DEFAULT" /> ,那么可以不用intent.setCategory,系统会默认调用
posted on 2011-06-17 11:27 汪杰 阅读(372) 评论(2)  编辑 收藏 引用 所属分类: Java

FeedBack:
# re: 关于intent-filter
2012-05-07 15:28 | 汪杰
PackageManager pm=getPackageManager();

Intent intent=new Intent();

intent=pm.getLaunchIntentForPackage("此处写要打开的程序的包名");
startActivity(intent);  回复  更多评论
  
# re: 关于intent-filter
2012-05-07 15:31 | 汪杰
1.安装apk程序

Intent intent=new Intent();
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(”此处写apk路径”),"application/vnd.android.package-archive");
context.startActivity(intent);

2.卸载程序

Intent intent=new Intent(Intent.ACTION_DELETE,Uri.parse("package:"+此处为要卸载的程序的包名));
context.startActivity(intent);
  回复  更多评论
  
只有注册用户登录后才能发表评论。

<2012年5月>
293012345
6789101112
13141516171819
20212223242526
272829303112
3456789

常用链接

留言簿(15)

随笔分类(1)

随笔档案(90)

文章分类(727)

文章档案(712)

相册

收藏夹

http://blog.csdn.net/prodigynonsense

友情链接

最新随笔

搜索

  •  

积分与排名

  • 积分 - 457957
  • 排名 - 6

最新随笔

最新评论

阅读排行榜

评论排行榜