Embed in mobile apps
This section covers the process of embedding web AR projects into mobile applications through the use of web views, taking advantage of the native web browsers included in the OS.
Web AR experiences require access to multiple device sensors such as the camera or gyroscope. Make sure you include all required permissions through app manifiest files (manifest.xml and Info.plist for Android and iOS respectively).
Android
First, make sure the app manifest.xml has the following permissions:
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS" />
Then, configure the webview as follows (location might not be required depending on the experience type):
void initializeWebView() {
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webSettings.setDomStorageEnabled(true);
webSettings.setGeolocationEnabled(true);
webSettings.setMediaPlaybackRequiresUserGesture(false);
webSettings.setAllowFileAccessFromFileURLs(true);
webSettings.setAllowUniversalAccessFromFileURLs(true);
webView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
return false;
}
});
webView.setWebChromeClient(new WebChromeClient() {
public void onGeolocationPermissionsShowPrompt(String origin, GeolocationPermissions.Callback callback) {
callback.invoke(origin, true, false);
}
@Override
public void onPermissionRequest(final PermissionRequest request) {
request.grant(request.getResources());
}
});
webView.loadUrl("<your_experience_embed_URL_here>");
}
As you may see, this enables some required browser APIs and grants permissions for the web view.
It is important to note that this process of embedding experiences in Android apps is not compatible with Web XR functionality.
iOS
iOS native web views (WKWebView) are the preferred way of integration.
Compatibility: iOS 14.3 or above (prior this version, native webviews could not access to the camera)
The following configuration is required for the web view:
let configuration = WKWebViewConfiguration()
configuration.allowsInlineMediaPlayback = true
configuration.mediaTypesRequiringUserActionForPlayback = []
webView = WKWebView(frame: .zero, configuration: configuration)
Also you may need to override WKDelegates to allow navigation and creating the webview with the new configuration:
public func webView(_ webView: WKWebView, decidePolicyFor navigationAction: WKNavigationAction, decisionHandler: @escaping (WKNavigationActionPolicy) -> Void) {
decisionHandler(.allow)
}
public func webView(_ webView: WKWebView, createWebViewWith configuration: WKWebViewConfiguration, for navigationAction: WKNavigationAction, windowFeatures: WKWindowFeatures) -> WKWebView? {
if navigationAction.targetFrame == nil {
webView.load(navigationAction.request)
}
return nil
}
Finally load the experience URL:
webView.load(url: URL(string: "<your_experience_embed_URL_here>")!)