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:https://i.sstatic.net/JgdGb.jpg

//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);

}

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

3 Comments

Java code to "get" the db file? It is mostly just user input text, checkboxes, etc. so it's not really that large.
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.
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.
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"

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.