【问题标题】:Android intent.Action_view file permission deniedAndroid intent.Action_view 文件权限被拒绝
【发布时间】:2013-08-16 13:03:41
【问题描述】:

我正在尝试从我的存储中获取媒体文件并按 action_view 意图播放它。它保存在缓存中。我的代码如下所示:

@Override
    public void onClick(View arg0) {

        Intent viewMediaIntent = new Intent();
        viewMediaIntent.setAction(android.content.Intent.ACTION_VIEW);
        File file = new File(prefs.getAssetDir() + "/" + poi.getRoute().getId() + "/"
                + poiMedia.getContentMedia().getMedia().getFileName());
        Log.w("Karl",file.exists()+" < File exists"); 
        // returns true
        viewMediaIntent.setDataAndType(Uri.fromFile(file), "video/*");
        viewMediaIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        startActivity(viewMediaIntent);
    }
};

我得到的错误是权限被拒绝错误。我已经在清单中获得了用户权限 WRITE_EXTERNAL_STORAGE。

有人可以帮帮我吗?

编辑:

Logcat:

Failed to open file '/data/data/nl.kloeg.beleefroutes/cache/beleefRoutes/com.burokloeg.beleefroutes.0210OpPadMetRembrandt1/38669.mp4'. (Permission denied)
E/AwesomePlayer(1931): cannot create dataSource
W/AwesomePlayer(1931): onPrepareAsyncEvent() finishSetDataSource_l error(-2147483648)
W/AwesomePlayer(1931): abortPrepare() mIsAsyncPrepare (1), err (-2147483648)

【问题讨论】:

  • 发布 logctat 消息
  • 添加了 logcat 消息。
  • 你能发布完整的 logcat 吗?我的意思是整个异常报告,而不是所有内容。
  • 这就是我得到的一切......
  • E/MediaPlayer(22900): 错误 (1, -2147483648) E/MediaPlayer(22900): 错误 (1,-2147483648)

标签: android file android-intent view action


【解决方案1】:

这可能晚了,但我遇到了同样的事情。 我通过添加解决它的方式

    intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_GRANT_WRITE_URI_PERMISSION);

希望这对某人有所帮助。

【讨论】:

    【解决方案2】:

    您可能想要使用 FileProvider https://developer.android.com/reference/android/support/v4/content/FileProvider 并检查此 StackOverFlow 答案以获取示例代码:FileProvider is very confusing

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-04-01
      • 2013-07-03
      • 2015-12-21
      • 2020-06-03
      • 2020-08-27
      • 1970-01-01
      • 1970-01-01
      • 2011-11-10
      相关资源
      最近更新 更多