Absicht FLAG_GRANT_READ_URI_PERMISSION Mit FileProvider in Lebkuchen

Ich habe ein Problem, wo ich versuche, um mehrere Dateien anzuhängen von meinem internen Speicher auf eine E-Mail Absicht, indem Sie Ihnen mit einem FileProvider erklärt in meinem manifest und die Gewährung der lese-uri-Berechtigungen. Hier ist mein code.

Manifest

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

Absicht Schaffung

        emailIntent = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE);
        emailIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,new String[] {"randomemailaddress"});

    ArrayList<Uri> uris = new ArrayList<Uri>();
    File directory = getFilesDir();
    File[] list = directory.listFiles();
    for (File f : list) {
        if (f.getName().contains("log") && f.getName().contains(".txt"))
            uris.add(FileProvider.getUriForFile(this, "com.company.example.logprovider",f));
    }

    emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);

Das Problem

Dieser funktioniert auf zwei Geräte mit Jelly Bean doch es funktioniert nicht, für zwei Geräte mit gingerbread.

Ausnahme bin ich immer wie folgt.

java.lang.RuntimeException: Unable to start activity ComponentInfo{com.google.android.gm/com.google.android.gm.ComposeActivity}: java.lang.SecurityException: Permission Denial: opening provider android.support.v4.content.FileProvider from ProcessRecord{40b2db08 3885:com.google.android.gm/10110} (pid=3885, uid=10110) requires null or null
E/AndroidRuntime( 3885):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1659)
E/AndroidRuntime( 3885):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1675)
E/AndroidRuntime( 3885):    at android.app.ActivityThread.access$1500(ActivityThread.java:121)
E/AndroidRuntime( 3885):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:943)
E/AndroidRuntime( 3885):    at android.os.Handler.dispatchMessage(Handler.java:99)
E/AndroidRuntime( 3885):    at android.os.Looper.loop(Looper.java:138)
E/AndroidRuntime( 3885):    at android.app.ActivityThread.main(ActivityThread.java:3701)
E/AndroidRuntime( 3885):    at java.lang.reflect.Method.invokeNative(Native Method)
E/AndroidRuntime( 3885):    at java.lang.reflect.Method.invoke(Method.java:507)
E/AndroidRuntime( 3885):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:878)
E/AndroidRuntime( 3885):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:636)
E/AndroidRuntime( 3885):    at dalvik.system.NativeStart.main(Native Method)
E/AndroidRuntime( 3885): Caused by: java.lang.SecurityException: Permission Denial: opening provider android.support.v4.content.FileProvider from ProcessRecord{40b2db08 3885:com.google.android.gm/10110} (pid=3885, uid=10110) requires null or null
E/AndroidRuntime( 3885):    at android.os.Parcel.readException(Parcel.java:1322)
E/AndroidRuntime( 3885):    at android.os.Parcel.readException(Parcel.java:1276)
E/AndroidRuntime( 3885):    at android.app.ActivityManagerProxy.getContentProvider(ActivityManagerNative.java:1882)
E/AndroidRuntime( 3885):    at android.app.ActivityThread.getProvider(ActivityThread.java:3365)
E/AndroidRuntime( 3885):    at android.app.ActivityThread.acquireProvider(ActivityThread.java:3390)
E/AndroidRuntime( 3885):    at android.app.ContextImpl$ApplicationContentResolver.acquireProvider(ContextImpl.java:1728)
E/AndroidRuntime( 3885):    at android.content.ContentResolver.acquireProvider(ContentResolver.java:754)
E/AndroidRuntime( 3885):    at android.content.ContentResolver.query(ContentResolver.java:262)
E/AndroidRuntime( 3885):    at com.google.android.gm.ComposeArea.addAttachment(ComposeArea.java:736)
E/AndroidRuntime( 3885):    at com.google.android.gm.ComposeArea.initFromExtras(ComposeArea.java:699)
E/AndroidRuntime( 3885):    at com.google.android.gm.ComposeActivity.initFromExtras(ComposeActivity.java:1482)
E/AndroidRuntime( 3885):    at com.google.android.gm.ComposeActivity.finishOnCreateAfterAccountSelected(ComposeActivity.java:1020)
E/AndroidRuntime( 3885):    at com.google.android.gm.ComposeActivity.onCreate(ComposeActivity.java:259)
E/AndroidRuntime( 3885):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
E/AndroidRuntime( 3885):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1623)
E/AndroidRuntime( 3885):    ... 11 more

Meine Gedanken

Also irgendwo hinunter die Linie, die FLAG_GRANT_READ_URI_PERMISSION Flagge, ich bin das hinzufügen, um die Absicht nicht ist, zu arbeiten?

Ich glaube auch, dass das Problem kann sein weil ich bin anbringen der uris, die auf die Absicht als EXTRA_STREAM und für einige Grund, auf älteren Android-Versionen nicht das abholen? (haben nicht alle Dokumentation, die auf dieser noch).

Jede Hilfe ist willkommen.

InformationsquelleAutor StuStirling | 2014-02-10
Schreibe einen Kommentar