【问题标题】:Share an android notification to whatsapp/email/other 3rd party apps将 android 通知分享到 whatsapp/电子邮件/其他 3rd 方应用程序
【发布时间】:2021-01-11 12:43:00
【问题描述】:

我想让我的用户选择将我的应用生成的通知文本分享给其他应用。

以下是我尝试过的代码,但没有成功。当我单击通知上的共享按钮时,它确实打开了“共享方式”屏幕,但是从“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, 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);

【问题讨论】:

    标签: java android-studio android-intent android-notifications android-pendingintent


    【解决方案1】:
    PendingIntent sendPendingIntent = PendingIntent.getActivity(context, 0, sendIntent, PendingIntent.FLAG_UPDATE_CURRENT);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-09-26
      • 1970-01-01
      • 2021-11-06
      • 1970-01-01
      相关资源
      最近更新 更多