android启动应用

  1. private void openApp(String packageName) {  
  2. PackageInfo pi = getPackageManager().getPackageInfo(packageName, 0);  
  3.   
  4. Intent resolveIntent = new Intent(Intent.ACTION_MAIN, null);  
  5. resolveIntent.addCategory(Intent.CATEGORY_LAUNCHER);  
  6. resolveIntent.setPackage(pi.packageName);  
  7.   
  8. List<ResolveInfoapps = pm.queryIntentActivities(resolveIntent, 0);  
  9.   
  10. ResolveInfo ri = apps.iterator().next();  
  11. if (ri != null ) {  
  12. String packageName = ri.activityInfo.packageName;  
  13. String className = ri.activityInfo.name;  
  14.   
  15. Intent intent = new Intent(Intent.ACTION_MAIN);  
  16. intent.addCategory(Intent.CATEGORY_LAUNCHER);  
  17.   
  18. ComponentName cn = new ComponentName(packageName, className);  
  19.   
  20. intent.setComponent(cn);  
  21. startActivity(intent);  
  22. }  
  23. }  
posted @ 2017-10-20 10:27  小毛驴  阅读(163)  评论(0编辑  收藏  举报