如何创建从我的应用到 Facebook 页面的意向?



这似乎是一个已成定局的问题,我想我已经可以很容易地找到答案了, 但我找到的答案很老,它们不起作用。 如何创建从我的应用到 Facebook 页面的意向? 我希望如果有打开Facebook应用程序,否则浏览器

到目前为止,最好的解决方案是Rishav Singla的解决方案:

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>"));
}
}

用:

startActivity(getOpenFacebookIntent(getApplicationContext()));

。In attesa di altre soluzioni

您可以使用以下代码重定向到特定用户 您的Facebook应用程序将在后台运行,因此为了打开它,您必须运行此代码两次(这是一个奇怪的行为:((

try
{
Intent followIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("fb://profile/<your profile_id>"));
startActivity(followIntent);
final Handler handler = new Handler();
handler.postDelayed(new Runnable()
{
@Override
public void run() {
Intent followIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("fb://profile/<your profile_id>"));
startActivity(followIntent);
}
}, 1000 * 2);
}
catch (Exception e)
{
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.facebook.com/<user_name>")));
String errorMessage = (e.getMessage()==null)?"Message is empty":e.getMessage();
Log.e("Unlock_ScreenActivity:FacebookAppNotFound" ,errorMessage);
}

希望这对你有帮助 祝您编码愉快!

使用 URL 到 facebook 在浏览器中打开它

String url = "https://www.facebook.com/ZambianWatchdog/";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(url));
startActivity(i);
public Intent getIntent() {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("fb://page/{{page}}"));
if (intent.resolveActivity(getPackageManager()) != null) {
return intent;
}
return null;
}

最新更新