android - 是否有任何隐含意图的解决方案不适用于某些设备
问题描述
具有 webview 的 Android Activity,如果 url 与 upi:// 匹配,则意图选择器应弹出其与所有设备一起使用,但某些设备(如带有 android 9 的 mi)无法正常工作
if (url.startsWith("upi://")) { this if 检查 url 是否以 upi:// 开头,如果它以 upi 开头,选择器会弹出所有包名称以 upi 开头的应用程序。它适用于所有设备
@SuppressLint("RestrictedApi")
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
if (url.startsWith("upi://")) {
Toast.makeText(home.this, url, Toast.LENGTH_SHORT).show();
webView.stopLoading();
try {
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setData(Uri.parse(url));
Intent chooser = Intent.createChooser(intent, "Pay with...");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
startActivityForResult(chooser, 1, null);
}
else
{
Toast.makeText(home.this, "ELSE", Toast.LENGTH_SHORT).show();
}
} catch (android.content.ActivityNotFoundException ex) {
String MakeShortText = "PhonePe have not been installed";
Toast.makeText(home.this, MakeShortText, Toast.LENGTH_SHORT).show();
}
}
return true;
}
});
}
日志
2019-10-27 18:55:15.781 17960-17960/? E/ChooserActivityInjector: getResolversForIntent [boolean, boolean, interface java.util.List]
java.lang.NoSuchMethodException: getResolversForIntent [boolean, boolean, interface java.util.List]
at java.lang.Class.getMethod(Class.java:2068)
at java.lang.Class.getDeclaredMethod(Class.java:2047)
at com.android.internal.app.ChooserActivityInjector.createSortedResloveListByResolverController(ChooserActivityInjector.java:91)
at com.android.internal.app.ChooserActivityInjector.startInterceptByMiAppStore(ChooserActivityInjector.java:66)
at com.android.internal.app.ResolverActivity.onCreate(ResolverActivity.java:372)
at com.android.internal.app.ChooserActivity.onCreate(ChooserActivity.java:274)
at android.app.Activity.performCreate(Activity.java:7224)
at android.app.Activity.performCreate(Activity.java:7213)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1272)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2926)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3081)
at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:78)
at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:108)
at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:68)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1831)
at android.os.Handler.dispatchMessage(Handler.java:106)
at android.os.Looper.loop(Looper.java:201)
at android.app.ActivityThread.main(ActivityThread.java:6810)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:547)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:873)
解决方案
推荐阅读
- ruby-on-rails - 将erb标签添加到rails中的link_to类
- jquery - 无法选中好选择多个下拉列表的复选框?
- c# - 将参数分配给 List
- excel - 如何选择一系列单元格直到特定值
- authentication - 微服务的去中心化身份验证
- python - 如何在 Gurobi 中线性化约束
- python-3.x - Atom 脚本在 Mac 上找不到 Python 3 的路径
- reactjs - 什么时候使用没有依赖的 useEffect?
- .net - TransactionScope 需要在 C# MVC 中启用 DTC
- spring - hibernate回滚错误信息不清楚