我有一个片段,当他们单击uninstall时,它使用一个意图来卸载应用程序。
View.OnClickListener removeButtonClick = new View.OnClickListener() {
@Override
public void onClick(View paramView) {
PackageManager pm = ContextProvider.getContext().getPackageManager();
Intent intent = new Intent(Intent.ACTION_DELETE, Uri.fromParts("package",
app.packageName, null));
int result = 0;
startActivityForResult(intent, result);
}
};
当活动成功完成时,它将调用:
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
new MainActivity.UpdateDatabase().execute(); // update database
ContextProvider.getContext().getFragmentManager().popBackStack(); // go back
}
但无论用户是按了uninstall还是cancel,requestcode和resultcode均为0,数据均为空。我怎样才能知道他们选择了什么?
这就是我最后所做的:
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
Boolean found = false;
PackageManager pm = ContextProvider.getContext().getPackageManager();
List<PackageInfo> packages = pm.getInstalledPackages(0);
for (PackageInfo pi : packages) {
if (pi.packageName.equals(app.packageName)) {
found = true;
break;
}
}
if (!found) { // User uninstalled app so update database and go back
new MainActivity.UpdateDatabase().execute();
goBack();
}
}
最佳答案
不知道该怎么做,但你能不能用包管理器看看包是否还在?