Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/185.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 单击共享按钮后如何处理WebView中的外部链接?_Android_Webview_Android Webview - Fatal编程技术网

Android 单击共享按钮后如何处理WebView中的外部链接?

Android 单击共享按钮后如何处理WebView中的外部链接?,android,webview,android-webview,Android,Webview,Android Webview,我有一个加载webview的屏幕,现在用于处理打开外部应用程序和其他链接,我使用了url.startsWith()和url.contains()。这些对于webview来说很好。还有一个home按钮,它也使用webview的相同功能来处理外部链接 我的问题 顶部工具栏上还有一个共享按钮,问题是当单击该按钮时,链接不再由上述方法处理,即使我在共享按钮中使用了它们 下面是处理webview内部链接的代码,它适用于onCreate和homeIcon方法,但不适用于shareText() 我该怎么处理?

我有一个加载webview的屏幕,现在用于处理打开外部应用程序和其他链接,我使用了url.startsWith()和url.contains()。这些对于webview来说很好。还有一个home按钮,它也使用webview的相同功能来处理外部链接

我的问题 顶部工具栏上还有一个共享按钮,问题是当单击该按钮时,链接不再由上述方法处理,即使我在共享按钮中使用了它们

下面是处理webview内部链接的代码,它适用于onCreate和homeIcon方法,但不适用于shareText()


我该怎么处理?或者工具栏中的按钮无法处理此问题?

我认为当您单击工具栏时,WebView只会打开链接,第一次不会调用shouldOverrideURL加载,因此您需要在单击工具栏按钮时在WebView上加载URL时调用此URL过滤的逻辑。

您可能想尝试一下这个

Intent intent = new Intent(android.content.Intent.ACTION_SEND);
intent.setType("text/plain");
String shareBodyText = "Check out this awesome store at https://showroom.dotpe.in/stylenstyle882. Or download the app now.";
intent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject/Title");
intent.putExtra(android.content.Intent.EXTRA_TEXT, shareBodyText);
// Here are 1 added lines to handle URLs.
intent.putExtra(Intent.EXTRA_STREAM, Uri.parse("http://" + bkpUrl));
// Here are 2 added lines to share a file.
// intent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + filePath));
// intent.setDataAndType(Uri.parse("content://" + getPackageName() + ".file" + filePath), "text/plain");
startActivity(Intent.createChooser(intent, "Sharing Option"));

如果你不替换URL会怎么样?你的意思是如果我不处理外部链接的打开?它只是为每个点击的链接显示错误未知URI模式查看
Chrome
,它发送的是:
intent.putExtra(android.content.intent.EXTRA)文本,URI.parse(“https://stackoverflow.com"));是,我处理了意图,请参见上面的代码。问题是我尝试过的所有东西都在home按钮和webview屏幕中工作,但只要我按下顶部工具栏上的按钮,webview就会刷新,然后没有链接被处理。当你点击share按钮时,你可能需要检查正在运行的js脚本函数,然后尝试覆盖Android代码中的脚本乐趣在WebView的第一个屏幕上调用逻辑,当我用同样的方法单击home按钮调用WebView时
Intent intent = new Intent(android.content.Intent.ACTION_SEND);
intent.setType("text/plain");
String shareBodyText = "Check out this awesome store at https://showroom.dotpe.in/stylenstyle882. Or download the app now.";
intent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Subject/Title");
intent.putExtra(android.content.Intent.EXTRA_TEXT, shareBodyText);
// Here are 1 added lines to handle URLs.
intent.putExtra(Intent.EXTRA_STREAM, Uri.parse("http://" + bkpUrl));
// Here are 2 added lines to share a file.
// intent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + filePath));
// intent.setDataAndType(Uri.parse("content://" + getPackageName() + ".file" + filePath), "text/plain");
startActivity(Intent.createChooser(intent, "Sharing Option"));