【问题标题】:Android open specific facebook app profile page at other android app redirect to newsfeed page when facebook app is closed当 Facebook 应用程序关闭时,Android 在其他 android 应用程序中打开特定的 facebook 应用程序配置文件页面重定向到新闻源页面
【发布时间】:2014-06-24 05:58:01
【问题描述】:

我正在尝试使用特定用户 ID 在我的 android 应用中打开某些 Facebook 个人资料页面。 如果已安装,我的代码将打开 facebook 应用程序,否则打开 webbrowser。 它工作正常,除非安装了 facebook 应用程序并关闭它。 在这种情况下,它只会打开新闻源页面而不是个人资料页面。当 facebook 应用程序在后台打开时,它会成功重定向到所需的个人资料页面。我该如何解决这个问题?还有一个官方的 facebook 文档描述了访问 facebook 应用程序 URI 的方式吗?

    try{
        this.getPackageManager()
        .getPackageInfo("com.facebook.katana", 0); //Checks if FB is even installed.

        final String facebookScheme = String.format("fb://profile/%s", user2FbID);
        final Intent facebookIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(facebookScheme)); 

        facebookIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_NO_HISTORY
                | Intent.FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET);
        startActivity(facebookIntent);
    }catch (Exception e) {
        String facebookScheme = "https://m.facebook.com/" + user2FbID;
        Intent facebookIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(facebookScheme)); 
        startActivity(facebookIntent);          
    } 

【问题讨论】:

    标签: android facebook facebook-graph-api


    【解决方案1】:

    试试这个,对我有用

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

    【讨论】:

    • 如果 Facebook 应用程序没有在后台运行,就会发生这种情况。我也面临同样的问题,并通过启动两个活动来解决这个问题,当第一个活动开始时,它启用 Facebook 应用程序,并在 2 秒后完成相同的过程,然后它打开给定 Facebook 页面/个人资料
    • 谢谢辛格!有用 !看起来你两次调用意图?你能给我一些描述你在你的代码中尝试什么来解决我的问题吗?谢谢你拯救了我的一天..
    • 在我的应用程序中,我试图打开一个 Facebook 页面和 Facebook 群组页面,通过应用它,我解决了显示“新闻提要”页面的问题。 @user3769783
    【解决方案2】:

    这也发生在我身上。更新了 Facebook 应用程序,现在已经解决,似乎与 Facebook 有关。它现在工作正常。

    这是我正在使用的代码:

    public static Intent getOpenFacebookIntent(Context context) {
            try{
               // open in Facebook app
               context.getPackageManager().getPackageInfo("com.facebook.katana", 0);
               return new Intent(Intent.ACTION_VIEW, Uri.parse("fb://page/<profile_id>"));
            } catch (Exception e) {
               // open in browser
              return new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.facebook.com/<profile_id>"));
            }
        }
    

    【讨论】:

    • 如果我想在有 url / id 的特定帖子上打开 Facebook 应用程序怎么办?
    猜你喜欢
    • 2011-06-16
    • 1970-01-01
    • 1970-01-01
    • 2014-08-22
    • 2013-02-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多