別介意傢伙,我終於找到了解決辦法:不是ACTION_DELETE,我用ACTION_UNINSTALL_PACKAGE(最小API 14),這是最後的代碼:
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");
}
}
我希望這會幫助別人。