【发布时间】:2018-04-04 19:34:36
【问题描述】:
我有一个与 facebook 聊天选项集成的网站。我对我的网站进行了 webview,可以在我的 android 应用程序中看到该聊天按钮,但问题是 单击聊天按钮时它不会将我重定向到手机中安装的信使应用程序,而是将我重定向到一个页面上面写了1。
另一方面,在我的手机上(在手机视图模式下)以 chrome 打开我的网站时,聊天功能运行良好。
这是我的 MainActivity.java 类:
public class MainActivity extends AppCompatActivity {
private WebView webView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
webView = (WebView)findViewById(R.id.webView);
WebSettings webSettings = webView.getSettings();
webSettings.setJavaScriptEnabled(true);
webView.loadUrl("https://geekyvisuals.github.io/website/");
webView.setWebViewClient(new MyWebViewClient());
}
@Override
public void onBackPressed() {
if(webView.canGoBack())
webView.goBack();
else
super.onBackPressed();
}
private class MyWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (Uri.parse(url).getHost().equals("https://geekyvisuals.github.io/website")) {
// This is my web site, so do not override; let my WebView load the page
return false;
}
// Otherwise, the link is not for a page on my site, so launch another Activity that handles URLs
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
return true;
}
}
}
我应该怎么做才能直接从我的 android 应用打开 Messenger?
【问题讨论】:
-
你能修复它吗?
-
@KaranSethi 检查我的解决方案。
标签: android android-intent android-webview facebook-messenger