How do I ensure Android phonegap/cordova apps use Chrome webviews?

前端 未结 6 1336
长情又很酷
长情又很酷 2020-12-23 01:52

I\'m writing a game app that twists SVG graphics until they cry \"Uncle!\". The program works OK on an iPad (safari/webkit) when hosted from a web server, for which no more

6条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-23 02:51

    One option would be to launch the Chrome browser with a link to the appropriate site.

    This isn't a great user experience, but might get you some of the way there.

    You can check for and launch the Chrome Browser with something along the lines of:

        String url = "http://www.totallyawesomeurl.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);
    
        List activitiesList = context.getPackageManager().queryIntentActivities(
                browserIntent, -1);
        if(activitiesList.size() > 0) {
            // Found the browser on the device, launch it
            context.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);
            context.startActivity(playStoreIntent);
        }
    

    It's worth noting that Chrome for Android is only available for ICS devices and above, so you might want to ensure you set the minimumTargetSDK to 14 and perhaps switch to using Opera for older version of Android if you site works in Opera which has package name "com.opera.browser"

提交回复
热议问题