Android 打开本地pdf文件

        Intent intent = new Intent();
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        intent.setAction(android.content.Intent.ACTION_VIEW);
        intent.setClassName("cn.wps.moffice_eng",
                "cn.wps.moffice.documentmanager.PreStartActivity2");
        Uri uri = FileProvider.getUriForFile(PdfShowsActivity.this, "com.example.dsfiscal.fileProvider", new File("/storage/emulated/0/2013_PDF.pdf"));//在AndroidManifest中的android:authorities值
        intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);//添加这一句表示对目标应用临时授权该Uri所代表的文件
        intent.setData(uri);
        startActivity(intent);
        <provider
            android:name="android.support.v4.content.FileProvider"
            android:authorities="包名.fileProvider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/provider_paths" />
        </provider>
发布了180 篇原创文章 · 获赞 27 · 访问量 15万+

猜你喜欢

转载自blog.csdn.net/sinat_28238111/article/details/92840607