After successfully running krpano with WebVR on Chrome and Firefox, I encountered an issue where the cardboard button was not visible or enabled when embedded in a WebView on Android. However, to my surprise, the compiled apk with the WebView showed the cardboard button on another device.
Now, I am puzzled about how to force the same behavior on my phone. I know that it works on Chrome and Firefox Mobile but not within my WebView implementation. What configuration settings do I need to tweak to ensure WebVR is universally enabled across all Android devices capable of supporting it?
static final String BASE = "http://app.imaginarydomain.com";
static final Pattern PATH_PATTERN = Pattern.compile(Pattern.quote(BASE) + "/(.*)");
...
WebSettings webSettings = webView.getSettings();
webSettings.setBlockNetworkLoads(false);
webSettings.setJavaScriptEnabled(true);
webView.setWebViewClient(new TestWebViewClient());
webView.loadUrl(BASE + "/tour.html");
...
class TestWebViewClient extends WebViewClient {
@Override
public WebResourceResponse shouldInterceptRequest(WebView view, String url) {
Matcher matcher = PATH_PATTERN.matcher(url);
if (matcher.matches()) {
String asset = "sample-tour-cardboard/" + matcher.group(1);
try {
InputStream is = getAssets().open(asset);
String extension = MimeTypeMap.getFileExtensionFromUrl(url);
String type = "application/octet-stream";
if (extension != null) {
type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
}
return new WebResourceResponse(type, "UTF-8", is);
} catch (IOException e) {
Log.e("ERROR!", "Asset loading error: " + asset, e);
}
}
return null;
}
}
Despite attempting to enable WebVR fake mode in the krpano WebView plugin, I still faced challenges.
It seems like the WebVR plugin may be conducting a specific check within the WebView context that only passes on Chrome Mobile, Firefox Mobile, or other implementers by different devices.