我正在尝试将图片和文字分享到手机上的不同应用。我创建了一个IntentChooser
来选择要与之分享内容的应用,并创建一个Broadcast Receiver
来获取用户点击内容的回调。现在问题在于Facebook。我想分享一个标签,但它不会通过Intent.EXTRA_TEXT
。我也整合了Facebook SDK
。我添加了Broadcast Receiver
,以便我可以显示Facebook的ShareDialog
来分享图片和Hashtag。但是当用户从createChooser
选择Facebook时,它会打开应用程序,然后回拨Broadcast
。
如何将HashTag
添加到我通过Facebook分享的帖子中?
public void doSocialShare(String title, String text, Bitmap resource){
Intent sendIntent = new Intent(android.content.Intent.ACTION_SEND);
sendIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
sendIntent.putExtra(Intent.EXTRA_TEXT, text);
sendIntent.putExtra(Intent.EXTRA_STREAM, getBitmapFromDrawable(resource));
sendIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
sendIntent.setType("image/*");
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP_MR1) {
Log.d("INFORMATION", "The current android version allow us to know what app is chosen by the user.");
Intent receiverIntent = new Intent(this,ShareBroadcastReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, receiverIntent, PendingIntent.FLAG_CANCEL_CURRENT);
sendIntent = Intent.createChooser(sendIntent,"Share via...", pendingIntent.getIntentSender());
}
startActivity(sendIntent);
}
这是我的广播接收器:
public class ShareBroadcastReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// TODO: This method is called when the BroadcastReceiver is receiving
// an Intent broadcast.
for (String key : intent.getExtras().keySet()) {
Log.d(getClass().getSimpleName(), " " + intent.getExtras().get(key));
}
}
}