Reputation: 949
On android pie, I want to call the package manager to uninstall my own app. Here is what I am trying:
val uri = Uri.parse("package:$packageName")
val uIntent = Intent(Intent.ACTION_UNINSTALL_PACKAGE, uri)
startActivity(uIntent)
Oddly this is not working. Nothing is being shown in the logcat as well.
I have also tried ACTION_DELETE
val uri = Uri.parse("package:$packageName")
val uIntent = Intent(Intent.ACTION_DELETE, uri)
startActivity(uIntent)
Please tell me what I am doing wrong. This seems a pretty straightforward job. Am I missing any permission or something I need to declare in manifest? Thanks.
Upvotes: 4
Views: 2455
Reputation: 949
I was missing manifest permission.
<uses-permission android:name="android.permission.REQUEST_DELETE_PACKAGES"/>
This is probably required for Android 6.0 and above. The code in the question now works perfectly. Tested on Android 9 and Android 10.
Upvotes: 13
Reputation: 114
Intent intent = new Intent(Intent.ACTION_DELETE);
intent.setData(Uri.parse("package:com.example.myapplication"));
startActivity(intent);
Upvotes: -1