Why doesn't the Google Drive app on Android send file:// URIs anymore?

淺唱寂寞╮ 提交于 2019-12-01 22:31:56

As of Feb 17th 2016, the Drive Apps no longer sends file:// URIs to other apps. This was done to improve security and has been encouraged by Android since 2013.

Content URIs can be resolved to a ParcelFileDescriptor using ContentResolver as shown:

Intent intent = getIntent();
if (Intent.ACTION_VIEW.equals(intent.getAction()) {
    Uri incomingData = getIntent().getData();
    ParcelFileDescriptor pfd =
        getContentResolver().openFileDescriptor(incomingData, "r");
    // Use file ...
}

Additionally, apps should no longer use intent filters that restrict the URI to the file scheme:

<intent-filter>
    <action android:name="android.intent.action.VIEW" />
        <data android:scheme="file"/> <!-- Drive will not show this app -->
</intent-filter>

Mime-type and other filters will continue to work and are encouraged:

<intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <data android:mimeType="video/mpeg"/>
</intent-filter>

More information about file sharing and content URIs can be found at developer.android.com.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!