lundi 31 août 2015

app that gets records from a sqlite db. I need this file to be then sent as an attachment. Not able to attach a CSV file

I have created a csv file that stores data from a sqlite database table. The csv file is stored in data/data/cache. The file is generated with no errors, but I am not able to retrieve the file and add it as an attachment to send in an email. The email sends successfully but does not have the csv file attached.

public void sendMail() {
    File csvFile = new File(getCacheDir() + "/emailtables/items.csv");
    Intent sendIntent = new Intent(Intent.ACTION_SEND);

    Uri uri = Uri.parse(csvFile.toString());
    Log.d(TAG, "Uri-path is: " + uri.getPath()); // or .toString()

    Intent i = new Intent(android.content.Intent.ACTION_SEND);
    i.setType("application/csv");
    i.putExtra(Intent.EXTRA_EMAIL, new String[]{"doggonemad11@gmail.com"});
    i.putExtra(Intent.EXTRA_SUBJECT, "Test Email - with Attachment");
    i.putExtra(Intent.EXTRA_TEXT, "This is a test Email with an Attachment.");
    i.putExtra(Intent.EXTRA_STREAM, uri);
    //startActivity(Intent.createChooser(i, "Select application"));
    startActivity(Intent.createChooser(i, "Send mail"));
}

Aucun commentaire:

Enregistrer un commentaire