【问题标题】:Do I need runtime permissions to open a local html file created by the app in android我是否需要运行时权限才能打开由应用程序在 android 中创建的本地 html 文件
【发布时间】:2016-03-26 15:09:13
【问题描述】:

我正在尝试使用

打开应用程序先前创建的 html
Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setDataAndType(Uri.fromFile(htmlFile), "text/html");
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);

并且带有 api 23 的模拟器说错误被拒绝。我要重新申请权限吗?

【问题讨论】:

  • "error denied" 什么被拒绝了?访问本地文件?
  • 最好显示完整的堆栈跟踪。
  • 您没有使用问题中的代码访问 Android 上的文件。您正在要求第三方应用程序打开文件。能不能完全取决于htmlFile的值是多少。

标签: android file permissions


【解决方案1】:

它无法打开文件,因为我需要去设置/应用程序并设置浏览器权限从存储打开..

【讨论】:

    【解决方案2】:

    或者你可以使用webView.,直接在app里面加载html页面。

    web = (WebView)findViewById(R.id.web);
    web.loadData(html, "text/html; charset=UTF-8", null);
    

    在上面一行中,html 可以是包含所需 html 的字符串。如果 html 是某个文件,那么您可以先加载文件并将其读入字符串。

    String html="<html>\n" +
                "<body>\n" +
                "<\body>\n" +
                "<\html>\n";
    

    这种方式效率不高,但在某些情况下可能有用

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-25
      • 1970-01-01
      相关资源
      最近更新 更多