erisu commented on issue #426:
URL: 
https://github.com/apache/cordova-plugin-file/issues/426#issuecomment-920924613


   > Hello,
   > I just want to share a solution I found to my problem as it's related to 
this thread.
   > 
   > **Problem with SDK 30 :**
   > Out team used the path externalApplicationStorageDirectory to store some 
assets of the application, wich are downloaded the first time the user connect 
to the application.
   > But we weren't able to access those files, and got an ACCESS_DENIED error.
   > 
   > **Solution :**
   > I made a little modification in CordovaActivity.java in init() function
   > 
   > ```
   > protected void init() {
   >     appView = makeWebView();
   >     createViews();
   >     if (!appView.isInitialized()) {
   >         appView.init(cordovaInterface, pluginEntries, preferences);
   >     }
   >   
   >     /********** MODIFICATION SDK 30 **********/
   >         WebView webView = (SystemWebView)(appView.getEngine().getView());
   >         WebSettings webSettings = webView.getSettings();
   >         webSettings.setAllowFileAccess(true);
   >     /**********************************/
   >   
   >     cordovaInterface.onCordovaInit(appView.getPluginManager());
   >   
   >     // Wire the hardware volume controls to control media if desired.
   >     String volumePref = preferences.getString("DefaultVolumeStream", "");
   >     if ("media".equals(volumePref.toLowerCase(Locale.ENGLISH))) {
   >         setVolumeControlStream(AudioManager.STREAM_MUSIC);
   >     }
   >  }
   > ```
   > 
   > you also need to add these import :
   > 
   > ```
   > import android.webkit.WebView;
   > import android.webkit.WebSettings;
   > import org.apache.cordova.engine.SystemWebView;
   > ```
   > 
   > Hope this can help some of you :)
   
   I also want to include what Google says about setting `setAllowFileAccess` 
to `true`, for informational purposes:
   
   > **`setAllowFileAccess`**
   >
   > Enables or disables file access within WebView. Note that this enables or 
disables file system access only. Assets and resources are still accessible 
using `file:///android_asset` and `file:///android_res`.
   >
   > **Note:** Apps should not open **file://** URLs from any external source 
in WebView, don't enable this if your app accepts arbitrary URLs from external 
sources. It's recommended to always use androidx.webkit.WebViewAssetLoader to 
access files including assets and resources over **http(s)://** schemes, 
instead of **file://** URLs. To prevent possible security issues targeting 
**Build.VERSION_CODES.Q** and earlier, you should explicitly set this value to 
**false**.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to