1
이 주제와 관련된 몇 가지 질문을 살펴본 결과 알림 작성기에서 .setSound(alarmSound)
을 사용하면 알림이있는 소리가 재생됩니다. 그러나, 나는 단지 그것을하고 있고 그것은 작동하지 않습니다.Android 알림 - setSound가 작동하지 않습니다.
나는 아마 뭔가를 놓치고 있지만 그것이 무엇인지 찾을 수 없습니다.
private void newArrivalNotification(String locId, String userId) {
...
mNotificationManager = (NotificationManager)
this.getSystemService(Context.NOTIFICATION_SERVICE);
Intent mainActivity = new Intent(this, MainActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(this, locId.hashCode(),
mainActivity, 0);
Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
if(alarmSound == null) {
Log.w("GcmIntentService", "alarmSound is null");
}
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setAutoCancel(true)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle(title)
.setStyle(new NotificationCompat.BigTextStyle()
.bigText(msg))
.setSound(alarmSound, AudioManager.STREAM_NOTIFICATION)
.setTicker(msg)
.setContentText(msg);
mBuilder.setContentIntent(contentIntent);
Notification arrivalNotification = mBuilder.build();
arrivalNotification.defaults |= Notification.DEFAULT_VIBRATE;
mNotificationManager.notify(NOTIFICATION_ID, arrivalNotification);
}
당신은 내가 잘못했던 것을 발견 할 수 : 여기
내가 통지를 발행하는 사용하고 코드입니다? 나는 몇 시간을 보았고 아무것도 찾을 수 없었다.
진동을 생성하기 위해'arrivalNotification.defaults | = Notification.DEFAULT_VIBRATE;를 사용하는 대신 자신의 패턴을 사용할 수도 있습니다.'long pattern [] = {0,2000, 500,2000};'.setVibrate (pattern)'을 사용하여 진동을 설정할 수 있습니다. 정상적으로 작동합니다. –