android - 在其他 fragment 中打开 URL?

标签 android android-fragments android-webview

这是我的安卓代码:

public boolean shouldOverrideUrlLoading(WebView view, String url) {
                    Intent myIntent = new Intent();
                    startActivity(myIntent);
                    return true;
                }

我遇到了这个错误:

FATAL EXCEPTION: main android.content.ActivityNotFoundException: No Activity found to handle Intent { }

我想设置当人们在 WebView 中点击一个 url 时,它将在其他 fragment 中打开

如何设置?

最佳答案

您缺少想要开始的类(class)。 假设您要开始的 Activity 是您应该使用的导航器:

Intent myIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(myIntent);

如果,您想做的是在您自己的应用程序中启动一个将 url 作为额外的 Activity :

Intent myIntent = new Intent(getApplicationContext(), MyActivity.class);
myIntent.putExtra("theUrl", url);
startActivity(myIntent);

如果你想在另一个 fragment 中显示信息,(假设你已经在一个 fragment 中)你可以这样做:

try{
    MyWebviewFragment f = new MyWebViewFragment(url);
    Bundle extras = new Bundle();
    extras.putString("theUrl", url);
    f.setArguments(extras);
    getActivity().getSuportFragmentManager().beginTransaction().add(f).commit();
}catch(Exception e){
    e.printStackTrace();
}

希望对您有所帮助!

关于android - 在其他 fragment 中打开 URL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20446240/

相关文章:

Android Monitor 显示我的应用程序内存不断增加

android - 当 Fragment onActivityCreated 调用时

java - 在 web View 中删除特定域的所有 cookie

android - 加载数据后如何防止 ScrollView 滚动到 WebView ?

android - 如何从 URL 获取参数值

Android:如何创建 "Ongoing"通知?

android - 如果 View 永远不可见,我应该在 View 生命周期的哪个点取消订阅?

android - 类路径中的flutter build Runtime JAR 文件应该具有相同的版本。这些文件在类路径中找到

android - 显示/隐藏 DrawerLayout 取决于当前 fragment

android - 查看寻呼机上的进度对话框