Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Alternative to Android WebView

I need to call a website inside my app which isn't displayed correctly by the native webview that comes along with android.

I already searched the net for some answers but I did find much beside this Is there an alternative to webview? .

As suggested in the post above, I already tested crosswalk. However, crosswalk has a lot of disadvantages:

  1. Very unstable and incomplete
  2. Way too large (including crosswalk will blow up you apk by at least 50 MB)
  3. IMHO not production ready.

So, I'm actually very desperately seeking an alternative but cannot find any.

Does anybody know a working and production ready webview? That would help me sooo much.

edit:

I had to add webView.getSettings().setDomStorageEnabled(true); to make the website work.

like image 954
toom Avatar asked Oct 22 '15 09:10

toom


2 Answers

The new Chrome custom tabs for Android app developers.

You can get more granular control by building a custom browsing experience on top of Android’s WebView, but at the cost of more technical complexity and an unfamiliar browsing experience for users. A new feature in the most recent version of Chrome called custom tabs addresses this tradeoff by allowing an app to customize how Chrome looks and feels, making the transition from app to web content fast and seamless.

Find Google code sample for Chrome custom tabs is here

For implementation:-

Please check Implementation guide for Chrome custom tabs

enter image description here

like image 197
pRaNaY Avatar answered Sep 27 '22 21:09

pRaNaY


Custom Tabs is one of the ways as @pRaNaY mentioned. Here is a quick implementation:

    private static final String EXTRA_CUSTOM_TABS_TOOLBAR_COLOR = "android.support.customtabs.extra.TOOLBAR_COLOR";
    private static final String PACKAGE_NAME = "com.android.chrome";
    private CustomTabsClient mClient;


@Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        warmUpChrome();
        launchUrl();
    }

   private void warmUpChrome() {
        CustomTabsServiceConnection service = new CustomTabsServiceConnection() {
            @Override
            public void onCustomTabsServiceConnected(ComponentName name, CustomTabsClient client) {               
                mClient = client;
                mClient.warmup(0);
            }

            @Override
            public void onServiceDisconnected(ComponentName name) {               
                mClient = null;
            }
        };

        CustomTabsClient.bindCustomTabsService(getApplicationContext(),PACKAGE_NAME, service);
    }

private void launchUrl() {
        Uri uri = getIntent().getData();
        if (uri == null) {
            return;
        }
        CustomTabsIntent customTabsIntent = new CustomTabsIntent.Builder().build();
        customTabsIntent.intent.setData(uri);
        customTabsIntent.intent.putExtra(EXTRA_CUSTOM_TABS_TOOLBAR_COLOR, getResources().getColor(R.color.red));


        PackageManager packageManager = getPackageManager();
        List<ResolveInfo> resolveInfoList = packageManager.queryIntentActivities(customTabsIntent.intent, PackageManager.MATCH_DEFAULT_ONLY);

        for (ResolveInfo resolveInfo : resolveInfoList) {
            String packageName = resolveInfo.activityInfo.packageName;
            if (TextUtils.equals(packageName, PACKAGE_NAME))
                customTabsIntent.intent.setPackage(PACKAGE_NAME);
        }

        customTabsIntent.launchUrl(this, uri);
    }

Gradle:

  compile "com.android.support:customtabs:23.0.0"

Additional Notes:

Calling warmUpChrome as early as possible will make the switch to the browser faster. The implementation in the example works with deeplinks, but if you want to launch it manually rewrite launchUrl and give a URI or a String as a parameter. The code is mostly stitched together from other stackoverflow answsers, but I have changed some parts of it to work for my case.

like image 24
Mikelis Kaneps Avatar answered Sep 27 '22 21:09

Mikelis Kaneps