0
當我通知的iconIndex = 0時,它在位置0的數組中查找名稱,並返回「ic_alert」,它是圖標的名稱。但是,選擇該圖標時,纔不想要播放的通知聲音,即使isPlaySound()返回true,太奇怪了......其他圖標做工精細當選擇特定圖標時,Android忽略我的通知聲音
public class AlarmReceiver extends BroadcastReceiver
{
@Override
public void onReceive(Context context, Intent intent)
{
Log.e("ALARMRECEIVER","ONRECEIVE");
//Create a notification
long notificationId = intent.getLongExtra("id", -1);
if(notificationId == -1)
{
Log.e("AlarmReceiver","id went missing");
}
else
{
NotificationRepository repository = NotificationRepository.getInstance(context);
Notification notification = repository.getNotification(notificationId);
if(notification != null)
{
String[] icons = context.getResources().getStringArray(R.array.icons);
int iconId = context.getResources().getIdentifier(context.getPackageName()
+ ":drawable/" + icons[notification.getIconIndex()], null, null);
String icon = icons[notification.getIconIndex()];
//create the android notification
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context)
.setSmallIcon(iconId)
.setContentTitle(notification.getTitle())
.setContentText(notification.getSubtitle())
.setColor(ContextCompat.getColor(context, R.color.colorPrimary));
if(notification.isPlaySound())
{
mBuilder.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION));
Log.e("ALARMRECEIVER", "SOUND");
}
else Log.e("ALARMRECEIVER","NO SOUND");
if (notification.isVibrate())
{
mBuilder.setVibrate(new long[]{1000, 1000});
}
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
// mId allows you to update the notification later on.
mNotificationManager.notify((int) notificationId, mBuilder.build());
//Delete the notification from the database
repository.removeNotification(notificationId);
Intent i = new Intent("dvanack.gmail.com.NOTIFY");
context.sendBroadcast(i);
Log.w("ONRECEIVE","ENDED");
}
我認爲這可能是一個bug在Android – PrisonMike
我已經解決了它,因爲所有其他手機都工作正常並通過更新來解決 – PrisonMike
@XaverKapeller實際上,當運行Cyanogenmod的時候有99%的時間,正確地指責Android,但絕對不能忘記指定它是Android的特殊解釋。如果最初表明這是針對Cyanogenmod建造的,那麼沒有人會質疑這種說法。 – LoungeKatt