将Android通知分享到whatsapp /电子邮件/其他第三方应用程序

问题描述

我想让我的用户可以选择将我的应用程序生成通知文本共享给其他应用程序。

下面是我尝试过的代码,但是没有成功。当我单击通知上的共享按钮时,它的确打开了“共享方式”屏幕,但是从“ Intent.EXTRA_TEXT”显示的共享文本没有任何意义。如果我对“ sShare”是什么进行了日志检查,那么它会向我显示正确的字符串。

请尽一切可能提供帮助。

Intent sendIntent = new Intent();
            sendIntent.setAction(Intent.ACTION_SEND);
            sendIntent.putExtra(Intent.EXTRA_TEXT,sShare);
            sendIntent.setType("text/plain");

            PendingIntent sendPendingIntent = PendingIntent.getActivity(context,sendIntent,0);

mBuilder.setSmallIcon(R.drawable.ic_launcher);
            mBuilder.setContentTitle("Title");
            mBuilder.setContentText(sOther);
            mBuilder.setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
            mBuilder.addAction(R.drawable.share,"Share",sendPendingIntent);
mBuilder.setContentIntent(pendingIntent);

解决方法

PendingIntent sendPendingIntent = PendingIntent.getActivity(context,sendIntent,PendingIntent.FLAG_UPDATE_CURRENT);