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

故事扮演 提交于 2019-12-20 01:42:11

问题


Google Drive used to send file:// URIs as the data for ACTION_VIEW intents. It now sends content:// URIs instead. Why did this change?


回答1:


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.



来源:https://stackoverflow.com/questions/35351652/why-doesnt-the-google-drive-app-on-android-send-file-uris-anymore

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