Can we remove(clear) shared preferences of one application from other application?

116 views
Skip to first unread message

Abhishek Kumar Gupta

unread,
Sep 7, 2012, 9:19:03 AM9/7/12
to android-...@googlegroups.com
Currently I am working in ICS source. I want to remove(clear) the sharedpreferences of one application from other application.
I have tried the following code in the other application to remove preferences of application having package name "com.android.blesettings":

                    Context context = getActivity().createPackageContext(
                            "com.android.blesettings", 0);
                    SharedPreferences mSettings = mSettingsContext.getSharedPreferences(
                            "profile_preference", MODE_WORLD_READABLE);
                    SharedPreferences.Editor mSettingsEditor = mBLESettings.edit();
                    mSettingsEditor.clear();
                    mSettingsEditor.commit();
     
                    File file = new File(
                            "/data/data/com.android.blesettings/shared_prefs/profile_preference.xml.bak");
                    file.delete();


I am able to remove(clear) the value of the sharedpreference of application(that I have observed by looking the "profile_settings" file) but it is taking value(previously saved) from the .bak file of the sharedpreferences.

I am unable to delete the .bak file of the sharedpreferences(profile_preference) of application having package name "com.android.blesettings".

I have used the same sharedUserId inside the manifest tag of AndroidManifest.xml of both applications (e.g.android:sharedUserId="android.uid.system")

 

How to resolve this issue?  Is it possible with SharedPreferences?
Any help or guidance will be well appreciated. 

Dianne Hackborn

unread,
Sep 7, 2012, 9:30:44 PM9/7/12
to android-...@googlegroups.com
No you can't do this.  And obviously this:

                    File file = new File(
                            "/data/data/com.android.blesettings/shared_prefs/profile_preference.xml.bak");

is totally wrong.  If you are writing fixed paths like this, you are going to break in certain situations in the future, I guarantee.

More generally, except under special situations (shared user IDs), two applications can not get direct access to each others' files at all, and this is enforced by the Linux kernel.


--
You received this message because you are subscribed to the Google Groups "android-platform" group.
To view this discussion on the web visit https://groups.google.com/d/msg/android-platform/-/X34vak3EQgcJ.
To post to this group, send email to android-...@googlegroups.com.
To unsubscribe from this group, send email to android-platfo...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-platform?hl=en.



--
Dianne Hackborn
Android framework engineer
hac...@android.com

Note: please don't send private questions to me, as I don't have time to provide private support, and so won't reply to such e-mails.  All such questions should be posted on public forums, where I and others can see and answer them.

Abhishek Kumar Gupta

unread,
Sep 8, 2012, 1:51:07 AM9/8/12
to android-...@googlegroups.com
Hi Dianne Hackborn,

Thanks for the reply. Is there any way to clear the Shared preferences of another application? Or I have to use only Content Provider?

Dianne Hackborn

unread,
Sep 9, 2012, 7:13:29 PM9/9/12
to android-...@googlegroups.com
You'll have to talk with the developer of the other application for what they would allow you to do.  You can't directly poke at anything in another application unless it is providing something explicitly to let you do this.

--
You received this message because you are subscribed to the Google Groups "android-platform" group.
To view this discussion on the web visit https://groups.google.com/d/msg/android-platform/-/evoAo5NvQ3sJ.

To post to this group, send email to android-...@googlegroups.com.
To unsubscribe from this group, send email to android-platfo...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/android-platform?hl=en.
Reply all
Reply to author
Forward
0 new messages