方法一:
Intent intent = new Intent();
intent.setAction("com.lzy.example.MAIN"); intent.addCategory("android.intent.category.DEFAULT"); startActivity(intent);注:在要启动的应用程序主入口中添加
<intent-filter>
<action android:name="com.lzy.example.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter>
// ComponentName
方法二:(如果要启动的Activity不是主Activity,需要在AndroidManifest添加exported=true)
Intent intent1 = new Intent();
intent1.setComponent(new ComponentName("com.lzy.example",
"com.lzy.example.MainActivity"));
Bundle bundle = new Bundle();
bundle.putString("abc", "哈哈哈哈哈");
intent1.putExtras(bundle);startActivity(intent1);
/** * 判断相对应的APP是否存在 * * @param context * @param packageName(包名) * @return */ private boolean isAvilible(Context context, String packageName) throws Exception { PackageManager packageManager = context.getPackageManager(); //获取手机系统的所有APP包名,然后进行一一比较 List<PackageInfo> pinfo = packageManager.getInstalledPackages(0); for (int i = 0; i < pinfo.size(); i++) { if (((PackageInfo) pinfo.get(i)).packageName.equalsIgnoreCase(packageName)) return true; } return false; } /** * 判断我们的手机中是否存在我们要的这个action * * @param context * @param action * @return */ private boolean isActionSupport(Context context,String action){ final PackageManager packageManager = context.getPackageManager(); final Intent intent = new Intent(action); List<ResolveInfo> resolveInfo = packageManager.queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY); if (resolveInfo.size() > 0) { return true; } return false; }