繁体   English   中英

单击按钮更新通知

[英]Update Notification with a Button click

我只是Android的新手,在编程时遇到了关于Notification的问题。

我需要您的帮助来处理更新通知。 这样的上下文就像您在玩游戏并且收到有关另一游戏的通知(第二个游戏在后台运行)时一样。 然后,您将获得第二个游戏的新通知,该通知具有与先前通知相同的ID

这是我的声明:我使用NotificationManager类创建一个Notification。

private NotificationManager manager;
private int notiId = 6789; // Each notification will be managed by an ID
private int numMsg = 0;

这是功能clickToSend按钮:

public void clickToSend(View view) {

    NotificationCompat.Builder builder = new NotificationCompat.Builder(this);

    // Setting Notification Properties
    builder.setContentTitle("New Message");
    builder.setContentText("Notification Demo: Message has received");
    builder.setTicker("Message Alert");
    builder.setSmallIcon(R.drawable.ic_action_unread);
    builder.setNumber(++numMsg);

    Intent intent = new Intent(this, NotificationDetailActivity.class);

    TaskStackBuilder stack = TaskStackBuilder.create(this);
    stack.addNextIntent(intent);

    PendingIntent pendingIntent = stack.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT);
    builder.setContentIntent(pendingIntent);
    manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    manager.notify(notiId, builder.build());
}

我认为函数clickToUpdate代码将像clickToSend函数一样进行clickToSend

谢谢你的帮助!

我的语言不好。 对不起给您带来不便。

暂无
暂无

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

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