为什么在2.3.6设备上没有显示此通知?

时间:2014-05-11 09:15:31

标签: android notifications

我有这个发出通知的简单代码。

NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
            this)
    .setSmallIcon(
            R.drawable.ic_launcher)
            .setContentTitle("Error deactivating Tracker")
            .setContentText("Unable to send deactivation SMS");

    NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    // mId allows you to update the notification later on.
    mNotificationManager.notify(0, mBuilder.build());

通知在4.4.2设备上正确显示,但不会在2.3.6设备上显示。

我正在使用NotificationCompat所以我想它应该显示。

我做错了什么?

1 个答案:

答案 0 :(得分:1)

解决。

显然它在任何情况下都需要PendingIntent,

所以我加了它:

PendingIntent pi = PendingIntent.getBroadcast(this, 0, new Intent(),      PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
            this)
    .setSmallIcon(
            R.drawable.ic_launcher)
            .setContentTitle("Error deactivating Tracker")
            .setContentText("Unable to send deactivation SMS")
            .setContentIntent(pi).setTicker("Error deactivating Tracker");

    NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    // mId allows you to update the notification later on.
    mNotificationManager.notify(0, mBuilder.build());