【问题标题】:MediaStyle notification updatesMediaStyle 通知更新
【发布时间】:2014-11-01 14:35:57
【问题描述】:

我正在更改现有应用程序以使用 MediaStyle 通知在 Android 5.0 中提供锁屏音乐信息和传输控件。但是,更新此类通知似乎没有按预期工作。以下代码 sn-p 每次按下按钮时都会生成通知,并增加通知标题中显示的计数器:

public class MainActivity extends Activity {    
    private int serial;
    private TextView text;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        text = (TextView)findViewById(R.id.textView1);
    }

    public void buttonClick(final View view) {
        final Notification.Builder builder = new Notification.Builder(this)
            .setContentTitle("Title " + serial)
            .setContentText("Text")
            .setContentInfo("Info")
            .setSmallIcon(R.drawable.ic_launcher)
            .setLargeIcon(BitmapFactory.decodeResource(getResources(),R.drawable.ic_launcher))
            .setOngoing(true)
            .setStyle(new Notification.MediaStyle())
            .setVisibility(Notification.VISIBILITY_PUBLIC);

            NotificationManager nm = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE );
            nm.notify(1, builder.build());

            text.setText("Serial = " + serial);

            serial++;
    }
}

问题是:

  • 在运行 5.0 的模拟器中执行时,通知抽屉或锁屏中的通知文本与 TextView 中显示的序列号不同步。如果 MediaStyle设置,通知在通知抽屉中的编号正确,但在锁定屏幕中没有。
  • MediaStyle 通知在锁定屏幕中正确显示,直到它第一次在通知抽屉中查看。之后,它不再在锁定屏幕中显示为 MediaStyle 通知(但不完全像标准的非 MediaStyle 通知)。值得注意的是,使用addAction() 添加的按钮将不再显示,直到模拟器重新启动。

所以我怀疑我做错了什么(要么是那个,要么是模拟器上运行的 Android 映像坏了,但这似乎不太可能)。有什么想法吗?

【问题讨论】:

    标签: android android-notifications android-5.0-lollipop


    【解决方案1】:

    原来模拟器毕竟坏了。通知行为,包括更新添加了addAction() 的图标、标题和信息更新以及在抽屉中看到后锁定屏幕中的通知,在真实设备(运行 5.0 的 Nexus 5)中是正确的。但是,在编写此答案时,API 21 SDK 提供的模拟器中仍然存在问题,并且没有可用的更新。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-06
      • 2022-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多