zoukankan      html  css  js  c++  java
  • android7.0后对于file://的限制

    错误信息:

    04-18 14:56:58.283  4440  4440 W System.err: android.os.FileUriExposedException: file:///storage/emulated/0/temp.jpg exposed beyond app through ClipData.Item.getUri()
    04-18 14:56:58.283  4440  4440 W System.err:    at android.os.StrictMode.onFileUriExposed(StrictMode.java:1799)
    04-18 14:56:58.283  4440  4440 W System.err:    at android.net.Uri.checkFileUriExposed(Uri.java:2346)
    04-18 14:56:58.283  4440  4440 W System.err:    at android.content.ClipData.prepareToLeaveProcess(ClipData.java:845)
    04-18 14:56:58.283  4440  4440 W System.err:    at android.content.Intent.prepareToLeaveProcess(Intent.java:9044)
    04-18 14:56:58.283  4440  4440 W System.err:    at android.content.Intent.prepareToLeaveProcess(Intent.java:9029)
    04-18 14:56:58.283  4440  4440 W System.err:    at android.app.Instrumentation.execStartActivity(Instrumentation.java:1525)
    04-18 14:56:58.283  4440  4440 W System.err:    at android.app.Activity.startActivityForResult(Activity.java:4341)
    04-18 14:56:58.283  4440  4440 W System.err:    at android.support.v4.app.BaseFragmentActivityJB.startActivityForResult(BaseFragmentActivityJB.java:48)
    04-18 14:56:58.283  4440  4440 W System.err:    at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:75)
    04-18 14:56:58.283  4440  4440 W System.err:    at android.app.Activity.startActivityForResult(Activity.java:4299)
    04-18 14:56:58.283  4440  4440 W System.err:    at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:856)
    04-18 14:56:58.283  4440  4440 W System.err:    at com.longdai.android.ui.ui2.PersonInfoActivity.b(PersonInfoActivity.java:110)
    04-18 14:56:58.283  4440  4440 W System.err:    at com.longdai.android.ui.ui2.PersonInfoActivity$2.onClick(PersonInfoActivity.java:388)
    04-18 14:56:58.283  4440  4440 W System.err:    at android.view.View.performClick(View.java:5642)
    04-18 14:56:58.283  4440  4440 W System.err:    at android.view.View$PerformClick.run(View.java:22489)
    04-18 14:56:58.283  4440  4440 W System.err:    at android.os.Handler.handleCallback(Handler.java:751)
    04-18 14:56:58.283  4440  4440 W System.err:    at android.os.Handler.dispatchMessage(Handler.java:95)
    04-18 14:56:58.283  4440  4440 W System.err:    at android.os.Looper.loop(Looper.java:154)
    04-18 14:56:58.283  4440  4440 W System.err:    at android.app.ActivityThread.main(ActivityThread.java:6217)
    04-18 14:56:58.283  4440  4440 W System.err:    at java.lang.reflect.Method.invoke(Native Method)
    04-18 14:56:58.283  4440  4440 W System.err:    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1108)
    04-18 14:56:58.283  4440  4440 W System.err:    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:998)
    04-18 14:56:58.323   548   635 W SurfaceFlinger: eventControl: set enabled=0

    官网对于此的限制说明:

    https://developer.android.com/reference/android/os/FileUriExposedException.html

    The exception that is thrown when an application exposes a file:// Uri to another app.
    This exposure is discouraged since the receiving app may not have access to the shared path. For example, the receiving app may not have requested the READ_EXTERNAL_STORAGE runtime permission, or the platform may be sharing the Uri across user profile boundaries.
    Instead, apps should use content:// Uris so the platform can extend temporary permission for the receiving app to access the resource.
    This is only thrown for applications targeting N or higher. Applications targeting earlier SDK versions are allowed to share file:// Uri, but it's strongly discouraged.

    对于代码变化的说明:

    在6.0的代码:

    /frameworks/base/core/java/android/os/StrictMode.java

    1752    /**
    1753     * @hide
    1754     */
    1755    public static void onFileUriExposed(String location) {
    1756        final String message = "file:// Uri exposed through " + location;
    1757        onVmPolicyViolation(null, new Throwable(message));
    1758    }

    在7.0的代码:

    /frameworks/base/core/java/android/os/StrictMode.java

    1793    /**
    1794     * @hide
    1795     */
    1796    public static void onFileUriExposed(Uri uri, String location) {
    1797        final String message = uri + " exposed beyond app through " + location;
    1798        if ((sVmPolicyMask & PENALTY_DEATH_ON_FILE_URI_EXPOSURE) != 0) {
    1799            throw new FileUriExposedException(message);
    1800        } else {
    1801            onVmPolicyViolation(null, new Throwable(message));
    1802        }
    1803    }
  • 相关阅读:
    Maker DAO 与稳定币 Dai
    0x 协议治理体系,Part-2:Q&A
    Gnosis白皮书
    Digix:密码学资产中的黄金标准
    闪电网络主心骨——HTLC(哈希时间锁定)简介
    如何减少PDF文件的大小
    以太坊:创建 ERC-20 token
    Sublime Text 3 快捷键大全
    数据库学习第二季第三集:各种编程语言从数据库中获得数据方式小结
    数据库学习第二季第三集:各种编程语言从数据库中获得数据方式小结
  • 原文地址:https://www.cnblogs.com/jason207489550/p/6743438.html
Copyright © 2011-2022 走看看