public void jumpToAppByPackage(final String packname) {
runOnUiThread(new Runnable() {
@Override
public void run() {
PackageManagerpackageManager = getPackageManager();
if (checkPackInfo(packname)) {
Intentintent =packageManager.getLaunchIntentForPackage(packname);
startActivity(intent);
}else {
Toast.makeText(MainActivity.this, getString(R.string.no_found_app) +packname, Toast.LENGTH_LONG).show();
}
}
});
}
private boolean checkPackInfo(String packname) {
PackageInfo packageInfo =null;
try {
packageInfo = getPackageManager().getPackageInfo(packname, 0);
}catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
return packageInfo !=null;
}
网友评论