-2

Can we clear or delete data of one application from another application in android. If it is not possible simply could you please suggest any tricky way to do this like to go to the folder in internal memory and delete that folder programatically.

Thanks.

Piyush Agarwal
  • 25,608
  • 8
  • 98
  • 111

3 Answers3

1

Simple answer,

Android is designed that this should not be possible.

But when using root access you can actually delete folders from other applications.

I believe if two applications having a different package, but with the same signature, actually can have access to each others private folders. Or i'm not sure, i believe you could add some kind of declaration to you manifest file allowing other (friend) apps to have access to your private folder. But i'm not sure i should search for it.

Edit after search:

Apps having the same android:sharedUserId and android:sharedUserLabel and signature have access to each others private files.

http://developer.android.com/guide/topics/manifest/manifest-element.html#uid

Two Android applications with the same user ID

Edit 2:

There are some private methods in the android API, witch can be used to clear app data i think. I'm not sure but if you reflect those methods with the right permissions in you manifest file it could be possible to clear app data, but i'm not 100% sure.

Some small example code:

Method clearApplicationUserData = getReflectedMethod("clearApplicationUserData", String.class, IPackageDataObserver.class);

And the method i use the get it reflected...

private Method getReflectedMethod(String methodname, Class<?>... args) {
    Method temp = null;
    try {
        temp = pm.getClass().getMethod(methodname, args);
    } catch (SecurityException e) {

        return null;
    } catch (NoSuchMethodException e) {

        return null;
    }
    return temp;
}

The IPackageDataObserver class should be copied from the original android source, and added as new class in the source folder of your project under the package android.content.pm.

When you want to clear user data i think you should invoke the method like this:

public void clearApplicationUserData(String packageName) {
    if (clearApplicationUserData != null) {
        try {
            clearApplicationUserData.invoke(pm, packageName, data_helper);
        } catch (IllegalArgumentException e) {

        } catch (IllegalAccessException e) {

        } catch (InvocationTargetException e) {

        }
    }
}

The data_helper is any class extending the IPackageDataObserver.Stub class.

You can find a lot of questions about reflecting methods and stuff here on stackoverflow.

I have no idea if this works but this is the only way i can think of.

Rolf

Community
  • 1
  • 1
Rolf ツ
  • 8,611
  • 6
  • 47
  • 72
0

If its stored in the database you can delete the data using content provider by following method

mRowsDeleted = getContentResolver().delete(
    UserDictionary.Words.CONTENT_URI,   // the user dictionary content URI
    mSelectionClause                    // the column to select on
    mSelectionArgs                      // the value to compare to
);

follow the methods Here

Rajesh Rajaram
  • 3,271
  • 4
  • 29
  • 48
0

The question is not very clear.

Do you mean your app will delete data from someone elses app? The answer there is "it depends". First, if the data is on the SD card, you could access it and delete it. If the data is in the apps private data area, then you cannot do that unless your phone is rooted.

If the apps in question are both made by you, the answer is yes, it is possible. You would have to use the android:sharedUserId property in the manifest file of each app, make them the same and sign both apps with the same key. This would give the apps access to each others data.

If the data you are speaking of is on the devices SD card, yes you can. If it is in the internal storage, then no (unless you created both apps and have used the

Barak
  • 16,318
  • 9
  • 52
  • 84