我已经实现了一个webview,我只是在加载一个facebook页面。点击链接(分享或类似)时,它在webview中打开。我想在facebook应用程序中打开链接(如果已安装)。
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View layoutProgressWebview = inflater.inflate(R.layout.fragment_webview,container,false);
progressDialog = new ProgressDialog(getActivity().getApplicationContext());
progressDialog.setMessage("Loading...");
webView = (WebView) layoutProgressWebview.findViewById(R.id.webView);
webView.setWebChromeClient(new ArticleWebChromeClient());
webView.setWebViewClient(new WebViewClient(){
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
return false;
}
});
webView.getSettings().setUserAgentString(userAgent);
webView.getSettings().setJavaScriptEnabled(true);
Bundle args = getArguments();
String resourceUrl = args.getString(ARG_URL);
webView.loadUrl(resourceUrl);
return layoutProgressWebview;
}
private class ArticleWebChromeClient extends WebChromeClient {
public void onProgressChanged(WebView view, int progress) {
if (progress == 100) {
if (progressDialog != null)
progressDialog.dismiss();
}
}
}
答案 0 :(得分:0)
这对我有用:
转到https://graph.facebook.com/(例如https://graph.facebook.com/fsintents) 复制你的身份证 使用此方法:
public static Intent getOpenFacebookIntent(Context context)
{
try
{
context.getPackageManager().getPackageInfo("com.facebook.katana",0);
return new Intent(Intent.ACTION_VIEW,Uri.parse("fb://page/<id_here>"));
}catch (Exception e)
{
return new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.facebook.com/<user_name_here>"));
}
}
如果用户已安装Facebook应用,则会打开该应用。否则,它将在浏览器中打开Facebook。