2011-04-17 114 views
1

在手机安卓画廊没有对图像分享到Facebook和张贴在墙上。我想的完全相似的方式发布消息或图像到墙上的一个选项从我的app.How可以做到这一点?在Android的Facebook墙上发布?

我的理解:我认为,它使用Facebook应用程序已经出现在我的phone.If是这样的话,那么我就可以启动特定的活动或抛出相应的从我的app.If该活动的目的是这样的话有人可以让我知道什么是相应的意图,我应该抛出。 什么是我应该传递的意图和什么关键字我应该传递这些参数?

纠正我,如果我的理解是错误的,让我知道如何做到这一点。

P.S:根据这个美好的职位Android/Java -- Post simple text to Facebook wall?我一直在使用Facebook SDK,并将其works.But对话框别看good.That。这就是为什么我要寻找一个不同的选项。

谢谢

+0

你能否详细说明 '对话框并不看好'?这样,任何新的解决方案都可以在你看到它们时克服这些限制。 – 2011-04-17 10:56:59

+0

我相信它显示在网络视图上,非常拥挤,我在画廊中看到的那个看起来更好。 – rogerstone 2011-04-17 12:43:46

回答

2

我认为你正在寻找ACTION_SEND意图。

请参阅this post

编辑:和its doc

第二个编辑:请注意,如果男人没有Facebook的应用程序,他将无法分享。如果您使用the Facebook API,那么他将能够分享到Facebook,但只有Facebook。

+0

是的,这是我正在寻找,但似乎现在没有正确处理Facebook的ACTION_SEND意图。http://stackoverflow.com/questions/3515198/share-text-on-facebook-from-android-app-via-action-send – rogerstone 2011-04-17 12:37:47

+0

ACTION_SEND处理不当,但它仍然适用于基本使用。破坏的是它不处理ACTION_SEND中的所有字段,也不使用Facebook应用程序来处理该操作。相反,它打开一个网页m.facebook.com来处理墙贴(至少它验证)。 – 2011-04-18 20:41:50

1

很长一段时间的研究。最后我找到了解决办法..

它对我很好。

private void postToFacebookViaIntent() { 
File mFile = new File(Environment.getExternalStorageDirectory()+ "/images.jpg"); 
    Intent shareIntent = findFacebookClient(); 

    if (shareIntent != null && mFile!= null) { 

     shareIntent.putExtra(Intent.EXTRA_STREAM,Uri.fromFile(mFile)); 
     startActivity(Intent.createChooser(shareIntent, "Share")); 
    } else { 
     Toast.makeText(SharingActivity.this, "Facebook App is not installed", Toast.LENGTH_SHORT).show(); 
    } 

}

private Intent findFacebookClient() { 
    final String twitterApps = "facebook"; 
    Intent facebookIntent = new Intent(); 
    facebookIntent.setAction(Intent.ACTION_SEND); 
    facebookIntent.setType("image/jpeg"); 
    final PackageManager packageManager = getPackageManager(); 
    List<ResolveInfo> list = packageManager.queryIntentActivities(
      facebookIntent, 0); 

    for (ResolveInfo resolveInfo : list) { 
     String p = resolveInfo.activityInfo.packageName; 
     if (p != null && p.contains(twitterApps)) { 
      facebookIntent.setPackage(p); 
      return facebookIntent; 
     } 
    } 
    return null; 
}