net::ERR_UNKNowN_URL_SCHEME intent://maps.yandex.ru?utm_medium=tab…
如何打开此链接,或者至少检查是否安装了适当的应用并运行它?
我试图通过实现自定义WebVIEwClIEnt来覆盖url加载:
@OverrIDe public boolean shouldOverrIDeUrlLoading(WebVIEw vIEw,String url) { if (!url.startsWith("http")) { getActivity().startActivity(new Intent(Intent.ACTION_VIEW).setData(Uri.parse(url))); return true; } return false; }
但在这种情况下,应用程序崩溃与ActivityNotFoundException.
02-24 20:58:51.886 31255-31255/ru.uxapps.voicesearch W/System.err: androID.content.ActivityNotFoundException: No Activity found to handle Intent { act=androID.intent.action.VIEW dat=intent://maps.yandex.ru?utm_medium=tab-maps&text=магазин&utm_source=serp&yandexuID=2258091361456330110 }02-24 20:58:51.886 31255-31255/ru.uxapps.voicesearch W/System.err: at androID.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1798)02-24 20:58:51.886 31255-31255/ru.uxapps.voicesearch W/System.err: at androID.app.Instrumentation.execStartActivity(Instrumentation.java:1512)02-24 20:58:51.886 31255-31255/ru.uxapps.voicesearch W/System.err: at androID.app.Activity.startActivityForResult(Activity.java:3930)02-24 20:58:51.886 31255-31255/ru.uxapps.voicesearch W/System.err: at androID.app.Activity.startActivityForResult(Activity.java:3890)02-24 20:58:51.886 31255-31255/ru.uxapps.voicesearch W/System.err: at androID.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:784)02-24 20:58:51.886 31255-31255/ru.uxapps.voicesearch W/System.err: at androID.app.Activity.startActivity(Activity.java:4213)02-24 20:58:51.886 31255-31255/ru.uxapps.voicesearch W/System.err: at androID.app.Activity.startActivity(Activity.java:4181)02-24 20:58:51.886 31255-31255/ru.uxapps.voicesearch W/System.err: at ru.uxapps.voicesearch.FWeb$CustomWebVIEwClIEnt.shouldOverrIDeUrlLoading(FWeb.java:70)02-24 20:58:51.886 31255-31255/ru.uxapps.voicesearch W/System.err: at com.androID.webvIEw.chromium.WebVIEwContentsClIEntAdapter.shouldOverrIDeUrlLoading(WebVIEwContentsClIEntAdapter.java:325)02-24 20:58:51.886 31255-31255/ru.uxapps.voicesearch W/System.err: at org.chromium.androID_webvIEw.AwContentsClIEntBrIDge.shouldOverrIDeUrlLoading(AwContentsClIEntBrIDge.java:266)02-24 20:58:51.886 31255-31255/ru.uxapps.voicesearch W/System.err: at org.chromium.base.SystemMessageHandler.nativeDoRunLoopOnce(Native Method)02-24 20:58:51.886 31255-31255/ru.uxapps.voicesearch W/System.err: at org.chromium.base.SystemMessageHandler.handleMessage(SystemMessageHandler.java:37)02-24 20:58:51.886 31255-31255/ru.uxapps.voicesearch W/System.err: at androID.os.Handler.dispatchMessage(Handler.java:102)02-24 20:58:51.886 31255-31255/ru.uxapps.voicesearch W/System.err: at androID.os.Looper.loop(Looper.java:148)02-24 20:58:51.886 31255-31255/ru.uxapps.voicesearch W/System.err: at androID.app.ActivityThread.main(ActivityThread.java:5417)02-24 20:58:51.887 31255-31255/ru.uxapps.voicesearch W/System.err: at java.lang.reflect.Method.invoke(Native Method)
即使安装了必需的应用程序,应用程序也会崩溃.但是如果在Chrome中打开此链接,它会显示maps.yandex.ru网站,或者如果已安装则会打开应用.
是否有一个通用的解决方案,适用于所有意图://链接?
谢谢你的建议.
结果,我写了一个遵循这个逻辑的链接处理程序:
>在同一WebVIEw中打开http和https
>试图处理已知的方案(电话:等)
>如果找不到已知活动,则解析intent:scheme并尝试运行相应的应用程序
>如果未安装所需的应用程序,请尝试将提供的回退URL加载到当前的WebVIEw中
>如果没有提供后备网址,请重定向到市场并要求安装所需的应用
代码是:
mWebVIEw.setWebVIEwClIEnt(new CustomWebVIEwClIEnt());//...private class CustomWebVIEwClIEnt extends WebVIEwClIEnt { @OverrIDe public boolean shouldOverrIDeUrlLoading(WebVIEw webVIEw,String url) { if (url.startsWith("http")) return false;//open web links as usual //try to find browse activity to handle uri Uri parsedUri = Uri.parse(url); PackageManager packageManager = getActivity().getPackageManager(); Intent browseIntent = new Intent(Intent.ACTION_VIEW).setData(parsedUri); if (browseIntent.resolveActivity(packageManager) != null) { getActivity().startActivity(browseIntent); return true; } //if not activity found,try to parse intent:// if (url.startsWith("intent:")) { try { Intent intent = Intent.parseUri(url,Intent.URI_INTENT_SCHEME); if (intent.resolveActivity(getActivity().getPackageManager()) != null) { getActivity().startActivity(intent); return true; } //try to find fallback url String fallbackUrl = intent.getStringExtra("browser_fallback_url"); if (fallbackUrl != null) { webVIEw.loadUrl(fallbackUrl); return true; } //invite to install Intent marketIntent = new Intent(Intent.ACTION_VIEW).setData( Uri.parse("market://details?ID=" + intent.getPackage())); if (marketIntent.resolveActivity(packageManager) != null) { getActivity().startActivity(marketIntent); return true; } } catch (URISyntaxException e) { //not an intent uri } } return true;//do nothing in other cases }}
也许它需要一些清理,但它可能会有所帮助.请告诉我,如果您知道更简单的方法,我仍然在寻找最佳解决方案.
总结以上是内存溢出为你收集整理的Web开放式意图://协议全部内容,希望文章能够帮你解决Web开放式意图://协议所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)