0

My app has a backup/restore feature which export data to a file either to a file in device, or share to DropBox, email etc. When restore user can select that file to import data back. But after the new Android storage privacy policy:

https://developer.android.com/about/versions/11/privacy/storage

My app can no longer see the files that exported if the app that restore is after uninstall and reinstall, or in a new device which must be a different installation. It seems all the app can see are the files is generate. This breaks the purpose of the backup/restore feature.

Can anyone advice how do my app should change in order to help user keep data across different installation? Thank you for any suggestions or advice.

Antony Ng
  • 767
  • 8
  • 16
  • 1
    If you store a file in DropBox or send with email you can always get it back later. So i do not agree with your scenario. – blackapps Sep 21 '21 at 12:57
  • 1
    And other files saved on public external storage you can let the user pick with Storage Access Framework ACTION_OPEN_DOCUMENT. – blackapps Sep 21 '21 at 12:59

1 Answers1

0

The new policy is about reading/writing every file in the device, you can still ask for the system for external files that will be delivered to you as a Uri that you just open and read

    val intentGetPDF = Intent(Intent.ACTION_GET_CONTENT)
    intentPDF.type = fileType
    intentPDF.addCategory(Intent.CATEGORY_OPENABLE)
    ctx.startActivityForResult(Intent.createChooser(intentFetPDF, ""), REQUEST_PDF)

And from onActivityResult

val iS = ctx.contentResolver.openInputStream(data.data as Uri)

To save the files you now need to share it from your internal app storage trough a Uri from FileProvider

    val fileUri = FileProvider.getUriForFile(ctx, "apppackage.provider", "your internal file path here")
    val intent = Intent(MediaStore.ACTION_SEND)
    intent.putExtra(Intent.EXTRA_STREAM, fileUri)
    startActivity(intent)

You will need to setup a FileProvider in the AndroidManifest so it work

Marcos Vasconcelos
  • 18,136
  • 30
  • 106
  • 167
  • It looks to me that there is no need to save the file again as it is already on the device. Further OP did not name sharing. But if you wanna share you could use the uri obtained from ACTION_GET_CONTENT. No need or possibility for a FileProvider as for using FileProvider you need a readable file path first. – blackapps Sep 21 '21 at 13:07
  • A I just added more info about saving the file in the new policy – Marcos Vasconcelos Sep 21 '21 at 13:33
  • Why the fuss? OP did not ask to save the readed content to file. Moreover ACTION_SEND does not save a file. And you have no path that you can use for a FileProvider. – blackapps Sep 21 '21 at 13:43