且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Android Share - Facebook SDK - ShareActionProvider

更新时间:2023-01-27 11:07:57

答案你不能通过使用意图来共享一个字符串到用户自己的墙。您需要SDK才能做到这一点。原因是因为Facebook不允许预先填写用户状态更新,如平台中所示政策IV.2 。但是,如果您使用SDK,我们提供了一个Feed对话框,提示用户共享状态,并允许部分状态更新由开发商。然而,它并未纳入Android的本机选择器。



跟踪此问题的外部错误报告是 here


I am trying to implement sharing a simple string inside my application. Obviously everything other than Facebook works. As far as I know, now I have to use their Facebook SDK to post statuses on a wall.

However, if I do implement it using their SDK, is there a way to have it incorporated into the chooser (default or ShareActionProvider) and somehow override it and insert the Facebook SDK's implementation?

Or do I have to create a dedicated button?

//EDIT

package com.example.shareactionproviderdemo;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

public class MainActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        Intent sharingIntent = new Intent(Intent.ACTION_SEND);
        sharingIntent.setType("text/plain");
        sharingIntent.putExtra(android.content.Intent.EXTRA_TEXT, "Test message");
        startActivity(Intent.createChooser(sharingIntent, "Share using"));
    }

}

The answer is you cannot share a string to the user's own wall by using intents. You need the SDK in order to do that. The reason why is because Facebook does not allow the prefilling of the user's status update as seen in Platform Policy IV.2.

However, if you use the SDK, we have provided a feed dialog that prompts the user to share a status and it allows parts of the status update to be prefilled by the developer. It is not incorporated into the Android's native chooser, however.

The external bug report that tracked this issue is here.