Hey,
I am trying to achive a simple demo where I embed a webpage (an html on my webserver with nothing but a model viewer component with dependencies) in my Android and iOS Xamarin app.
I am able to view the model and interact with it, but I am getting no ar-fallback error when I try to take it to Scene Viewer. Is it possible to launch Scene Viewer from inside a Webview from my app?
@satputerohan this topic veers a little bit outside of my expertise, but my best answer is two parts:
intent:// URL triggered by <model-viewer> and triggering the intent yourself with a modified WebView. See this Stack Overflow answer for an example of what I mean by "modified" in this case.In general, it should be possible to trigger Scene Viewer so long as the actual glTF file you are loading is hosted on a secure origin.
Hi @cdata,
I was wondering what intent I should trigger as I am getting following when I try it:
No Activity found to handle Intent { act=android.intent.action.VIEW typ=model/gltf-binary flg=0x1 pkg=com.google.ar.core }
I am trying to launch the viewer.ViewerActivity. Have you got any idea about this?
Hi @satputerohan @cdata you can do it this way in android java:
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
Intent intent;
// Perform generic parsing of the URI to turn it into an Intent.
try {
intent = Intent.parseUri(url, Intent.URI_INTENT_SCHEME);
} catch (Exception ex) {
Log.w("", "Bad URI %s");//, url, ex);
return false;
}
// Sanitize the Intent, ensuring web pages can not bypass browser
// security (only access to BROWSABLE activities).
intent.addCategory(Intent.CATEGORY_BROWSABLE);
//intent.setComponent(null);
intent.setComponent(new ComponentName("com.google.ar.core", "com.google.ar.core.viewer.IntentForwardActivity"));
Intent selector = intent.getSelector();
if (selector != null) {
selector.addCategory(Intent.CATEGORY_BROWSABLE);
selector.setComponent(null);
}
// Pass the package name as application ID so that the intent from the
// same application can be opened in the same tab.
intent.putExtra(Browser.EXTRA_APPLICATION_ID, "com.google.chrome");
try {
view.getContext().startActivity(intent);
return true;
} catch (ActivityNotFoundException ex) {
Log.w("", "No application can handle %s");
} catch (SecurityException ex) {
// This can happen if the Activity is exported="true", guarded by a permission, and sets
// up an intent filter matching this intent. This is a valid configuration for an
// Activity, so instead of crashing, we catch the exception and do nothing. See
// https://crbug.com/808494 and https://crbug.com/889300.
Log.w("", "SecurityException when starting intent for %s");
}
return false;
}
@PerspectivesLab that looks familiar :) did you borrow it from the Android Chrome source tree?
@PerspectivesLab that looks familiar :) did you borrow it from the Android Chrome source tree?
ohhhhh dyeah !!!
@PerspectivesLab Kudos for your earlier workaround suggest here, it helped me figure out a solution to this problem in my Flutter plugin that embeds <model-viewer> in an Android WebView.
@artob glad to help !
Most helpful comment
Hi @satputerohan @cdata you can do it this way in android java: