Mani Ahmadian
Mani Ahmadian

Reputation: 21

Problem: Loading Mapbox in Webview (Android Studio Project)

I have an html file in my website: http://manizani.ir/hamyar_gas_php/map/map_app.html

I want to show it on my Android Application. I created an Activity and use a Webview to load above url. But nothing is loaded and it shows me just an empty activity.

I can load any other web pages successfully, but not about my url.

Please help me to solve it.

Thanks a lot

activity_map_web.xml :

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MapWebActivity">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <WebView
            android:id="@+id/webview_intro"
            android:layout_width="match_parent"
            android:layout_height="wrap_content">
        </WebView>

    </LinearLayout>

</RelativeLayout>

//////////////End of file//////////////////

MapWebActivity.java :

public class MapWebActivity extends AppCompatActivity {

    WebView WV;
    String url = "";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_map_web);

        try {

            WV = (WebView) findViewById(R.id.webview_intro);

            WV.getSettings().setLoadsImagesAutomatically(true);
            WV.getSettings().setJavaScriptEnabled(true);
            WV.setScrollBarStyle(View.SCROLLBARS_INSIDE_OVERLAY);
            WV.getSettings().setBuiltInZoomControls(true);

            WV.getSettings().setDomStorageEnabled(true);
            WV.getSettings().setAppCacheEnabled(true);
            WV.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
            WV.getSettings().setRenderPriority(WebSettings.RenderPriority.HIGH);

            WV.setWebViewClient(new WebViewClient());


                  url="http://manizani.ir/hamyar_gas_php/map/map_app.html";

                WV.loadUrl(url);


        } catch (Exception ex) {
            Toast.makeText(this, ex.toString(), Toast.LENGTH_SHORT).show();
        }
    }
}

Upvotes: 1

Views: 944

Answers (1)

Vahid Rajabi
Vahid Rajabi

Reputation: 359

Mapbox use WebGL and may be is not support on your device. webview log :

 [INFO:CONSOLE(31)] "Error: Failed to initialize WebGL", source: https://api.mapbox.com/mapbox-gl-js/v2.2.0/mapbox-gl.js (31)

more at here

Upvotes: 1

Related Questions