Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

clear my own app defaults programmatically [closed]

Tags:

android

Is it possible in android 4.0 and higher to programmatically clear your own app's defaults? can someone point me in the right direction if possible

like image 239
erik Avatar asked Dec 16 '22 18:12

erik


2 Answers

You cannot set your app as the default for an action programmatically in any version of Android.

This is for security reasons, as a malicious app could exploit this to become the default for any user action, and steal personal information, or render the device useless etc.

At best, on your first run you could launch a chooser intent with dummy data and ask the user to set your app as the default.

EDIT:

My mistake. I thought you wanted to set the defaults.

clearPackagePreferredActivities() in PackageManager will clear the defaults of a particular app, whichever's package name you pass.

like image 156
Raghav Sood Avatar answered Jan 09 '23 12:01

Raghav Sood


PreferenceManager.getDefaultSharedPreferences(context).edit().clear().commit();
like image 41
user1475122 Avatar answered Jan 09 '23 10:01

user1475122