【问题标题】:how to change notification to another when clicked- android点击时如何将通知更改为另一个 - android
【发布时间】:2023-03-30 22:13:01
【问题描述】:

我的应用程序用于显示类似于提醒的通知。到目前为止,我可以在通知框上显示我的文本。但是我希望它在用户点击它时切换到另一个通知。

这是我的代码:`else{

  Text = "go to shopping mall";
  Text2 = "meet emma";
 final PendingIntent pending = PendingIntent.getActivity(arg0.getContext(), 0, new         Intent(arg0.getContext(),MainActivity.class), 0);
new AsyncTask<Void, Void, Void>(){

    public Void doInBackground(Void... args){


        Bitmap bmp = BimapFactory.decodeResource(arg0.getContext().getResources(), R.drawable.image);

        notification = new NotificationCompat.Builder(arg0.getContext())
         .setContentTitle("I want to...")
         .setContentText(Text)
         .setContentIntent(pending)
         .setSmallIcon(R.drawable.ic_launcher)
         .setStyle(new NotificationCompat.BigPictureStyle()
             .bigPicture(bmp))
         .build();
        notificationmanager = (NotificationManager)arg0.getContext().getSystemService(Context.NOTIFICATION_SERVICE);

        notificationmanager.notify(notificationId, notification);
        notificationId++;
        return null;
    }
}.execute();

`

这完全符合我的要求。但我想在用户点击通知时显示 *Text2。*

*注意:*现在,当我单击此通知时,它会将我带到应用程序本身,这是预期的。但这现在应该只更改文本,而不会将我带到其他地方。

如果可能的话,请考虑重新编辑我的代码来解释。

【问题讨论】:

    标签: android notifications push-notification android-notifications notificationmanager


    【解决方案1】:

    您应该能够通过将BroadcastReceiver 实现为点击侦听器来实现此目的,将您的操作PendingIntent 更改为指向它,并将updating 您的Notification 使用来自BroadcastReceiver 回调的新文本.

    【讨论】:

    • 对 Android 应用程序开发非常陌生。你能告诉我从哪里开始学习broadcastReceiver吗?和改变你的行动 PendingIntent 指向它你的意思是我应该调用广播接收器作为未决的意图(我的意思是午餐的第二个意图)??
    • @androCoder-BD:您可以在reference docs 中了解BroadcastReceiver。是的,您应该使用getBroadcast() 方法来创建PendingIntent 并提供Intent 来启动您的BroadcastReceiver 而不是Activity。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-20
    • 1970-01-01
    • 2023-03-13
    • 2011-07-07
    相关资源
    最近更新 更多