How to make a Cross Origin Request work on Android

Hi, there!

I have an HTML Game saved to the internal memory of an Android tablet. I’m trying to run it without leaving Unity using a Webview Plugin from Gree: GitHub - gree/unity-webview

I’ve worked most of the details out so far, but I’m stuck with a limitation from Android’s side. The game needs to make some Cross Origin Requests, which Android does not allow when you try to access ** file:// ** . Instead, I’m requried to use ** http:// **, ** https:// ** or ** data:// **

08-31 18:35:52.163  20063-20063/com.CompanyName.ProjectName I/chromium﹕ [INFO:CONSOLE(0)] "XMLHttpRequest cannot load file:///storage/emulated/0/Android/data/com.CompanyName.ProjectName/files/GameName/frameworks/cocos2d-html5/moduleConfig.json. Cross origin requests are only supported for protocol schemes: http, data, https.", source:
file:///storage/emulated/0/Android/data/com.CompanyName.ProjectName/files/GameName/index.html (0)

I’ve worked with two possible solutions:

  1. Creating a Localhost on the application so I can access it using http://
  2. Bypassing the restriction by tricking Android (as mentioned here: android - Access local file in a WebView - Stack Overflow)

Still, I wasn’t able to figure out how to implement any of these options. Does anyone have ideas on how to go about this? Or perhaps another solution I haven’t thought of?

Also, if anyone needs more info, I’d be glad to provide it.

Maybe this could work If the smartphone browser is chrome?
https://chrome.google.com/webstore/detail/allow-control-allow-origi/nlfbmbojpeacfghkpbjhddihlkkiljbi/related?hl=en