Android"打开..."给出不同的URL(意图过滤器)

时间:2017-07-19 08:01:36

标签: android pdf android-intent

我希望我的应用程序能够打开外部pdf,因此实现了这个intent-filter,允许我在选择PDF时打开我的应用程序。

        <intent-filter>
            <action android:name="android.intent.action.VIEW" />
            <category android:name="android.intent.category.DEFAULT" />
            <category android:name="android.intent.category.BROWSABLE" />
            <data android:mimeType="application/pdf" />
        </intent-filter>

在某些设备上,数据网址如下:

content://downloads/all_downloads/4860

我可以用这段代码打开:

Cursor returnCursor = this.cordova.getActivity().getApplicationContext().getContentResolver().query(returnUri, null, null, null, null);

在One plus One等其他设备上(无法确定Android版本的差异),意图收到了此网址:

file:///storage/emulated/0/Download/pdf-test.pdf

我无法打开此网址,因为我可能无权访问该网址。谁知道我做错了什么?

1 个答案:

答案 0 :(得分:0)

好吧,毕竟这很容易。不得不请求读/写外部存储的权限,以便我可以处理文件URL。