从通知中发送一个ACTION_SEND意图

5

我正在尝试在单击通知时发送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()运行相同的意图,它就可以正常工作。

有人能帮我解决这个问题吗?

1个回答

2

您在Intent上未指定MIME类型,可以使用setType()进行设置。尝试添加并查看是否有帮助。


我知道我有点抢了话头,但我正在寻找一款应用程序或某种实用工具,可以让您从下载通知中共享已下载的图像。Imgur应用程序中的共享选项仅共享图像的链接,但我想将该图像嵌入我的Hangouts聊天中。目前,我必须下载图像,打开文件浏览器,在其他图像列表中查找奇怪命名的文件,从那里选择共享,选择Hangouts,然后点击发送。这个问题似乎是谷歌上唯一与我想要的东西密切相关的事情。我在谷歌上问错了吗? - Kristopher

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接