Ton*_*Joe 5 android uninstallation android-intent
我正在尝试制作一个卸载程序应用程序,这是我用来卸载应用程序的部分:
Uri uri = Uri.fromParts("package", app.getPackageName(), null);
Intent intent = new Intent(Intent.ACTION_DELETE, uri);
startActivity(intent);
Run Code Online (Sandbox Code Playgroud)
当用户单击卸载按钮时,会出现一个确认弹出对话框。有没有办法检查用户是否在对话框中单击了“确定”或“取消”?
没关系伙计们,我终于找到了解决方案:我使用了 ACTION_UNINSTALL_PACKAGE(最低 API 14)而不是 ACTION_DELETE,这是最终代码:
private void uninstallApps(List<AppModel> apps) {
for (AppModel app : apps) {
Uri uri = Uri.fromParts("package", app.getPackageName(), null);
Intent intent = new Intent(Intent.ACTION_UNINSTALL_PACKAGE, uri);
// store result
intent.putExtra(Intent.EXTRA_RETURN_RESULT, true);
startActivityForResult(intent, 1);
}
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// get result
if(resultCode == RESULT_OK){
Log.d(TAG, "onActivityResult: OK");
}else if (resultCode == RESULT_CANCELED){
Log.d(TAG, "onActivityResult: CANCEL");
}
}
Run Code Online (Sandbox Code Playgroud)
我希望这会帮助某人。
| 归档时间: |
|
| 查看次数: |
701 次 |
| 最近记录: |