从通知发送ACTION_SEND意图

时间:2022-11-15 12:13:07

I am trying to send and Intent.ACTION_SEND on click of a notification. This is what I have done

我试图点击通知发送和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);
}

I get the share action on the notification but when i click it i a dialog box that says

我在通知上获得了共享操作,但是当我点击它时,我会出现一个对话框

No Apps can perform this action

没有应用可以执行此操作

When I run the same intent via startActivity() it works fine.

当我通过startActivity()运行相同的意图时它工作正常。

Can somebody help me out here?

有人可以帮帮我吗?

1 个解决方案

#1


2  

You failed to specify a MIME type on the Intent, using setType(). Try adding that and see if it helps.

您未能使用setType()在Intent上指定MIME类型。尝试添加它,看看它是否有帮助。

#1


2  

You failed to specify a MIME type on the Intent, using setType(). Try adding that and see if it helps.

您未能使用setType()在Intent上指定MIME类型。尝试添加它,看看它是否有帮助。