通过PackageManager 获取 Intent 启动应用程序。

代码如下: 

        Intent launch = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
        launch.addCategory(Intent.CATEGORY_LAUNCHER);
        launch.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        context.startActivity(launch);

 下面代码是为了启动的时候以新的activity 启动,不然可能会打开以前的界面。

launch.addCategory(Intent.CATEGORY_LAUNCHER);

 

 

你可能感兴趣的:(通过PackageManager 获取 Intent 启动应用程序。)