我正在尝试在单击通知时发送Intent.ACTION_SEND。这是我的做法:
public static void generateNotification(Context context, String title, String message)
{
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
Builder notificationBuilder = new Notification.Builder(context)
.setContentTitle(title)
.setContentText(message)
.setSmallIcon(R.drawable.ic_launcher)
.setWhen(System.currentTimeMillis());
Intent shareIntent = new Intent(Intent.ACTION_SEND);
String extraText = title + " has " + message;
shareIntent.putExtra(Intent.EXTRA_TEXT, extraText);
PendingIntent pendingShareIntent = PendingIntent.getActivity(context, 0, Intent.createChooser(shareIntent, "share..."),
PendingIntent.FLAG_UPDATE_CURRENT);
notificationBuilder.addAction(android.R.drawable.ic_menu_share, "share...", pendingShareIntent);
Notification bigTextNotification = new Notification.BigTextStyle(notificationBuilder)
.setBigContentTitle(title)
.bigText(message)
.build();
notificationManager.notify(tag, notificationId++, bigTextNotification);
}
我在通知栏里看到分享操作,但是当我点击它时,弹出一个对话框,上面写着:
没有应用程序可以执行此操作
但是,如果我通过startActivity()运行相同的意图,它就可以正常工作。
有人能帮我解决这个问题吗?