Quantcast
Viewing all articles
Browse latest Browse all 7

Answer by Saik Caskey for Error: Cannot attach empty file in GMAIL app using File provider

In case it helps- here's what I do in an app debug function with a few files, it shouldn't really be any different. I do copy/export them into a user-public folder first before attaching them, and make them world readable.

 if (verifyStoragePermissions(c)) {        final Intent intent = new Intent(Intent.ACTION_SEND_MULTIPLE);        intent.setType("text/plain");        intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"recipient@email.address"});        intent.putExtra(Intent.EXTRA_SUBJECT, "Email Subject");        //build up message        ArrayList<Uri> uris = new ArrayList<>();        StringBuilder content = new StringBuilder();        content.append(                String.format(                        c.getString(R.string.message_log_upload_email_body) +"\n\nmodelDesc:%s \n\nmanuf:%s \n\naId: %s,\n\nhIid: %s,\n\nfbId: %s.",                        Build.MODEL, Build.MANUFACTURER, getSomeVar1(), getSomeVar2(), getSomeVar3())        );        content.append("\n\nMy logged in account id is: ").append(getAccountId(c)).append(".");        content.append("\n\nHere's an overview of my attachments:\n");        for (String s : addresses) {            File f = new File(s);            //noinspection ResultOfMethodCallIgnored            f.setReadable(true, false);            Uri add = Uri.fromFile(f);            //add attachment manifest            content.append(String.format(Locale.UK, "|->  %s (%.3f kb)\n", f.getName(), (float) f.length() / 1024));            uris.add(add);        }        //attach the things        intent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);        //set content/message        intent.putExtra(Intent.EXTRA_TEXT, content.toString());        c.startActivity(intent);    }}

addresses is a String[] param to that function. I build it up by making the functions I use to export the files return arrays of strings of the addresses of the files they've exported - as I initially store the files in my app's private storage


Viewing all articles
Browse latest Browse all 7

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>