阅读 170

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">
            data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/file_paths"
                />
        

2、file_apths;

"1.0" encoding="utf-8"?>
"http://schemas.android.com/apk/res/android">
    "." name="external_storage_root" />

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开启哦。

 

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

 

原文:https://www.cnblogs.com/jiduoduo/p/15080928.html

文章分类
代码人生
版权声明:本站是系统测试站点,无实际运营。本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 XXXXXXo@163.com 举报,一经查实,本站将立刻删除。
相关推荐