vendredi 19 février 2016

Share sqlite file via intent

In my app I want users to be able to make backups of their database so I provide an option to upload a db file to some cloud storage app via intent.

Here's my current code (in Scala) which does not work:

val intent = new Intent(Intent.ACTION_SEND)
intent setType "application/octet-stream"

val file = getDatabasePath(AbstractKit.DB_FILE_NAME)
android.util.Log.d(TAG, file.exists.toString) // true

intent.putExtra(Intent.EXTRA_STREAM, Uri.parse(file.getPath))
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
startActivity(intent)

File chooser gets started but none of the apps available actually accept a file saying it has a wrong format or a like. Why does it happen and how can I fix this?

Aucun commentaire:

Enregistrer un commentaire