Android7.0android.os.FileUriExposedException: file:storageemulated0through Intent.getData()

    xiaoxiao2021-04-01  41

    关于android 7.0 错误 Caused by: android.os.FileUriExposedException: file:///storage/emulated/0/c90d0cf8b0.dwg exposed beyond app through Intent.getData()

    错误代码 :`

    Intent intent = new Intent("android.intent.action.VIEW"); intent.addCategory("android.intent.category.DEFAULT"); intent.addFlags (Intent.FLAG_ACTIVITY_NEW_TASK); intent.setDataAndType (Uri.fromFile(file), "application/pdf"); startActivity(intent);`

    解决方案: 把最后一行 startActivity(intent) 修改成 startActivity(Intent.createChooser(intent, “标题”));

    解决之后的代码:`

    Intent intent = new Intent("android.intent.action.VIEW"); intent.addCategory("android.intent.category.DEFAULT"); intent.addFlags (Intent.FLAG_ACTIVITY_NEW_TASK); intent.setDataAndType (Uri.fromFile(file), "application/pdf"); // startActivity(intent); startActivity(Intent.createChooser(intent, "标题"));`
    转载请注明原文地址: https://ju.6miu.com/read-665517.html

    最新回复(0)