AlarmManager只播放默认铃声

发布于 2025-01-19 00:01:43 字数 1300 浏览 3 评论 0原文

我正在使用AlarmManager和PendentIntent创建一个警报。警报起作用,并在正确的时间触发。不幸的是,无论我选择哪种铃声,它总是播放默认的铃声。这是我的代码:

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);
}

我已经使用了调试器,并且知道正确的铃声被作为“ AlarmTone”额外的。

知道为什么选定的铃声不玩

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文