相关疑难解决方法(0)

安静地更新正在进行的通知

我有一个无线连接到其他设备的服务.启用该服务后,我会持续发出通知,说明它已启用.

启用该服务后,用户将连接到另一台设备.此时,我想更新我正在进行的通知,以说明已连接的设备的名称.通过startForeground(ONGOING_NOTIFICATION, notification)使用更新的信息再次呼叫,这很容易做到; 但每次调用时,它会在条形图上闪烁通知.我真正想要的是通知在后台静默更新而不会在通知栏上闪烁,因此用户在打开通知区域之前不会知道区别.

有没有在没有调用的情况下更新通知startForeground()

此行为仅发生在Honeycomb中.姜饼设备(我假设Froyo等)表现出理想的方式.

notifications android android-3.0-honeycomb

40
推荐指数
3
解决办法
5万
查看次数

如何在更改按钮时避免闪烁通知更新

我有一个通知,支持播放,前进和后退.

private static Notification createNotification(String interpret, String title, boolean paused) {
//  if (builder == null)
       builder = new NotificationCompat.Builder(context);

    builder.setPriority(Notification.PRIORITY_MAX);
    builder.setAutoCancel(false);
    builder.setContentTitle(title);
    builder.setContentText(interpret);
    builder.setOngoing(true);
    builder.setOnlyAlertOnce(true);
    builder.setSmallIcon(R.drawable.ic_launcher);
    builder.setContentIntent(PendingIntent.getActivity(context, 9, new Intent(context, ApplicationActivity.class), Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT));
    builder.addAction(R.drawable.av_previous, "", PendingIntent.getBroadcast(context.getApplicationContext(), 0, new Intent(NotificationPlayerControlReceiver.MUSIC_PLAYER_INTENT).putExtra("resultcode", NotificationPlayerControlReceiver.PREVIOUS), PendingIntent.FLAG_CANCEL_CURRENT));

    if (paused)
        builder.addAction(R.drawable.av_play, "", PendingIntent.getBroadcast(context.getApplicationContext(), 2, new Intent(NotificationPlayerControlReceiver.MUSIC_PLAYER_INTENT).putExtra("resultcode", NotificationPlayerControlReceiver.PLAY), PendingIntent.FLAG_CANCEL_CURRENT));
    else
        builder.addAction(R.drawable.av_pause, "", PendingIntent.getBroadcast(context.getApplicationContext(), 3, new Intent(NotificationPlayerControlReceiver.MUSIC_PLAYER_INTENT).putExtra("resultcode", NotificationPlayerControlReceiver.PAUSE), PendingIntent.FLAG_CANCEL_CURRENT));

    builder.addAction(R.drawable.av_next, "", PendingIntent.getBroadcast(context.getApplicationContext(), 1, new Intent(NotificationPlayerControlReceiver.MUSIC_PLAYER_INTENT).putExtra("resultcode", NotificationPlayerControlReceiver.NEXT), PendingIntent.FLAG_CANCEL_CURRENT));

    Notification notification = builder.build();

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
        notification.tickerView = null;

    return …
Run Code Online (Sandbox Code Playgroud)

notifications android android-notifications

18
推荐指数
3
解决办法
5319
查看次数

如何正确更新api 11的通知?

  • 之前Notification.Builder进入了存在更新的方式通知了已被通知栏是调用setLatestEventInfo(),然后发送通知回通过NotificationManager.notify()与第一相匹配的ID调用notify()你做电话.

  • 现在setLatestEventInfo()不推荐使用消息:Use Notification.Builder而是.但我找不到任何有关如何正确更新通知的文档Notification.Builder.

  • 您是否只是想在Notification每次需要更新通知时重新创建新实例?然后简单地将其传递给NotificationManager.notify()您之前使用的ID?

  • 它似乎工作,但我想看看是否有人有任何官方验证,这是新的"这样做的方式"?

我之所以要问这是因为在Android 4.1.1 Jelly Bean,每次notify()调用通知都会闪现.更新进度条时,setProgress()这看起来非常糟糕,并且很难点击通知.4.1或以前的版本不是这种情况.因此,我想确保在提交错误之前正确执行此操作.

android android-notifications android-4.2-jelly-bean

17
推荐指数
1
解决办法
4501
查看次数