安卓通知 : compatibility with APIs

标签 android notifications android-4.2-jelly-bean android-2.3-gingerbread

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

我的应用规范是我的目标 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/

相关文章:

android - Broadcastreceiver 发出的通知在被反压时关闭应用程序

javascript - @JavaScriptInterface 与 ICS 和 JB 项目一起工作

android - Jelly Bean WebView 不能很好地使用文本框的 HTML maxlength 属性

Android:应用在 LaunchActivity {java.lang.SecurityException} 上崩溃

java - 错误 : Execution failed for task ':app:shrinkReleaseMultiDexComponents'

android - Kivy:跨平台通知图标

iphone - iOS推送通知分发证书

android - 有没有办法在 Android JellyBean TimePickerDialog 中使用取消?

java - 经过 Android 验证后无法在 Firebase 中添加

java - FusedLocationApi 方法 getLastLocation() 在第一次调用期间始终为 null