简体   繁体   English

将 android 通知分享到 whatsapp/电子邮件/其他 3rd 方应用程序

[英]Share an android notification to whatsapp/email/other 3rd party apps

I would like to give my users the option of sharing the text of a notification that my app produces to other apps.我想让我的用户选择将我的应用生成的通知文本分享给其他应用。

Below is the code that I have attempted, but does not result in any success.下面是我尝试过的代码,但没有成功。 It does open the "share via" screen when I click the share button on the notification, but the text that is shared that appears from "Intent.EXTRA_TEXT" makes no sense.当我单击通知上的共享按钮时,它确实打开了“共享方式”屏幕,但是从“Intent.EXTRA_TEXT”中出现的共享文本没有任何意义。 If I do a Log check on what "sShare" is, then it shows me the correct string.如果我对“sShare”是什么进行日志检查,那么它会显示正确的字符串。

Please assist in anyway that you can.请尽可能提供帮助。

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

            PendingIntent sendPendingIntent = PendingIntent.getActivity(context, 0, 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, 0, sendIntent, PendingIntent.FLAG_UPDATE_CURRENT);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM