I read the documentation of the facebook sdk. But i am not able to make the Send Button work. Below is the work i have done.
public class Main2Activity extends AppCompatActivity {
private LoginButton loginButton;
private CallbackManager callbackManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
FacebookSdk.sdkInitialize(getApplicationContext());
callbackManager = CallbackManager.Factory.create();
setContentView(R.layout.activity_main2);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
Bitmap image = BitmapFactory.decodeResource(this.getResources(),
R.drawable.cos2ms);
SharePhoto photo = new SharePhoto.Builder()
.setBitmap(image)
.build();
ShareContent shareContent = new ShareMediaContent.Builder()
.addMedium(photo)
.build();
System.out.println("Test me!!!!");
SendButton sendButton = (SendButton)findViewById(R.id.messenger_send_button);
sendButton.setShareContent(shareContent);
sendButton.registerCallback(callbackManager, new FacebookCallback<Sharer.Result>() {
@Override
public void onSuccess(Sharer.Result result) {
}
@Override
public void onCancel() {
}
@Override
public void onError(FacebookException error) {
}
});
}
@Override
protected void onActivityResult(final int requestCode, final int resultCode, final Intent data) {
super.onActivityResult(requestCode, resultCode, data);
callbackManager.onActivityResult(requestCode, resultCode, data);
}
}
Please i want to know how to make it work as it do nothing when i press send button it do not open the messenger to send message?
You are on the right way, just make sure to add this provider to your AndroidManifest.xml
<provider android:authorities="com.facebook.app.FacebookContentProvider{APP_ID}"
android:name="com.facebook.FacebookContentProvider"
android:exported="true"/>
also make sure to have messanger app on your device, you can get more information here
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.