jackysee commented on issue #1361:
URL: 
https://github.com/apache/cordova-android/issues/1361#issuecomment-978763603


   My workaround is convert those `file://` to `__file__` in js.
   And create a pathHandler in plugin. 
   In my case I just clone cdv photo plugin and modify the source.
   One thing to notice that you cannot get query parameter in path, so in the 
case of cdvphotolibrary I need to specially handle them
   ```java
   
     @Override   
     public CordovaPluginPathHandler getPathHandler() {
         return new CordovaPluginPathHandler(new 
WebViewAssetLoader.PathHandler() {
               @Nullable
               @Override
               public WebResourceResponse handle(@NonNull String path) {
                   Log.d(TAG, "Path Handler " + path);
                   //e.g. 
cdvphotolibrary/thumbnail/photoId=3112&width=512&height=384&quality=0.8
                   if(path.startsWith(PHOTO_LIBRARY_PROTOCOL)) {
                       path = path.replaceAll("^cdvphotolibrary/", 
"cdvphotolibrary://");
                       path = path.replaceAll("thumbnail/", "thumbnail?");
                       path = path.replaceAll("photo/", "photo?");
                       Uri uri = Uri.parse(path);
                       Log.d(TAG, "URI " + uri);
                       Uri remappedUri = remapUri(uri);
                       Log.d(TAG, "RemappedUri " + uri);
                       if(remappedUri != null) {
                           try {
                               CordovaResourceApi.OpenForReadResult result = 
handleOpenForRead(remappedUri);
                               Log.d(TAG, "Result " + 
result.inputStream.available());
                               return new WebResourceResponse(result.mimeType, 
"utf-8", result.inputStream);
                           } catch (IOException e) {
                               LOG.e(TAG, "error open cdvphotolibrary resource 
"+ e);
                           }
                       }
                   }
   
                   if(path.startsWith("__file__/")) {
                       File file = new File(path.replaceAll("^__file__/", "/"));
                       Uri fileUri = Uri.fromFile(file);
                       Log.d(TAG, "fileUri " + fileUri);
                       String mimeType = 
webView.getResourceApi().getMimeType(fileUri);
                       Log.d(TAG, "mimeType " + mimeType);
                       try {
                           InputStream is = 
getContext().getContentResolver().openInputStream(fileUri);
                           Log.d(TAG, "Result " + is.available());
                           return new WebResourceResponse(mimeType, "utf-8", 
is);
                       } catch(Exception e) {
                           LOG.e(TAG, "error open file resource "+ e);
                       }
                   }
                   return null;
               }
           });
     }
   
   ```


-- 
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