private void uninstallPackage(String name) {
Intent intent = new Intent(Intent.ACTION_DELETE);
intent.putExtra(Intent.EXTRA_RETURN_RESULT, true);
intent.setData(Uri.parse("package:"+name));
startActivity(intent);
}
private boolean doesPackageExist(String name){
PackageManager pm=getPackageManager();
try {
PackageInfo info=pm.getPackageInfo(name,PackageManager.GET_META_DATA);
} catch (PackageManager.NameNotFoundException e) {
return false;
}
return true;
}
private void checkUninstallStatus(int requestCode, int resultCode, Intent data) {
if (requestCode == 1) {
if (resultCode == RESULT_OK) {
Log.d("TAG", "onActivityResult: user accepted the (un)install");
} else if (resultCode == RESULT_CANCELED) {
Log.d("TAG", "onActivityResult: user canceled the (un)install");
} else if (resultCode == RESULT_FIRST_USER) {
Log.d("TAG", "onActivityResult: failed to (un)install");
}
}
}
@Override
protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
checkUninstallStatus(requestCode,resultCode,data);
}
No comments:
Post a Comment