내 알림 소리의 지속 시간을 설정하는 데 문제가 있습니다. 여기에 지금 보이는 방법은 다음과 같습니다 당신이 볼 수 있듯이Android : 알림 소리 지속 시간
NotificationManager mNotificationManager = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
// mId allows you to update the notification later on.
mBuilder.setAutoCancel(true);
Uri alarmSound = Uri.parse(sharedPref.getString(
"notifications_new_message_ringtone", ""));
if (alarmSound != null) {
mediaPlayer.setAudioStreamType(AudioManager.STREAM_ALARM);
try {
mediaPlayer.setDataSource(context, alarmSound);
mediaPlayer.prepare();
} catch (IllegalArgumentException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SecurityException e) {
}
mBuilder.setSound(alarmSound);
mNotificationManager.notify(notificationId, mBuilder.build());
new Thread() {
public void run() {
try {
sleep(sharedPref.getInt("alarm_duration",2000) * DateUtils.SECOND_IN_MILLIS);
} catch (InterruptedException e) {
e.printStackTrace();
}
mNotificationManager.cancel(notificationId);
}
}.start();
}
, 나는 sharedPref 변수에 의해 주어진 시간 후에 알림을 중지 (사용자가이를 설정할 수 있습니다). 문제는 다음과 같습니다. "mNotificationManager.cancel (notificationId)"는 소리를 멈추게 할뿐만 아니라 전체 알림 (조명, 진동 및 알림 서랍의 아이콘)을 중지합니다.
알림을 완전히 취소하지 않고 알림을 종료하는 방법이 있습니까?
미리 감사드립니다.
고마워요! :) 나는 첫 번째 접근법을 좋아한다. 어떻게 진행되는지 알려 드리겠습니다. – feresr
이것을 구현할 수 없습니다 : setVolumeControlStream (AudioManager.STREAM_NOTIFICATION); 나는 활동에 있지 않기 때문에 (나는 방송 수신기에있다). 두 번째 코드에 대해서는별로 도움이되지 않습니다. ( – feresr
@ user1949554 [Activity.setVolumeControlStream] (http://bit.ly/1ggCVOk) – adneal