Do something before app removing - java

I've got an app that stores few files on sd card. I want my app to remove those files, if user wants to delete the application. How can I do that? Is there a method like onDelete() or something?

I've got an app that stores few files on sd card. I want my app to
remove those files,
Don't store them directly on the sdcard. Use the app's cache space or the directory pointed by getExternalFilesDir. Both are cleaned up by the system when the app is uninstalled

No, there is no way for you app to know when it is being deleted/removed from a device.
Intent.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.
This comes mostly because if a code would be executed on the app that was about to be removed some might prevent removal etc.
You should provide an option to your users to wipe sdcard data, or use another storage option (that is linked to your app), but I guess you're using the sdcard on purpose.

Related

How do I create a directory at /0 on Android?

I'm having a problem with my users (Android). They delete the app, and their data is gone. They expect it not to be.
Browsing my phone, I see a lot of apps put a folder right off of /internal shared storage. I.E. I click on internal shared storage and there's a bunch of folders for various apps with data in them that doesn't go away if I uninstall the app.
This is what my customers want. This is what will stop them from writing me and accusing me of destroying their data.
How do I get a path to that folder, and what permission do I need to write there?
First off, deleting when the app is gone is how Android works. Anything else is a bug that you should expect to see fixed.
Secondly, you can't put anything right in / anymore. There was a time you could, but that's long since gone.
Third, have you looked into Android Data Backup? https://developer.android.com/guide/topics/data/backup This will work even on a new device, so its a better path forward anyway

Store files on server and download them automatically when Android app is installed

I am making a Educational app for students of different classes from 9-12. Right now all the study materials are stored in the app itself so the size of the app is increased. Here is the screenshot:-
All the data is stored in html format inside 'assets' folder
These are the notes for all the students for each subject
I want to store these the whole assets folder on server and when the app is installed I want to automatically download the 'assets' folder to user's mobile so that the size of the apk file is reduced. Currently the size of the app is 11 MB, in which about 5 MB is for the assets folder and till now I have just added materials for class 10 and still I have to add content for class 9,11,12. And also i have to add more contents for class 10 so later on my app size will increase.This is the link to the app:-
1Learn NCERT App
The app I am developing is kind of offline app where the user need not to be connected to internet so for the first time when the app is installed I want to sync the files from server to user's mobile but from next time the app will use the downloaded files and no need of Internet connection.
I don't want to use obb files, Is there any other method to do it?
Try expansion files. More info here https://developer.android.com/google/play/expansion-files. It solves a lot of the problems with hosting large files by using Google Play. I am not sure if your main app must be >100 MB for extension files to be allow. Give it a shot let me know.

Store data on device on application install without opening app

Is it possible to save data to a device upon the installation of my application prior to the opening of the application?
If not, I'm looking for a way I can somehow mark a mobile device as "test device" without my application ever being opened on it (only installed).
If you want to distinguish between the shipped devices and every other device, use the build variants. You can add a variable to the BuildConfig class in gradle and specify a value for this sort of "prerelease" you are making and other for the build you are shipping to the store. Then, in the relevant code, check the value of the variable you created in BuildConfig.

Preventing the file to be downloaded on other device

I want to create an paid app which has a file which can be downloaded.If users buys my application and downloads the file.I want disable the user from transferring that file any other device.Some kind of Cyptography i guess.I have searched everywhere but no luck.Please guys help me to achieve that.
You would either have to hack the Android operating system in order to do that, or you would need to make a program that keeps checking what eachfile the user opens is.

Pull files from Android tablet for debugging purposes.

In school (high school), my partner and I are developing an Android tablet application. We were both issued Acer Iconia A500 tablets to use. I need to pull files created by our application on run-time off the device (adb pull), but because they are not rooted, and I wouldn't want to root school property, is there an effective way to remove files from an android device stored in your applications data/data/packagename/ area? We also did try the emulator, but have had numerous different problems with it, and when it does work, it takes about 4-5 minutes to upload an apk to it every time I change code and re-upload it. Any ideas on a good way to get files off a non-rooted device, in this case a database I'm trying to copy from assets, so I can inspect it?
If you have a choice, I'd definitely recommend writing your files to the SD card because that will be a lot easier to view and handle.
If your file must necessarily be written in /data, what you could do is mirror it to the SD card for debugging purposes. So every time you write the file, you also write exactly the same content to the SD card (if the debug flag is on, otherwise no).
If it's a file that is not being created by your code but by other code, what you can do in your app is copy it to the SD card when you detect that it's been changed.
You could use the external storage permission and write to the SD Card instead. Then you can pull them using the regular windows directory when you plug it in. Also, it should not take that long to update your code via the emulator, are you turning the emulator off every time?

Categories

Resources