Android - 单击按钮更改通知的ContentText [英] Android - Changing notification's ContentText on a button click

查看:833
本文介绍了Android - 单击按钮更改通知的ContentText的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个通知,其中包含一个按钮,在通知 .setContentText()中有一条谚语从包含众多谚语的字符串数组中显示,我是什么试图做的是当我点击该通知按钮时,新的谚语被分配给 .setContestText()

I have a notification that contains a button, inside that notification .setContentText() there is a proverb shown from an array of strings containing numerous proverbs, what I'm trying to do is when I click that notification button a new proverb is assigned to .setContestText()

我试过在SO上寻找其他解决方案,但我没有类似的东西

I tried looking for other solutions on SO but I got nothing similar

当前结果:当我点击按钮时没有任何反应

Current result : When I click the button nothing happens

到目前为止,这是我的代码:

public void notif(){
    int icon = getRandomIc();
    String Prov = getRandomProverb();
    String newProverb = getRandomProverb();
    Intent reloadQ = new Intent(this, Splash.class);

    PendingIntent piReload = PendingIntent.getService(this, 0, reloadQ, 0);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this);
    Notification notification = mBuilder
            .setSmallIcon(icon)
            .setVibrate(new long[] { 1000, 1000 })
            .setLights(Color.BLUE, 700, 500)
            .setContentTitle("Notification title")
            .setStyle(new NotificationCompat.BigTextStyle().bigText(NorProv))
            .addAction(R.mipmap.ic_autorenew_black_24dp, "New quote", piReload)
            .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))            
            .setContentText(Prov)
            .build();

    NotificationManager nMN = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
    nMN.notify(NOTIFICATION_ID, notification);
}


推荐答案

你做不到,一旦发送通知你就无法改变它的内容
看看 ANDROID NOTIFICATIONS

You can't do that, once a notification is sent you cannot change it's content take a look at ANDROID NOTIFICATIONS

这篇关于Android - 单击按钮更改通知的ContentText的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆