Google Drive used to send file://
URIs as the data for ACTION_VIEW
intents. It now sends content://
URIs instead. Why did this change?
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