如何使用您自己的Android应用中的意图在Facebook应用中打开特定的相册或照片

时间:2016-03-27 19:03:28

标签: android android-intent

如何使用您自己的Android应用程序中的意图在Facebook应用中打开相册或照片?

我一直在寻找这个问题的具体答案。大多数问题都是关于如何通过意图打开Facebook页面。

我看到了这个(关于iAppStreet的Sunny a Sr.软件工程师),但它没有用。

public Intent getOpenFacebookIntent(String pId) {

try {
    activity.getPackageManager().getPackageInfo("com.facebook.katana", 0);
    return new Intent(Intent.ACTION_VIEW, Uri.parse("facebook:/photos?album=0&photo=" + pId+"&user="+ownerId));
} catch (Exception e) {
    return new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.facebook.com/"));
}
}

startActivity(getOpenFacebookIntent(pid));

感谢。

3 个答案:

答案 0 :(得分:0)

其实我提出这个问题是为了帮助那些像我这样有同样问题的人。截至今天(2016年3月28日)我刚刚发现了如何使用意图打开相册但我无法在facebook应用中使用意图打开照片。我是android编程的初学者,所以请耐心等待。

我用一个按钮来实现这个。这是代码:

Button buttonOpenALbum = (Button) findViewById(R.id.button);
buttonOpenALbum.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            //It is a album from a facebook page @ www.facebook.com/thinkingarmy
            String albumID = "575146485903630";
            String userID = "575145312570414";

            String url = "facebook:/photos?album="+albumID+"&user="+userID;
            Uri uri = Uri.parse(url);
            Intent intent = new Intent(Intent.ACTION_VIEW, uri);
            startActivity(intent);
        }
    });

如果您想获取facebook相册的albumID和userID,请尝试在google上搜索或尝试使用此相册,如果有帮助,https://www.youtube.com/watch?v=sMEmlpmCHLc

修改代码以打开特定照片并未产生预期结果。即使我加入了photoID,你仍然会在专辑中出现。这是代码:

Button buttonOpenPhoto = (Button) findViewById(R.id.button);
buttonOpenPhoto.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            //It is a album from a facebook page @ www.facebook.com/thinkingarmy
            String albumID = "575146485903630";
            String userID = "575145312570414";
            String photoID = "803154029769540";

            String url = "facebook:/photos?album="+albumID+"&photo="+photoID+"&user="+userID;
            Uri uri = Uri.parse(url);
            Intent intent = new Intent(Intent.ACTION_VIEW, uri);
            startActivity(intent);
        }
    });

我无法确定原因。我试过看,但有人说facebook的网址没有记录。如果可以,我认为你不能打开一张特定的照片,因为在观察时,facebook会全屏打开一张照片,这意味着它与处理传入意图的主要活动不同。 Facebook应用程序的主要活动仅处理打开特定相册的意图。

我希望我能在第一篇文章中帮助其他“新的安卓程序员”。

注意:我只是使用google和stackoverflow学习编码。这是我的回馈方式。感谢。

答案 1 :(得分:0)

使用以下网址启动视图意图

https://www.facebook.com/photo.php?fbid= {photo_id}

          Intent browserIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
            ctx.startActivity(browserIntent);

如果安装了该应用,则会提示用户在应用中打开,否则将使用浏览器

答案 2 :(得分:0)

Open Facebook Page in Facebook App (if installed) on Android

上的一些有用信息

特别是,新版本的facebook应用

Uri.parse("fb://facewebmodal/f?href=" + FACEBOOKURL

我发现这是实现所需要的最简单的方法。

另请注意,要获取网址,您可以访问Facebook相册(在Facebook桌面上),点击"编辑"旁边的三个点。和#34;标记"并选择"获取链接"。我发现这比简单地从浏览器复制URL更可靠。