6

I have a (big) problem on chromebook with a functionnality working fine on "classic" android devices (phones, tablets).

I try to send an e-mail with an attached file.

Here's a portion of code (api>=23).

        Intent email = new Intent(Intent.ACTION_SEND);
        String[] str = new String[1];
        str[0] = "destination@yahoo.fr";
        email.putExtra(Intent.EXTRA_EMAIL, str);

        email.putExtra(Intent.EXTRA_TEXT, "My text");
        email.putExtra(Intent.EXTRA_SUBJECT, "My subject");

        Uri uri = FileProvider.getUriForFile(this, "com.TTT.fileprovider", new File(dest));

        email.putExtra(android.content.Intent.EXTRA_STREAM, uri);

        email.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION
                | Intent.FLAG_GRANT_WRITE_URI_PERMISSION
                | Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION);

        email.setType("message/rfc822");

        startActivity(email);

On my Phone (android 9 api 28), gmail app is called, all text fields are filled with correct information and the file (myResume.pdf) is correctly attached.

When sent then received, the e-mail contains a readable pdf file. that's cool.

With my chromebook (PB 314 / v. 83.0.4103.119), gmail is called, all text fields are filled with correct information but no attached file.

LogCat indicates :

2020-06-27 15:25:50.886 127-2348/? I/ActivityManager: START u0 {act=android.intent.action.SEND typ=message/rfc822 flg=0x43 cmp=org.chromium.arc.applauncher/.ChromeBrowserProxyActivity clip={message/rfc822 T:My text} (has extras)} from uid 10040
2020-06-27 15:25:50.887 565-565/? D/ArcDummy: New intent received: Intent { act=android.intent.action.SEND typ=message/rfc822 flg=0x10000043 cmp=org.chromium.arc.applauncher/.ChromeBrowserProxyActivity clip={message/rfc822 T:My text} (has extras) }
2020-06-27 15:25:50.887 565-565/? W/ContextImpl: Calling a method in the system process without a qualified user: android.app.ContextImpl.startService:1531 android.content.ContextWrapper.startService:664 org.chromium.arc.applauncher.DummyActivity.forwardIntentIfNeeded:155 org.chromium.arc.applauncher.DummyActivity.onNewIntent:121 android.app.Activity.performNewIntent:7255 
2020-06-27 15:25:50.892 127-2348/? W/WindowManagerInjector: Attempted to get menu state of app token with non existing window
2020-06-27 15:25:50.896 780-842/? D/ArcMediaControllerManager: onTaskMovedToFront: 2
2020-06-27 15:25:50.897 780-842/? I/ArcMediaControllerManager: onAppBecameActive: org.chromium.arc.applauncher
2020-06-27 15:25:50.892 127-2348/? W/WindowManagerInjector: Attempted to get menu state of app token with non existing window
2020-06-27 15:25:50.900 127-760/? W/ActivityManager: For security reasons, the system cannot issue a Uri permission grant to content://com.TTT.fileprovider/images/myResume.pdf [user 0]; use startActivityAsCaller() instead
2020-06-27 15:25:50.901 127-760/? W/WindowManagerInjector: Attempted to get menu state of app token with non existing window   

when testing on android phones, this sentence never appears :

For security reasons, the system cannot issue a Uri permission grant to content://com.TTT.fileprovider/images/myResume.pdf [user 0]; use startActivityAsCaller() instead  

more information about previous code :

the file "myResume.pdf" is copied to a special directory for beeing shared with gmail.
    
dest is a string (/storage/emulated/0/MyDir/myResume.pdf) obtained with
    
Environment.getExternalStorageDirectory().toString() > /storage/emulated/0/
my sub directory, created and verified > MyDir/
the file > myResume.pdf
    

the file AndroidManifest.xml includes

<provider
        android:name="android.support.v4.content.FileProvider"
        android:authorities="com.TTT.fileprovider"
        android:exported="false"
        android:grantUriPermissions="true">
        <meta-data
            android:name="android.support.FILE_PROVIDER_PATHS"
            android:resource="@xml/provider_paths"/>
</provider>

the file @xml/provider_paths is :

<?xml version="1.0" encoding="utf-8"?>
    <paths xmlns:android="http://schemas.android.com/apk/res/android">
    <external-path name="images"  path="myDir/"/>
    </paths>

I hope I have explained my problem with all details,
Can anyone help me? Thank you very much!

kodaski
  • 136
  • 4
  • Rather than putting the file in external storage, try putting it in internal storage (e.g., `getCacheDir()`), and see if you have better luck. Note that you will need to update your `provider_paths` to match. – CommonsWare Jun 27 '20 at 15:07
  • thanks @CommonsWare. I tried. same problem. works with phone. doesn't work with chromebook. fn=/data/user/0/com.TTT/cache/myDir/myResume.pdf ... For security reasons, the system cannot issue a Uri permission grant to content: //com.TTT.fileprovider/imagesBis/myResume.pdf [user 0]; use startActivityAsCaller() instead () – kodaski Jun 27 '20 at 17:23

1 Answers1

2

the problem is finally solved by using gmail app (after downloaded it) then using it instead of gmail/web/chrome.

kodaski
  • 136
  • 4