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:
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.
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With