Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android webview call use chrome Browser

I had made a webapp which works fine in mobile chrome but in chromium I see some problem, so is it possible to call android chrome from app instead of webview in app.

I could not find any way to do it. 1: I don not care whether chrome is installed or not 2:i wrote below webview to open local html webview but i see few js issue with drag drop which works fine in android chrome browser

below is my code :

public class MainActivity extends Activity {
    private static final String URL = "file:///android_asset/index.html";
    private WebView mWebView;

    @SuppressLint("SetJavaScriptEnabled")
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        getWindow().requestFeature(Window.FEATURE_PROGRESS);
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mWebView = (WebView) findViewById(R.id.webview); 
        mWebView.getSettings().setJavaScriptEnabled(true);
        mWebView.setWebViewClient(new WebViewClient());
        mWebView.setWebChromeClient(new WebChromeClient());

        mWebView.getSettings().setRenderPriority(RenderPriority.HIGH);
        mWebView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);


         final Activity activity = this;
         mWebView.setWebChromeClient(new WebChromeClient() {
           public void onProgressChanged(WebView view, int progress) {
             activity.setProgress(progress * 1000);
           }
         });

        mWebView.loadUrl(URL);
    }

    @Override
    public void onConfigurationChanged(Configuration newConfig){
        super.onConfigurationChanged(newConfig);
    }

}

i wrote code which open url using chrome intent can i use such type of feature to use chrome as web view.

 protected void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
//         setContentView(R.layout.activity_main);
         String url = "http://www.google.com";
         String packageName = "com.android.chrome";

         Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
         browserIntent.setPackage(packageName);
         browserIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

         //Activity context = null;
         List<ResolveInfo> activitiesList = getPackageManager().queryIntentActivities(
                 browserIntent, -1);
         if(activitiesList.size() > 0) {
             // Found the browser on the device, launch it
             startActivity(browserIntent);
         } else {
             // The browser isn't installed, so we should prompt the user to get
             Intent playStoreIntent = new Intent(Intent.ACTION_VIEW);
             playStoreIntent.setData(Uri.parse("market://details?id="+packageName));
             playStoreIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
             startActivity(playStoreIntent);
         }


     }
like image 310
mydeve Avatar asked Jul 02 '26 23:07

mydeve


1 Answers

You may consider using Crosswalk android webview , which is based on same underlying engine as chromium/chrome.

It is packaged with your APK, so it is self-contained; You do not need chrome to be installed.

Its supposed to give you better performance than standard webview, with more built-in features.

Here is a hello world to get you started

like image 154
ashoke Avatar answered Jul 05 '26 13:07

ashoke