【发布时间】:2016-09-23 20:40:12
【问题描述】:
我正在尝试使用 Android 的通知管理器,即 android.app.Notification 和 android.app.NotificationManager 在我的 Android 设备上使用以下代码可以正常工作有操作系统 4.4.2。 似乎它们在某些较旧的操作系统(例如 4.2.x)上无法正常工作。我看到一个通知弹出,但声音是默认通知声音,而不是我选择的声音,这在我的设备上运行良好,即 4.4.2。
Uri alarmSound = Uri.parse("/storage/sdcard1/MyApp/Media/Sounds/fire.mp3");
NotificationCompat.InboxStyle inboxStyle = new NotificationCompat.InboxStyle();
inboxStyle.setBigContentTitle(notificationString);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0,
(new Intent(context, NavigationMenu.class)),
0);
Notification notification = new NotificationCompat.Builder(context)
.setSmallIcon(R.drawable.logo_black)
.setContentTitle(notificationString)
.setContentText(notificationString)
.setContentIntent(pendingIntent)
.setAutoCancel(true)
.setSound(alarmSound)
.build();
mNotificationManager.notify(notificationId, notification);
uri 实际上不是硬编码的,而是使用 Environment.getExternalStorageDirectory() 获得的,并且文件存在于指定位置。由于这在我的设备上运行良好,而不是在旧设备上,所以首先想到的是操作系统版本的问题,但我找不到旧版本的解决方案。
更新 所以这似乎不是操作系统的问题,因为我在另一台使用 OS 4.2.2 的 Android 设备上对其进行了测试并且它工作正常。
还是查不出原因……
【问题讨论】:
标签: android notifications