Cordova 10和Android SDK 30:无法访问本地文件(“不允许加载本地资源:文件:///存储/模拟/0/Android/数据...”)

u2nhd7ah  于 2022-11-15  发布在  Android
关注(0)|答案(1)|浏览(345)

我试图更新我的cordova应用程序使用SDK 30而不是29,我有一个问题,我不能解决。
显然,在Android SDK 29和30之间,webview的setAllowAccessFile的默认值从true更改为false。问题是,在我的cordova应用中,我无法访问WebView API,因此需要使用config.xml文件更改此值。但我找不到任何合适的选项。
或者至少,我认为问题来自这里。
应用程序是一个Angular 的应用程序打包的Android与 cordova 10。我曾试图从Android 8.1.0切换到Android 10,以添加新的MANAGE_EXTERNAL_STORAGE权限,和其他一些东西,我很肯定不会工作,但,嗯...但没有改变任何事情。
如果你有任何想法如何做到这一点,或其他地方的问题可能来自,我很乐意接受你的建议。
谢谢你,谢谢你
配置文件:

<?xml version='1.0.0' encoding='utf-8'?>
<widget xmlns:android="http://schemas.android.com/apk/res/android" id="my.package.name" version="1.0.6" xmlns="http://www.w3.org/ns/widgets">
  <name>My package name</name>
  <description>

  </description>
  <author email="my.email@email.com" href="https://my.website">
    My website
  </author>

  <content src="index.html"/>

  <plugin name="cordova-plugin-whitelist" spec="1"/>
  <plugin name="cordova-plugin-wkwebview-engine" spec="https://github.com/driftyco/cordova-plugin-wkwebview-engine.git"/>
  <plugin name="cordova-plugin-wkwebview-engine" spec="1.2.1"/> 
  <plugin name="cordova-plugin-device" spec="~1.1.5"/>
  <plugin name="cordova-plugin-statusbar" spec="~2.2.2"/>
  <plugin name="cordova-plugin-splashscreen" spec="~4.0.2"/>
  <plugin name="cordova-plugin-file" spec="~6.0.0"/>
  <plugin name="cordova-plugin-zip" spec="~3.1.0"/>
  <plugin name="cordova-plugin-app-version" spec="~0.1.9"/>
  <plugin name="cordova-plugin-network-information" spec="~3.0.0"/>

  <plugin name="cordova-plugin-save-image" spec="0.2.5"/> 
  
  <plugin name="cordova-plugin-customurlscheme" spec="https://github.com/EddyVerbruggen/Custom-URL-scheme.git">
    <variable name="URL_SCHEME" value="my.package.name" />
  </plugin>

  <plugin name="cordova-plugin-intent" spec="https://github.com/napolitano/cordova-plugin-intent.git" />
  
  <feature name="StatusBar">
    <param name="ios-package" value="CDVStatusBar" onload="true"/>
  </feature>
  
  <preference name="Fullscreen" value="true" /> 
  <preference name="StatusBarOverlaysWebView" value="false"/>
  <preference name="DisallowOverscroll" value="true"/>
  <preference name="SplashScreen" value="screen"/>
  <preference name="SplashScreenDelay" value="3000"/>
  <preference name="SplashMaintainAspectRatio" value="true"/>
  <preference name="SplashScreenBackgroundColor" value="white"/>

  <preference name="android-minSdkVersion" value="21"/>
  <preference name="android-targetSdkVersion" value="30"/>

  <preference name="Orientation" value="landscape"/>

  <access origin="*"/>

  <allow-navigation href="http://localhost:8080/*"/>
  <feature name="CDVWKWebViewEngine">
    <param name="ios-package" value="CDVWKWebViewEngine"/>
  </feature>

  <preference name="CordovaWebViewEngine" value="CDVWKWebViewEngine"/>

  <allow-intent href="http://*/*"/>
  <allow-intent href="https://*/*"/>
  <allow-intent href="tel:*"/>
  <allow-intent href="sms:*"/>
  <allow-intent href="mailto:*"/>
  <allow-intent href="geo:*"/>

  <platform name="android">
    <edit-config file="AndroidManifest.xml" target="/manifest/application" mode="merge">
      <application android:allowBackup="false"/>
    </edit-config>
    <edit-config file="AndroidManifest.xml" target="/manifest/application" mode="merge">
      <application android:fullBackupContent="false"/>
    </edit-config>
    <edit-config file="AndroidManifest.xml" target="/manifest/application" mode="merge">
      <application android:largeHeap="true" />
    </edit-config>
    <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
    <preference name="AndroidLaunchMode" value="singleTask"/>
    <allow-intent href="market:*"/>
    <intent-filter>
      <action name="android.intent.action.SEND"/>
      <action name="android.intent.action.SEND_MULTIPLE"/>
      <category name="android.intent.category.DEFAULT"/>
      <data mimeType="*/*"/>
    </intent-filter>

    <intent-filter label="@string/launcher_name">
        <action name="android.intent.action.MAIN" />
        <category name="android.intent.category.LAUNCHER" />
    </intent-filter>
  </platform>

  <platform name="ios">
    <allow-intent href="itms:*"/>
    <allow-intent href="itms-apps:*"/>
     <preference name="WKWebViewOnly" value="true" />

    <feature name="CDVWKWebViewEngine">
        <param name="ios-package" value="CDVWKWebViewEngine" />
    </feature>

    <preference name="CordovaWebViewEngine" value="CDVWKWebViewEngine" />
  </platform>

  <engine name="ios" spec="~5.1.1"/>
  <engine name="android" spec="~10.0.0"/>
</widget>
rjee0c15

rjee0c151#

我们最近在Cordova应用中处理了Android 11的存储/安全问题。以下是我们发现的一些问题--这可能是也可能不是你的应用中正在发生的事情。更多信息可以在我的回答中找到(如何在PhoneGap将看到的Android目录中获取文档--我试图保持更新):

  • 如果可以的话,请远离MANAGE_EXTERNAL_STORAGE权限。谷歌为需要扫描文件系统的应用程序保留了该权限(我猜是病毒扫描程序等)--其他应用程序将被Play商店拒绝。
  • 我不知道该怎么说,但Android 6.x添加了一组额外的授权权限,您的应用需要在运行时请求这些权限(与AndroidManifext.xml文件中的权限相反)。我目前使用的是cordova.plugins.diagnostic插件,将ANDROIDX_VERSION标志设置为1.0.0。以下是相关代码:
// request read access to the external storage if we don't have it
                  cordova.plugins.diagnostic.getExternalStorageAuthorizationStatus(function (status) {
                      if (status === cordova.plugins.diagnostic.permissionStatus.GRANTED) {
                          console.log("External storage use is authorized");
                      } else {
                          cordova.plugins.diagnostic.requestExternalStorageAuthorization(function (result) {
                              console.log("Authorization request for external storage use was " + (result === cordova.plugins.diagnostic.permissionStatus.GRANTED ? "granted" : "denied"));
                          }, function (error) {
                              console.error(error);
                          });
                      }
                  }, function (error) {
                      console.error("The following error occurred: " + error);
                  });
                  // request runtime permissions if needed
                  cordova.plugins.diagnostic.getPermissionsAuthorizationStatus(function(statuses){
                      for (var permission in statuses){
                          switch(statuses[permission]){
                              case cordova.plugins.diagnostic.permissionStatus.GRANTED:
                                  console.log("Permission granted to use "+permission);
                                  break;
                              case cordova.plugins.diagnostic.permissionStatus.NOT_REQUESTED:
                                  console.log("Permission to use "+permission+" has not been requested yet; asking now");
                                  cordova.plugins.diagnostic.requestRuntimePermission(function(status){
                                      console.log("Runtime permission request result: " + status.toString());
                                  }, function(error){
                                      console.error("The following error occurred: "+error);
                                  }, permission);
                                  break;
                              case cordova.plugins.diagnostic.permissionStatus.DENIED_ONCE:
                                  console.log("Permission denied to use "+permission+" - ask again?");
                                  break;
                              case cordova.plugins.diagnostic.permissionStatus.DENIED_ALWAYS:
                                  console.log("Permission permanently denied to use "+permission+" - guess we won't be using it then!");
                                  break;
                          }
                      }
                  }, function(error){
                      console.error("The following error occurred: "+error);
                  },[
                      cordova.plugins.diagnostic.permission.WRITE_EXTERNAL_STORAGE,
                      cordova.plugins.diagnostic.permission.READ_EXTERNAL_STORAGE
                  ]);

请注意,还有其他插件可以请求适当的运行时权限/授权。诊断插件是我第一次遇到这个问题时遇到的第一个插件。
希望这能帮上忙。如果你需要比较笔记,我们的应用程序在GitHub上:https://github.com/adapt-it/adapt-it-mobile

相关问题