1 year ago

#374533

test-img

Jan Horčička

AlarmManager plays only default ringtone

I'm creating an alarm using AlarmManager and PendingIntent. The alarm works and is triggered at the correct time. Unfortunately, it always plays the default ringtone, regardless of what ringtone I have selected. This is my code:

public void setAlarm() {
    Cursor cursor = dataBaseHelper.showSpecificTableData(DBFields.TABLE_OF_ALARMS, DBFields.ALARM_STATUS, "On");
    cursor.moveToLast();

    String alpha[] = cursor.getString(cursor.getColumnIndex(DBFields.ALARM_TIME)).split(":");

    calendar.set(Calendar.HOUR_OF_DAY, Integer.parseInt(alpha[0]));
    calendar.set(Calendar.MINUTE, Integer.parseInt(alpha[1]));
    calendar.set(Calendar.SECOND, 0);

    Intent intent = new Intent(AddAlarm.this, AlarmReceiver.class);
    intent.putExtra("AlarmTone", cursor.getString(cursor.getColumnIndex(DBFields.ALARM_TONE)));
    intent.putExtra("AlarmId", cursor.getInt(cursor.getColumnIndex(DBFields.ALARM_ID)));
    intent.putExtra("AlarmName", cursor.getString(cursor.getColumnIndex(DBFields.ALARM_NAME)));
    intent.putExtra("AlarmTime", cursor.getString(cursor.getColumnIndex(DBFields.ALARM_TIME)));
    pendingIntent = PendingIntent.getBroadcast(getApplicationContext(),
            100,
            intent,
            FLAG_UPDATE_CURRENT);

    alarmManager.setExact(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);
}

I have used debugger and I know that the correct ringtone is put into the Intent as an "AlarmTone" extra.

Any idea why the selected ringtone isn't playing

android

alarmmanager

android-pendingintent

0 Answers

Your Answer

Accepted video resources