表现
<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>
意图创作
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);
问题
这在运行Jelly Bean的两个设备上工作正常,但是对于运行姜饼的两个设备来说,它不起作用.
我得到的例外如下.
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 nullE/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.access00(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 nullE/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
我的想法
所以在某处下来,FLAG_GRANT_READ_URI_PERMISSION标志我加入的意图是不行的?
我也认为这个问题可能是因为我把这个uri作为EXTRA_STREAM的意图,由于某些原因,较旧的AndroID版本不会选择这个? (尚未找到任何文件).
任何帮助是赞赏.
解决方法context.grantUriPermission(packagename,uri,Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);//revoke permisionscontext.revokeUriPermission(uri,Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
作为最后的手段,如果您不能提供包名称,您可以授予所有可以处理特定意图的应用程序的权限:
//grant permisions for all apps that can handle given intentIntent intent = new Intent();intent.setAction(Intent.ACTION_SEND);...List<ResolveInfo> resInfoList = context.getPackageManager().queryIntentActivitIEs(intent,PackageManager.MATCH_DEFAulT_ONLY);for (ResolveInfo resolveInfo : resInfoList) { String packagename = resolveInfo.activityInfo.packagename; context.grantUriPermission(packagename,Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);}总结
以上是内存溢出为你收集整理的android – 意图FLAG_GRANT_READ_URI_PERMISSION在Gingerbread中使用FileProvider全部内容,希望文章能够帮你解决android – 意图FLAG_GRANT_READ_URI_PERMISSION在Gingerbread中使用FileProvider所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)