Android 開啟其他 app

weixin_33938733發表於2016-06-16

通過包名獲取 啟動的 intent (推薦使用)

     public static Intent getMainIntent(Context context, String packageName) {
          return context.getPackageManager().getLaunchIntentForPackage(packageName);
     }
    Intent intent = getMainIntent(getApplicationContext(), "com.zuimeia.suite.lockscreen.international");
    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    intent.putExtra(EXTRA_LAYOUT_ID, themeid);
    startActivity(intent);

通過包名和MainActivity 名字來啟動:


     Intent intent = new Intent(Intent.ACTION_MAIN);
     intent.addCategory(Intent.CATEGORY_LAUNCHER);         
     ComponentName cn = new ComponentName(packageName, className);         
     intent.setComponent(cn);
     startActivity(intent);

相關文章