Search code examples
androidxamarin.androidautodesk-forgeautodesk-viewer

How to load SVF to Autodeks Forge viewer Offline in Android?


I am trying to load SVF file on Autodesk forge viewer locally in Xamarin.Android. I copied the content to my project Assets/html folder. My code to load the content looks like this.

In MyWebViewClient.cs

 public WebResourceResponse ShouldInterceptRequest(WebView webView, IWebResourceRequest request)
    {
        try
        {
            Android.Net.Uri url = request.Url;
            //Uri uri = url;
            String path = url.Path;
            if (path.StartsWith("/android_asset/"))
            {
                try
                {
                    AssetManager assetManager = this.context.Assets;
                    String relPath = path.Replace("/android_asset/", "").Replace("gz", "gz.mp3");
                    //InputStream stream = assetManager.Open(relPath);
                    return new WebResourceResponse(null, null, assetManager.Open(relPath));
                }
                catch (IOException ex)
                {
                    String str = ex.Message;
                }
            }
        }
        catch (Exception ex) { }

        return null;
    }

Then in my Activity.cs

 SetContentView(Resource.Layout.webview);
 var wbMain = FindViewById<WebView>(Resource.Id.webView1);
 wbMain.Settings.DomStorageEnabled = true;
 wbMain.Settings.JavaScriptEnabled = true;
 wbMain.Settings.AllowFileAccessFromFileURLs = true;
 wbMain.Settings.AllowUniversalAccessFromFileURLs = true;
 var customWebViewClient = new MyWebViewClient(BaseContext);
 customWebViewClient.OnPageLoaded += MyWebViewClient_OnPageLoaded;

 wbMain.SetWebViewClient(customWebViewClient);
 wbMain.LoadUrl("file:///android_asset/html/index.html");

This only loads the side views not the main viewer. enter image description here

Whats the reason for this and how can I resolve this?


Solution

  • Please note that the sample is a bit outdated and there have been some changes in our legal terms since then. Currently, the legal T&C state that all viewer assets (JS, CSS, icons, images, etc.) must be coming from the Autodesk domain.

    If you need to be able to run your viewer-based app in "temporarily offline" scenarios (for example, on a construction site), I'd suggest that you look at the following blog post: https://forge.autodesk.com/blog/disconnected-workflows. This approach (using Service Workers and Cache API) is consistent with the legal requirements.