我正在开发一个Android应用程序,我必须在其中发出警报并设置提醒。
答案 0 :(得分:0)
Android AlarmManager实际上并没有发出声音警报。如果您安排了警报,警报管理员将通过启动您提供的PendingIntent
(在您的情况下为AlarmService)在设定的警报时间通知您的应用程序。它没有做更多的事情。如果你想要声音,你的AlarmService应该在服务启动时播放。您可以使用android mediaplayer进行此操作。
答案 1 :(得分:0)
要在通知中播放声音,您必须将声音文件的网址设置如下
SharedPreferences pref = PreferenceManager.getDefaultSharedPreferences(context);
boolean isSound = pref.getBoolean("sound", true);
String soundUri;
if(isSound) {
soundUri = pref.getString("Ringtone", String.valueOf(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)));
}
notification.sound = Uri.parse(soundUri);
对于设置通知声音,您可以使用RingtonePreference
以下是Preference屏幕的演示xml
<CheckBoxPreference android:title="Vibrate"
android:key="Vibrate" android:defaultValue="true"></CheckBoxPreference>
<CheckBoxPreference android:title="Notification Sound"
android:key="Sound" android:defaultValue="true"></CheckBoxPreference>
<RingtonePreference android:title="Ringtone"
android:key="Ringtone" android:dependency="Sound" android:summary="Select Ringtone"
android:ringtoneType="notification" />
</PreferenceCategory>
<PreferenceCategory android:title="Synchronized Task Notification">
<CheckBoxPreference android:title="Notify for new synchronized task"
android:key="syncNotification" android:defaultValue="true"></CheckBoxPreference>
<ListPreference
android:title="Check for Synchronized tasks after every..."
android:key="syncTime"
android:dependency="syncNotification"
android:defaultValue="300000"
android:entries="@array/syncCheckTimeNames"
android:entryValues="@array/syncCheckTimeValues" />
</PreferenceCategory>