【FacebookSDK学习笔记】Facebook消息分享

本文介绍了如何在Android应用中集成Facebook SDK实现消息分享功能,首先确保手机已安装Facebook Messenger,然后通过添加Button并配置相应代码来触发分享操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.手机上要安装了Facebook Message才能使用这个功能

Google Play网址:https://play.google.com/store/apps/details?id=com.facebook.orca


2.直接添加一个button

 <Button
    android:id="@+id/messageButton"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textStyle="bold"
    android:gravity="center"
    android:layout_marginTop="30dp"
    android:visibility="invisible"
    android:text="message"
   />

3.添加监听事件即可

FacebookDialog.MessageDialogBuilder builder = new FacebookDialog.MessageDialogBuilder(getActivity())
		    .setLink("https://developers.facebook.com/docs/android/share/")
		    .setName("Message Dialog Tutorial")
		    .setCaption("Build great social apps that engage your friends.")
		    .setPicture("http://i.imgur.com/g3Qc1HN.png")
		    .setDescription("Allow your users to message links from your app using the Android SDK.")
		    .setFragment(this);

		// If the Facebook app is installed and we can present the share dialog
		if (builder.canPresent()) {
		  // Enable button or other UI to initiate launch of the Message Dialog
			FacebookDialog dialog = builder.build();
			dialog.present();
		}  else {
		  // Disable button or other UI for Message Dialog 
			Log.e("===Error===","Error!No Message!");//出现此log说明未安装Messager
		}

如下图:


效果图::


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值