You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by GitBox <gi...@apache.org> on 2022/10/12 16:26:40 UTC

[GitHub] [cordova-plugin-file-transfer] pieshop commented on issue #345: Cordova 11 > Android incompatible

pieshop commented on issue #345:
URL: https://github.com/apache/cordova-plugin-file-transfer/issues/345#issuecomment-1276441905

   Here is a hook I did:
   
   config.xml:
   `<hook type="after_prepare" src="hooks/hook-android-fix-file-transfer.js" info="Comment out whitelist code" />`
   
   hook-android-fix-file-transfer.js:
   
   ```
   const fs = require('fs-extra');
   const path = require('path');
   
   const DIR = path.join(__dirname, '../');
   
   /**
    * This hook removes whitelist from FileTransfer.java
    * see : https://github.com/apache/cordova-plugin-file-transfer/issues/345
    */
   module.exports = function main(ctx) {
       if (!ctx.opts.platforms.includes('android')) return;
   
       console.log('[hook] Fix file transfer on android');
   
       const file = `${DIR}/platforms/android/app/src/main/java/org/apache/cordova/filetransfer/FileTransfer.java`;
       let code = `import org.apache.cordova.Whitelist;`
       let commentedOut = `//  Commented out by hook-android-fix-file-transfer.js
   //  import org.apache.cordova.Whitelist;`
   
       let str = fs.readFileSync(file, 'utf8');
       str = str.replace(code, commentedOut);
   
       code = `        if (shouldAllowRequest == null) {
               try {
                   Method gwl = webView.getClass().getMethod("getWhitelist");
                   Whitelist whitelist = (Whitelist)gwl.invoke(webView);
                   shouldAllowRequest = whitelist.isUrlWhiteListed(source);
               } catch (NoSuchMethodException e) {
               } catch (IllegalAccessException e) {
               } catch (InvocationTargetException e) {
               }
           }`
       commentedOut = `//  Commented out by hook-android-fix-file-transfer.js
   //          if (shouldAllowRequest == null) {
   //            try {
   //                Method gwl = webView.getClass().getMethod("getWhitelist");
   //                Whitelist whitelist = (Whitelist)gwl.invoke(webView);
   //                shouldAllowRequest = whitelist.isUrlWhiteListed(source);
   //            } catch (NoSuchMethodException e) {
   //            } catch (IllegalAccessException e) {
   //            } catch (InvocationTargetException e) {
   //            }
   //        }`
   
       str = str.replace(code, commentedOut);
   
       fs.writeFileSync(file, str, 'utf8');
   };
   
   ```
   


-- 
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: commits-unsubscribe@cordova.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@cordova.apache.org
For additional commands, e-mail: commits-help@cordova.apache.org