gpt4 book ai didi

android - Chrome 自定义选项卡在未安装 chrome 时抛出错误 : No Activity found to handle Intent

转载 作者:太空狗 更新时间:2023-10-29 16:33:06 25 4
gpt4 key购买 nike

Chrome 自定义选项卡在安装 chrome 时工作正常,但在未安装 chrome 时会抛出错误

CustomTabsIntent.Builder intentBuilder = new CustomTabsIntent.Builder();
intentBuilder.setShowTitle(true);
CustomTabActivityHelper.openCustomTab(activityy, intentBuilder.build(), Uri.parse(link), new WebviewFallback());

LogCat 错误信息

FATAL EXCEPTION: main
Process: opensource.itspr.recycler, PID: 13114
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=http://www.google.com/... pkg=com.android.chrome (has extras) }
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1889)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1579)
at android.app.Activity.startActivityForResult(Activity.java:3921)
at android.app.Activity.startActivityForResult(Activity.java:3881)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:784)
at android.app.Activity.startActivity(Activity.java:4208)
at android.app.Activity.startActivity(Activity.java:4176)
at android.support.customtabs.CustomTabsIntent.launchUrl(CustomTabsIntent.java:165)
at opensource.itspr.recycler.Util.customtabs.CustomTabActivityHelper.openCustomTab(CustomTabActivityHelper.java:41)
at opensource.itspr.recycler.HolderNews.ItemLink$1.onClick(ItemLink.java:55)
at android.view.View.performClick(View.java:5201)
at android.view.View$PerformClick.run(View.java:21163)
at android.os.Handler.handleCallback(Handler.java:746)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5443)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:728)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)

错误信息图片

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);
}

最佳答案

我假设您的问题是“如何检测和处理未安装的 Chrome?”所以给你...

key 可能是 PackageManager.queryIntentActivities (Intent intent, int flags) :

Retrieve all activities that can be performed for the given intent.

Parameters

intent - The desired intent as per resolveActivity().

flags - Additional option flags. The most important is MATCH_DEFAULT_ONLY, to limit the resolution to only those activities that support the CATEGORY_DEFAULT. You can also set MATCH_ALL for preventing the filtering of the results.

Returns

A List<ResolveInfo> containing one entry for each matching Activity. These are ordered from best to worst match -- that is, the first item in the list is what is returned by resolveActivity(Intent, int). If there are no matching activities, an empty list is returned.

像这样:

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 a toast or something to notify the user
}

关于android - Chrome 自定义选项卡在未安装 chrome 时抛出错误 : No Activity found to handle Intent,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34823420/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com