0

I work for a company that developed an Android app, but since then the guys that wrote it have left. I am a beginner when it comes to Android development.

We have a situation where our customer has used the app and has data, but something has happened and the data can't be uploaded from the app (which it normally should do). The customer says the data is expensive and critical. We believe a database table has been corrupted.

I attempted to give them a build of the app which would download the file with the data, but when the link is tapped it gives the error "net::ERR_ACCESS_DENIED" because the file is in the app's protected storage (file:///data/user/0/com.mycompany.myapp/files/projects/projectname/data.sqlite).

I really am shooting in the dark as to what could be done to retrieve the file. Any suggestions?

Our app has allowBackup=true and targetSdkVersion=31 in it's AndroidManifest.xml and the app is running on Android 12.

1
  • My phone is an S21 on Android 12. The manifest file doesn't specify targetAPI, but it has a build.gradle file specifying minSdkVersion 23 and targetSdkVersion 31. Commented Sep 7, 2022 at 20:08

1 Answer 1

0

My first thought was that when backup is allowed you should be able to extract the file using adb backup command. Unfortunately that no longer only works on Android since about 12 for apps that have a targetSDKVersion of 31 or newer.

Therefore there is only one way to get the file through a new app version:

My recommended way would be to implement a new feature into your app that allows to export the data from the app-private directory and save it e.g. to the "sdcard" section of Android.

Alternatively you could try to implement a totally new app that uses the same packageName/applicationId and the same APK signature key. The versionCode in AndroidManifest.xml must be higher than any version you have ever released. That new app only needs to have one button to start the copy process of the important database to the sdcard section. This app can then be installed manually as update so that the app-internal data is kept and can then be exported.

3
  • I have managed to create code which uses an InputStream and OutputStream to try and copy the file. I currently getting an exception opening the OutputStream "EPERM (Operation not permitted)". Right now the output filename string is set to 'Environment.getExternalStorageDirectory().toString() + "/data.sqlite"; If interested, I may be able to convince my company to pay you for consulting. Commented Sep 9, 2022 at 21:29
  • @WalterWilliams Check Stackoverflow.com for the keywords Scoped Storage. The code you use is most likely outdated since Android 11 and thus won't work anymore.
    – Robert
    Commented Sep 10, 2022 at 10:39
  • I got something to work in the emulator. Hopefully it will work on the target tablet. Thanks! Commented Sep 12, 2022 at 15:18

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .