我正在尝试在我的应用程序中显示通知以及其中的进度条。
我的应用规范是我的目标是 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
,但这个类在我当前的规格中不可用。
提前致谢!
——法拉兹·阿扎尔