我正在尝试在我的应用中显示通知以及其中的进度条。
我的应用规范是我的目标 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
,但我当前的规范不提供此类。
提前致谢!
-法拉兹·阿扎尔
最佳答案
关于安卓通知 : compatibility with APIs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12914126/