-1

By "permanent" I mean that it resists the application uninstall option that the Android OS offers. Obviously you cannot make a file not deletable in the user's terminal, at the very least, the user will always be able to delete it via the file manager if he wishes so.

I'd need this because in my app when some actions have been performed the app forbids from doing some more. So far this is controlled via a file, but there's nothing that prevents the user from uninstalling the app, and with a new fresh install this doesn't happen anymore.

I could implement some type of server-side logic to prevent the user from continueing but:

1) It's way easier to prevent just by checking the file.

2) It's not that important what happens if the user manages to bypass this security measure, so I don't really mind if a few of them are able to bypass the protection, as long as the file can be "permanent" and is in some obscure directory, not many users are going to be able to perform the mentioned behavior.

Is there any way to do this?

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
user2638180
  • 1,013
  • 16
  • 37

3 Answers3

1

this can be done by configuring auto-backup, assuming that the user has it enabled.

for example, here I've explained how to disable that behavior in debug mode.

the advance is, that it works across several devices, bound to the account.

Martin Zeitler
  • 1
  • 19
  • 155
  • 216
1

Just get the write file permission and write the file to the root file directory. As described here: https://developer.android.com/training/data-storage/files#WriteExternalStorage

After you request storage permissions and verify that storage is available, you can save two different types of files:

  • Public files: Files that should be freely available to other apps and to the user. When the user uninstalls your app, these files should remain available to the user. For example, photos captured by your app or other downloaded files should be saved as public files.
  • Private files: Files that rightfully belong to your app and will be deleted when the user uninstalls your app. Although these files are technically accessible by the user and other apps because they are on the external storage, they don't provide value to the user outside of your app.
leonardkraemer
  • 6,573
  • 1
  • 31
  • 54
  • Thanks, this is what I needed, although I would have preferred something that doesn't involve asking for permission. But, if things are this way, it cannot be helped. – user2638180 Jan 02 '19 at 19:35
0

instead of file , I would suggest to use following intent to catch uninstalling your app and put your logic to allow or deny for uninstall

ACTION_PACKAGE_REMOVED -: Broadcast Action: An existing application package has been removed from the device. The data contains the name of the package. The package that is being installed does not receive this Intent.

ACTION_PACKAGE_FULLY_REMOVED - : Broadcast Action: An existing application package has been completely removed from the device. The data contains the name of the package. This is like ACTION_PACKAGE_REMOVED, but only set when EXTRA_DATA_REMOVED is true and EXTRA_REPLACING is false of that broadcast.

divyang4481
  • 1,584
  • 16
  • 32
  • How would I implement any logic to prevent anything if the Broadcast will be sent when "An existing application package **has been removed** from the device"? – Bö macht Blau Jan 02 '19 at 17:03
  • make your add as device administrator then you get control uninstall feature https://rootfs.wordpress.com/2010/09/09/android-make-your-application-a-device-administrator/#comment-98 – divyang4481 Jan 03 '19 at 09:20