android - Chrome Custom Tabs throwing an error when chrome is not installed : No Activity found to handle Intent -


chrome custom tabs working fine when chrome installed when chrome not installed throwing error

customtabsintent.builder intentbuilder = new customtabsintent.builder(); intentbuilder.setshowtitle(true); customtabactivityhelper.opencustomtab(activityy, intentbuilder.build(), uri.parse(link), new webviewfallback()); 

logcat error info

fatal exception: main process: opensource.itspr.recycler, pid: 13114    android.content.activitynotfoundexception: no activity found handle intent { act=android.intent.action.view dat=http://www.google.com/... pkg=com.android.chrome (has extras) }        @ android.app.instrumentation.checkstartactivityresult(instrumentation.java:1889)        @ android.app.instrumentation.execstartactivity(instrumentation.java:1579)        @ android.app.activity.startactivityforresult(activity.java:3921)        @ android.app.activity.startactivityforresult(activity.java:3881)        @ android.support.v4.app.fragmentactivity.startactivityforresult(fragmentactivity.java:784)        @ android.app.activity.startactivity(activity.java:4208)        @ android.app.activity.startactivity(activity.java:4176)        @ android.support.customtabs.customtabsintent.launchurl(customtabsintent.java:165)        @ opensource.itspr.recycler.util.customtabs.customtabactivityhelper.opencustomtab(customtabactivityhelper.java:41)        @ opensource.itspr.recycler.holdernews.itemlink$1.onclick(itemlink.java:55)        @ android.view.view.performclick(view.java:5201)        @ android.view.view$performclick.run(view.java:21163)        @ android.os.handler.handlecallback(handler.java:746)        @ android.os.handler.dispatchmessage(handler.java:95)        @ android.os.looper.loop(looper.java:148)        @ android.app.activitythread.main(activitythread.java:5443)        @ java.lang.reflect.method.invoke(native method)        @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:728)        @ com.android.internal.os.zygoteinit.main(zygoteinit.java:618)                                                      

click here error info image{logcat}

webviewfallback.java

public class webviewfallback implements customtabactivityhelper.customtabfallback { @override public void openuri(activity activity, uri uri) {     log.d("i came here", string.valueof(uri));     intent intent = new intent(activity, webviewactivity.class);     intent.putextra(webviewactivity.extra_url, uri.tostring());     activity.startactivity(intent); } 

}

webviewactivity.java

public class webviewactivity extends appcompatactivity { public static final string extra_url = "extra.url";  @override protected void oncreate(bundle savedinstancestate) {     super.oncreate(savedinstancestate);     setcontentview(r.layout.activity_webview);     string url = getintent().getstringextra(extra_url);     webview webview = (webview)findviewbyid(r.id.web_view);     webview.setwebviewclient(new webviewclient());     websettings websettings = webview.getsettings();     websettings.setjavascriptenabled(true);     settitle(url);     getsupportactionbar().setdisplayhomeasupenabled(true);     webview.loadurl(url); } 

i assume question "how detect , handle chrome not being installed?" here go...

the key going packagemanager.queryintentactivities (intent intent, int flags):

retrieve activities can performed given intent.

parameters

intent - desired intent per resolveactivity().

flags - additional option flags. important match_default_only, limit resolution activities support category_default. can set match_all preventing filtering of results.

returns

a list<resolveinfo> containing 1 entry each matching activity. these ordered best worst match -- is, first item in list returned resolveactivity(intent, int). if there no matching activities, empty list returned.

something this:

customtabsintent.builder intentbuilder = new customtabsintent.builder(); intentbuilder.setshowtitle(true); final intent customtabsintent = intentbuilder.build(); final list<resolveinfo> customtabsapps = activityy.getpackagemanager().queryintentactivities(customtabsintent, 0);  if (customtabsapps.size() > 0) {     customtabactivityhelper.opencustomtab(activityy, customtabsintent, uri.parse(link), new webviewfallback()); } else {     // chrome not installed. display toast or notify user } 

Comments

Popular posts from this blog

c - How to retrieve a variable from the Apache configuration inside the module? -

c# - Constructor arguments cannot be passed for interface mocks -

python - malformed header from script index.py Bad header -