Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/204.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/27.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
更改android通知消息而不重新停止和启动服务_Android - Fatal编程技术网

更改android通知消息而不重新停止和启动服务

更改android通知消息而不重新停止和启动服务,android,Android,这是我在android上启动服务时发出通知的方法: private void showNotification() { Notification notification = new Notification(R.drawable.call, "Some text", System.currentTimeMillis()); Intent intent = new Intent(this, MainActivity.class); intent.

这是我在android上启动
服务时发出
通知的方法:

private void showNotification() {
        Notification notification = new Notification(R.drawable.call, "Some text", System.currentTimeMillis());
        Intent intent = new Intent(this, MainActivity.class);

        intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
        PendingIntent pi = PendingIntent.getActivity(this, 0, intent, 0);
        notification.setLatestEventInfo(this, getString(R.string.notification_label), getString(R.string.notification_text_short), pi);
        notification.flags |= Notification.FLAG_NO_CLEAR;
        startForeground(7331, notification);
    }
以后是否可以更改文本。例如,现在是
“一些文本”
,稍后我想不停地更改它,然后再次启动服务


这可能吗?

您正在使用通知ID 7331显示通知以及启动服务。只要您发送具有相同ID的新通知,它就会替换旧通知

使用此选项更新通知

String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager) context
            .getSystemService(ns);
long when = System.currentTimeMillis();

Notification notification = new Notification("your icon", "your ticker text", when);
/*<set your intents here>*/
mNotificationManager.notify(7331, notification);
String ns=Context.NOTIFICATION\u服务;
NotificationManager mNotificationManager=(NotificationManager)上下文
.getSystemService(ns);
长时间=System.currentTimeMillis();
通知通知=新通知(“您的图标”、“您的股票代码文本”,何时);
/**/
通知经理通知(7331,通知);