Facebook 官方 Android SDK - 如何打开页面?

问题描述

我想打开 Facebook 应用并在用户按下我的应用中的按钮时直接转到 Facebook 页面。

如何使用官方 Facebook SDK 执行此操作?

到目前为止,我看到的所有解决方案都相当笨拙,检查是否使用包管理器或其他东西安装了 FB 应用程序。鉴于 Package Visibility 的先例,这在未来可能会成为一个问题。

Another solution 依赖于来自反编译的 Facebook APK 的非官方 URI 列表,该列表可能随时中断。

解决方法

我试过这个代码。打开facebook应用程序是工作 https://stackoverflow.com/a/52480045/14215175

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

如果你想针对特定的个人资料/群组/页面,你需要更改代码 fb://profile --> "fb://group" / "fb://page"

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...