|
检查包名(调试用),然后检查包名是否存在,再按照packname包名调起程序
- PackageManager packageManager = getPackageManager();
- List<ApplicationInfo> list = packageManager.getInstalledApplications(PackageManager.GET_UNINSTALLED_PACKAGES);
- //设置调起其他程序
- //com.example.test_aotostart
- String packname = "hello.world";
- // PackageManager packageManager = getPackageManager();
- if (checkPackInfo(packname)) {
- Intent intent = packageManager.getLaunchIntentForPackage(packname);
- startActivity(intent);
- } else {
- Toast.makeText(MainActivity.this, "没有安装" + packname, 1).show();
- }
复制代码- /**
- * 检查包是否存在,
- * @param packname
- * @return
- */
- private boolean checkPackInfo(String packname) {
- PackageInfo packageInfo = null;
- try {
- packageInfo = getPackageManager().getPackageInfo(packname, 0);
- } catch (PackageManager.NameNotFoundException e) {
- e.printStackTrace();
- }
- return packageInfo != null;
- }
复制代码
|
|