2017-08-13 80 views
0

我試圖讓一個卸載程序應用程序,這是我用它來卸載應用部分:如何檢測用戶點擊確定或取消Intent.ACTION_DELETE?

Uri uri = Uri.fromParts("package", app.getPackageName(), null); 
Intent intent = new Intent(Intent.ACTION_DELETE, uri); 
startActivity(intent); 

當用戶點擊卸載按鈕,出現確認彈出對話框。有沒有辦法檢查用戶是否在對話框中點擊了OK或CANCEL?

回答

0

別介意傢伙,我終於找到了解決辦法:不是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"); 
    } 
} 

我希望這會幫助別人。

相關問題