0

I have looked everywhere and I can't find out how to do this; I'm so frustrated...

How can I allow the user to send (via email) the SQLite db file?

That's it in a nutshell. I can convert it to string and attach, but I want to send the actual db file. And I'm using a new phone that doesn't have an external SD card.

The app is just a form that the user fills out, then it's saved to a SQLite database. That works wonderfully. As does printing the db to string (text) and then sending it. But, I want the user to email the actual db file (so I can use C# to read, process it, and "recreate" a real form).

Or should I be using something other than SQLite?

Edit: This is as far as I've made it. It seems to work, but it does not actually attach the file or rather the file is "blank/empty". Debug log says no such file or directory. screenshot of debug log here:http://imgur.com/oyzdtuJ

//trying again to send a SQL db file
//this seems to work and shows that it's attaching a file, but the file is empty so it won't attach
//gmail will say "cant attach empty file"
private void sendFile(String email){

    File myFile = this.getFileStreamPath("testresults.db");
    if(myFile != null) {
        Log.d("LOG PRINT SHARE DB", "File Found, Here is file location: " + myFile.toString());
    }else {
        Log.w("Tag", "file not found!");
    }

    Uri contentUri = FileProvider.getUriForFile(this, "com.columbiawestengineering.columbiawest.MainActivity", myFile);
    Log.d("LOG PRINT SHARE DB", "contentUri got: here is contentUri: " + contentUri.toString());

    //grant permision for app with package "com.columbiawestengineering.columbiawest", eg. before starting other app via intent
    this.grantUriPermission("com.columbiawestengineering.columbiawest", contentUri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
    Log.d("LOG PRINT SHARE DB", "permission granted, here is contentUri: " + contentUri.toString());

    Intent shareIntent = new Intent();
    shareIntent.setAction(Intent.ACTION_SEND);
    shareIntent.setType("application/octet-stream");
    shareIntent.putExtra(Intent.EXTRA_SUBJECT, "blaaa subject");
    String to[] = { email };
    shareIntent.putExtra(Intent.EXTRA_EMAIL, to);
    shareIntent.putExtra(Intent.EXTRA_TEXT, "blah blah message");
    shareIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
    shareIntent.putExtra(Intent.EXTRA_STREAM, contentUri);
    startActivityForResult(Intent.createChooser(shareIntent, "Send mail..."), 1252);

    //revoke permisions
    this.revokeUriPermission(contentUri, Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);

}
Dan Lehto
  • 185
  • 1
  • 2
  • 10

2 Answers2

0

See this answer

Android Utility to send sqlite db to server

You could do this any number of ways. I'd say posting it to a web service is easiest. If you can only use email then I'd compress and encode it and attach it to an email but that sounds painful.

Community
  • 1
  • 1
Harry
  • 10,932
  • 1
  • 25
  • 40
  • Java code to "get" the db file? It is mostly just user input text, checkboxes, etc. so it's not really that large. – Dan Lehto Apr 04 '16 at 17:23
  • I'd still be cautious with email though, some email clients and server have limits on how much data they will allow etc. If you can use a web service that would be the preferred route, if not then you are looking at email or FTP etc. – Harry Apr 04 '16 at 17:27
  • We have our own email client and server so it's okay. And the file is really small (very little actual text). But I can't seem to get the actual db file to send. Heck, I can't even seem to reference it. I'm so frustrated with this right now. – Dan Lehto Apr 06 '16 at 00:19
0

Solved. FileProvider cannot access the database directory. The db file must be copied to the files directory before it is attached. See solution here:Android: FileProvider "Failed to find configured root"

Community
  • 1
  • 1
Dan Lehto
  • 185
  • 1
  • 2
  • 10