码迷,mamicode.com
首页 > 移动开发 > 详细

Android根据APP包名启动应用

时间:2014-11-21 15:41:49      阅读:168      评论:0      收藏:0      [点我收藏+]

标签:android   style   blog   io   ar   color   sp   on   div   

 1     public void openApp(String packageName, Context context) {
 2         PackageManager packageManager = context.getPackageManager();
 3         Intent resolveIntent = new Intent(Intent.ACTION_MAIN, null);
 4         resolveIntent.addCategory(Intent.CATEGORY_LAUNCHER);
 5         resolveIntent.setPackage(packageName);
 6 
 7         List<ResolveInfo> apps = packageManager.queryIntentActivities(
 8                 resolveIntent, 0);
 9 
10         ResolveInfo ri = apps.iterator().next();
11         if (ri != null) {
12             String className = ri.activityInfo.name;
13 
14             Intent intent = new Intent(Intent.ACTION_MAIN);
15             intent.addCategory(Intent.CATEGORY_LAUNCHER);
16             intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
17             ComponentName cn = new ComponentName(packageName, className);
18 
19             intent.setComponent(cn);
20             context.startActivity(intent);
21         }
22     }

 

Android根据APP包名启动应用

标签:android   style   blog   io   ar   color   sp   on   div   

原文地址:http://www.cnblogs.com/l2rf/p/4112944.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!