5

我正在尝试在我的应用程序中显示通知以及其中的进度条。

我的应用规范是我的目标是 API 15,最小 SDK 设置为 8。我使用以下代码显示通知:

NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this);

mBuilder.setContentTitle("My Application")
        .setContentText("Downloading...")
        .setProgress(0, 0, true)
        .setSmallIcon(R.drawable.ic_launcher);

PendingIntent in = PendingIntent.getActivity(getApplicationContext(), 0, getIntent(), 0);
mBuilder.setContentIntent(in);

mNotificationManager.notify(0, mBuilder.build());

使用上面的代码,通知出现在通知抽屉中,但没有进度条(在 Android 2.2 和 2.3.3 上)。但进度条在 Android 4.1 上看起来很好。所以很明显它是一个兼容性问题。

如何对我的目标 API 上显示的带有不定进度条的通知进行编码。我尝试使用Notification.Builder,但这个类在我当前的规格中不可用。

提前致谢!

——法拉兹·阿扎尔

4

2 回答 2

0

我鼓励您使用Notification Compat 2。它是为处理此类问题而创建的。
如果您想为通知使用自定义 RemoteViews,请查看我的 fork。我已经提出了拉取请求,但尚未集成。

于 2012-10-16T11:59:30.837 回答
0

您是否尝试过使用http://developer.android.com/reference/android/widget/RemoteViews.html

于 2012-10-16T12:06:09.337 回答