gpt4 book ai didi

android - 未找到具有有效 http ://prefix 的 Activity (浏览器)

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:28:44 26 4
gpt4 key购买 nike

所以我的应用程序出现如下异常:

android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=http://google.com (has extras) }
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1512)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1384)
at android.app.Activity.startActivityForResult(Activity.java:3248)
at android.support.v4.app.FragmentActivity.startActivityForResult(FragmentActivity.java:839)
at android.app.Activity.startActivity(Activity.java:3359)
at android.text.style.URLSpan.onClick(URLSpan.java:62)
at android.text.method.LinkMovementMethod.onTouchEvent(LinkMovementMethod.java:212)
at android.widget.TextView.onTouchEvent(TextView.java:8704)
at android.view.View.dispatchTouchEvent(View.java:5556)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1957)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1726)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1957)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1726)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1957)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1726)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1957)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1726)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1957)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1726)
at android.view.ViewGroup.dispatchTransformedTouchEvent(ViewGroup.java:1957)
at android.view.ViewGroup.dispatchTouchEvent(ViewGroup.java:1726)
at com.android.internal.policy.impl.PhoneWindow$DecorView.superDispatchTouchEvent(PhoneWindow.java:1940)
at com.android.internal.policy.impl.PhoneWindow.superDispatchTouchEvent(PhoneWindow.java:1390)
at android.app.Activity.dispatchTouchEvent(Activity.java:2414)
at com.android.internal.policy.impl.PhoneWindow$DecorView.dispatchTouchEvent(PhoneWindow.java:1888)
at android.view.View.dispatchPointerEvent(View.java:5736)
at android.view.ViewRootImpl.deliverPointerEvent(ViewRootImpl.java:3017)
at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2582)
at android.view.ViewRootImpl.processInputEvents(ViewRootImpl.java:887)
at android.view.ViewRootImpl.handleMessage(ViewRootImpl.java:2591)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:4697)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:787)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:554)
at dalvik.system.NativeStart.main(Native Method)

这不会导致我的代码。我假设当用户单击文本中的 URL 时会发生这种情况(应用程序中有带有 URL 的文本)。这是关于什么的? Android设备怎么可能没有浏览器?如何绕过这个或至少要捕获(我需要 URL 在文本中可点击)?

更新
实际上我发现这个异常发生在 TextView 中,它本来是一个空 ListView stub :

listView = (ListView) findViewById(R.id.listView);
// empty pass list with clickable url inside
final TextView listEmptyView = (TextView) findViewById(R.id.txtNoPasses);
listEmptyView.setMovementMethod(LinkMovementMethod.getInstance());
listView.setEmptyView(listEmptyView);

所以我尝试了这个(根据 CommonsWare 的文章),但在这种情况下我的 URL 仍然完全不可点击:

    listView = (ListView) findViewById(R.id.listView);
// empty pass list with clickable url inside
final TextView listEmptyView = (TextView) findViewById(R.id.txtNoPasses);
fixTextView(listEmptyView);
listView.setEmptyView(listEmptyView);
}

private void fixTextView(TextView textView) {
final SpannableString current = new SpannableString(textView.getText());
final URLSpan[] spans = current.getSpans(0, current.length(), URLSpan.class);
int start, end;
for (URLSpan span : spans) {
start = current.getSpanStart(span);
end = current.getSpanEnd(span);
current.removeSpan(span);
current.setSpan(new DefensiveURLSpan(span.getURL()), start, end, 0);
}
}

private static class DefensiveURLSpan extends URLSpan {
public DefensiveURLSpan(String url) {
super(url);
}

@Override
public void onClick(View widget) {
try {
android.util.Log.d(getClass().getSimpleName(), "Got here!");
super.onClick(widget);
}
catch (ActivityNotFoundException e) {
// do something useful here
// android.text.SpannedString cannot be cast to android.text.SpannableString
}
}
}

和 TextView:

<TextView
android:id="@+id/txtNoPasses"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:visibility="gone"
android:gravity="center"
android:padding="15dp"
android:text="@string/no_passes"
android:textAppearance="?android:attr/textAppearanceMedium"/>

no_passes 字符串如下:

<string name="no_passes">Currently you have no cards to use.\n<a href="http://cardz.website.com">You could add some cards from our website</a></string>

最佳答案

我假设这是一个带有 android:autolink 的 TextView设置,或者以其他方式显示 HTML(例如,使用 Html.fromHtml())。

问题是这会创建 URLSpan嵌入 URI 的实例,并且此类“盲目地”使用提供的 URI 调用 startActivity()。只要 URI 与任何已注册的 Activity 不匹配,就会崩溃。对于“http”URLS,当设备没有浏览器应用程序时,或者(更有可能)使用 restricted profile 时,可能会发生这种情况。阻止对其的访问。

问题及其解决方案在this CommonsWare post 中有很好的解释。 .您可以将 URLSpan 实例替换为拦截 onClick() 的自定义派生类以避免异常。

另见 this answer对于相关问题。

关于android - 未找到具有有效 http ://prefix 的 Activity (浏览器),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26746339/

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