1

I am trying to render google map embedded in a webpage through WebView. Though it works on the emulator it's not working on device (android 2.3.6 and 4.4.2). Below is my code:

WebView webview = (WebView) findViewById(R.id.webView1);
webview.setWebViewClient(new WebViewClient());
webview.getSettings().setJavaScriptEnabled(true);

String url = "http://mywebsite.com/mobile_map.php";
webView.loadUrl(url);

enter image description here

  1. I tried a direct url and not my webpage as "https://www.google.co.in/maps/@20.3008841,85.7699553,12z?hl=en" This also works on AVD but not on devices.

  2. Tried to implement an AsysnkTask and also handle the ssl error as follows:

    public class LoadSocialNetworkUrlTask extends AsyncTask<String, String, Void> { 
        protected void onPreExecute() {
            dialog = new ProgressDialog(MapActivity.this);
            dialog.setMessage("Loading,Please wait...");
            dialog.setIndeterminate(true);
            dialog.setCancelable(true);
            dialog.show();
        }
    
        protected void onProgressUpdate(final String... url) {
            try {
    
                ((WebView) webView).getSettings().setJavaScriptEnabled(true);
                ((WebView) webView).setBackgroundColor(Color.TRANSPARENT);  
                ((WebView) webView).setWebViewClient(new WebViewClient() {
                        @Override
                        public void onReceivedSslError(WebView view, SslErrorHandler handler, SslError error) {
                            handler.proceed(); // Ignore SSL certificate errors
                        }
    
                        @Override
                        public void onPageFinished(WebView view, String url) {
                            // TODO hide your progress image
                            super.onPageFinished(view, url);
                            dialog.dismiss();
                        }
                    });
    
                ((WebView) webView).loadUrl(url[0]);
    
            } catch (Exception e) {
                e.printStackTrace();
                dialog.dismiss();
            }
    
        }
    
        @Override
        protected Void doInBackground(String... url) {
            try {
                publishProgress(url);
    
            } catch (Exception e) {
                e.printStackTrace();
                dialog.dismiss();
            }   
            return null;
        }
    }
    

    but the same result. What am I missing? Should not we display a page containing map in webview and handle map directly with api? Do I have to make some setting in the device? (the device is connected to internet.)

Dexter
  • 4,036
  • 3
  • 47
  • 55
  • Dexter@: Have you declared the INTERNET permission for your app (see http://stackoverflow.com/questions/25135595/permission-denied-missing-internet-permission)? Also, did you try opening other pages (e.g. the main google page) from your app? – Mikhail Naganov Mar 09 '15 at 09:30
  • yes, Internet permission added and viewed other page (non map) successfully. Problem is in map pages. – Dexter Mar 09 '15 at 11:27
  • Well, if you say you can reproduce this problem on Android 4.4.2, you can try debugging it on that device via remote debugging (https://developer.chrome.com/devtools/docs/remote-debugging#debugging-webviews). Use "Network" tab of DevTools to check what is happening to your requests. – Mikhail Naganov Mar 09 '15 at 12:39
  • your wifi connected or data? The image you provided doesn't suggest either of them. – so_jin_ee Mar 09 '15 at 17:12
  • wifi. The screen shot was taken after wifi is disabled so there is no notification. – Dexter Mar 09 '15 at 19:17
  • Was there ever any resolution to this? We're encountering the same issue. Try to load a Google map URL in the webview and it's just displaying a blank page on our devices. – George Clingerman May 27 '15 at 20:44

0 Answers0