zoukankan      html  css  js  c++  java
  • startActivity报错exposed beyond app through Intent.getData()

    背景:

    需要调用外部已安装的APP来打开文件,直接报错。

    解决:

    1、的application节的里面

    <provider
                android:name="androidx.core.content.FileProvider"
                android:authorities="com.xx.xxx.fileprovider"
                android:exported="false"
                android:grantUriPermissions="true">
                <meta-data
                    android:name="android.support.FILE_PROVIDER_PATHS"
                    android:resource="@xml/file_paths"
                    />
            </provider>

    2、file_apths;

    <?xml version="1.0" encoding="utf-8"?>
    <paths xmlns:android="http://schemas.android.com/apk/res/android">
        <external-path path="." name="external_storage_root" />
    </paths>

    3、打开比如docx

    //android获取一个用于打开Word文件的intent
        public static Intent getWordFileIntent(Context mContext, String Path) {
            File file = new File(Path);
            Intent intent = new Intent("android.intent.action.VIEW");
            intent.addCategory("android.intent.category.DEFAULT");
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            Uri uri = FileProvider.getUriForFile(mContext, "com.xx.xxx.fileprovider", file);//Uri.fromFile(file);
            intent.setDataAndType(uri, "application/msword");
            return intent;
        }

    记得用startActivity开启哦。

    不出什么意外的话,会弹出一个列表,选择打开文件。

    道法自然
  • 相关阅读:
    O'Reilly总裁提姆奥莱理:什么是Web 2.0
    在MFC程序中显示JPG/GIF图像
    VC窗体设计集锦
    VxWorks使用说明书
    关于双缓冲绘图之二
    如何将EVC4工程升级到VS.NET2005工程
    某个正在运行的程序的CPU占用率
    如何去掉回车键和取消键
    探索NTFS
    ARM上的C编程
  • 原文地址:https://www.cnblogs.com/jiduoduo/p/15080928.html
Copyright © 2011-2022 走看看