通过PendingIntent

时间:2016-11-26 05:14:58

标签: android android-pendingintent android-securityexception

我有一个mp3文件,我试图传递给其他应用,例如电子邮件或通过带有内容Uri的通知PendingIntent保存到Google云端硬盘。这在Nougat之前使用文件Uri很好,但现在我正在尝试使用提供程序。

清单:

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

提供商路径:

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

制作意图:

        Uri fileUri;
        boolean isN = Build.VERSION.SDK_INT >= Build.VERSION_CODES.N;
        if (isN) {
            fileUri  = FileProvider.getUriForFile(context,
                    "com.xxx.xxx.fileprovider",
                    file);

        } ...
        String mime = "audio/mpeg3";

        Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
        if (isN) emailIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
        emailIntent.setType(mime);
        emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
                file.getName());
        emailIntent
                .putExtra(
                        android.content.Intent.EXTRA_TEXT,
                        "xxx");

        emailIntent.putExtra(Intent.EXTRA_STREAM, fileUri);

        PendingIntent sIntent = PendingIntent.getActivity(
                context.getApplicationContext(), 0, emailIntent,
                PendingIntent.FLAG_UPDATE_CURRENT);

它适用于另一个pendingIntent我正在使用ACTION_VIEW而不是这个。我从Gmail和其他应用中获得以下SecurityException:

11-26 00:12:00.020 6496-6511/com.xxx.xxx E/DatabaseUtils: Writing exception to parcel
java.lang.SecurityException: Permission Denial: reading android.support.v4.content.FileProvider uri content://com.xxx.xxx.fileprovider/external_files/Music/xxxx/Sever%20-%20pitch%200.00%20-%20tempo-%20248-1%20-%20pitch%200.00%20-%20tempo-%20250-5.mp3 from pid=2905, uid=10069 requires the provider be exported, or grantUriPermission()
     at android.content.ContentProvider.enforceReadPermissionInner(ContentProvider.java:608)
     at android.content.ContentProvider$Transport.enforceReadPermission(ContentProvider.java:483)
     at android.content.ContentProvider$Transport.query(ContentProvider.java:212)
     at android.content.ContentProviderNative.onTransact(ContentProviderNative.java:112)
     at android.os.Binder.execTransact(Binder.java:565)
11-26 00:12:00.031 2905-2905/? E/Gmail: Error adding attachment
dcz: Security Exception from attachment uri
    at dda.a(SourceFile:416)
    at cgy.a(SourceFile:3395)
    at chh.run(SourceFile:7189)
    at cgy.a(SourceFile:17352)
    at cgy.a(SourceFile:1249)
    at cgy.E(SourceFile:1364)
    at cgy.onCreate(SourceFile:8561)
    at com.google.android.gm.ComposeActivityGmail.onCreate(SourceFile:202)
    at android.app.Activity.performCreate(Activity.java:6664)
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118)
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599)
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707)
    at android.app.ActivityThread.-wrap12(ActivityThread.java)
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460)
    at android.os.Handler.dispatchMessage(Handler.java:102)
    at android.os.Looper.loop(Looper.java:154)
    at android.app.ActivityThread.main(ActivityThread.java:6077)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:865)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:755)
 Caused by: java.lang.SecurityException: Permission Denial: reading android.support.v4.content.FileProvider uri content://com.xxx.xxx.fileprovider/external_files/Music/xxxx/Sever%20-%20pitch%200.00%20-%20tempo-%20248-1%20-%20pitch%200.00%20-%20tempo-%20250-5.mp3 from pid=2905, uid=10069 requires the provider be exported, or grantUriPermission()
    at android.os.Parcel.readException(Parcel.java:1683)
    at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:183)
    at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:135)
    at android.content.ContentProviderProxy.query(ContentProviderNative.java:421)
    at android.content.ContentResolver.query(ContentResolver.java:530)
    at android.content.ContentResolver.query(ContentResolver.java:472)
    at dda.a(SourceFile:363)
    at cgy.a(SourceFile:3395) 
    at chh.run(SourceFile:7189) 
    at cgy.a(SourceFile:17352) 
    at cgy.a(SourceFile:1249) 
    at cgy.E(SourceFile:1364) 
    at cgy.onCreate(SourceFile:8561) 
    at com.google.android.gm.ComposeActivityGmail.onCreate(SourceFile:202) 
    at android.app.Activity.performCreate(Activity.java:6664) 
    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1118) 
    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2599) 
    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2707) 
    at android.app.ActivityThread.-wrap12(ActivityThread.java) 
    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1460) 
    at android.os.Handler.dispatchMessage(Handler.java:102) 
    at android.os.Looper.loop(Looper.java:154) 
    at android.app.ActivityThread.main(ActivityThread.java:6077) 
    at java.lang.reflect.Method.invoke(Native Method) 

0 个答案:

没有答案