NotificationBuilder.setProgress在2.3.5上没有做任何事情

时间:2013-04-29 15:53:45

标签: android android-support-library

我正在使用v13支持库。我使用通知构建器和.setProgress构建进度通知。它在4.2.2设备上工作正常,但在2.3.5上没有显示任何内容。

这是正常行为吗?

mNotifyManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

mBuilder = new NotificationCompat.Builder(this);

mBuilder.setContentTitle("Photo Upload")
            .setContentText("Upload in progress")
            .setSmallIcon(R.drawable.ic_action_upload)
            .setOngoing(true);

.
.

mBuilder.setProgress(100, prog, false);
mNotifyManager.notify(sNotificationID, mBuilder.build());

2 个答案:

答案 0 :(得分:1)

似乎不支持姜饼(及以下),也没有记录。
以下是支持库中的实际代码,它创建了Notification的实例:

static class NotificationCompatImplBase implements NotificationCompatImpl {
    public Notification build(Builder b) {
        Notification result = (Notification) b.mNotification;
        result.setLatestEventInfo(b.mContext, b.mContentTitle,
                b.mContentText, b.mContentIntent);
        // translate high priority requests into legacy flag
        if (b.mPriority > PRIORITY_DEFAULT) {
            result.flags |= FLAG_HIGH_PRIORITY;
        }
        return result;
    }
}

唯一可行的选择是使用自定义RemoteView。您可能需要查看Android源代码以获取示例进度通知布局。

答案 1 :(得分:0)

  

它在4.2.2设备上工作正常,但在2.3.5上没有显示

Android 1.x和2.x(尤其是Gingerbread)需要Notification contentIntent(也为空)。所以创建这样的空行动:

PendingIntent action = PendingIntent.getBroadcast(<context>, 0, 
                                new Intent(), PendingIntent.FLAG_UPDATE_CURRENT);
...
mBuilder.setContentIntent(action);

现在它应该有效。