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-unsubscr...@cordova.apache.org

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


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

Reply via email to