I'm maintaining a legacy Android app that uses OrmLiteSqliteOpenHelper to create a Sqlite database on the device. On the device, I found out this file lives at:
/data/data/[package-name]/databases/mydatabase.db
My app has an "E-mail Support" feature, and I have unfortunately been tasked with attaching this SQLite file to an e-mail Intent for troubleshooting user issues. I'm running into some permission problems. Here is the code I'm using:
public void email(String[] to, String subject) {
Intent email = new Intent(Intent.ACTION_SEND);
email.setType("*/*");
email.putExtra(android.content.Intent.EXTRA_EMAIL, to);
email.putExtra(android.content.Intent.EXTRA_SUBJECT, subject );
File file = new File("/data/data/com.product.companyname/databases/mydatabase.db");
if( file.exists() ) //this returns false, why?
{
if( file.canRead() )
{
Uri uri = Uri.fromFile(file);
email.putExtra(Intent.EXTRA_STREAM, uri);
activity.get().startActivity(Intent.createChooser(email, "Email DB File"));
}
}
}
The file is never attached because file.exists() always returns false, even though in adb I can clearly see that the file exists...
(pardon the redacted product info)
Why is this? If my app created this file, why can't it also read it? If I remove the file.exists() and file.canRead(), I get a toast on the e-mail intent saying "Permission denied for attachment".
Any help is appreciated. Thanks.
Aucun commentaire:
Enregistrer un commentaire