사이트에서 가능한 모든 답변을 시도했지만 어쨌든 알림 사운드가 작동하지 않습니다.Android : 맞춤 알림 소리가 재생되지 않습니다.
public class AlarmReceiver extends BroadcastReceiver {
private static final int NOTIFICATION_ID = 0;
@Override
public void onReceive(Context context, Intent intent) {
NotificationCompat.Builder builder = new NotificationCompat.Builder(context)
.setContentTitle(context.getString(R.string.app_name))
.setContentIntent(PendingIntent.getActivity(context, 0, new Intent(context, MainActivity_.class), 0))
.setContentText("temporary text")
.setAutoCancel(true)
.setSound(Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE
+ "://" + context.getPackageName() + "/raw/alert"))
.setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE)
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
.setWhen(System.currentTimeMillis())
.setSmallIcon(R.drawable.ic_stat_notification);
Notification notification = builder.build();
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(NOTIFICATION_ID, notification);
소리 그러나, MediaPlayer를 통해 재생할 수 있습니다, 그래서 형식은 여기에 문제가되지 않습니다 : 내가 테스트를 해요 현재 코드 (알림이 알람 리시버에 내장되어 있습니다)이 있습니다. 소리의 길이 (30 초)와 관련이있을 수 있습니까? 도움을 주셔서 감사합니다.
소리 형식이란 무엇입니까? MediaPlayer를 통해 재생할 수있는 소리에는 문제가 있었지만 알림에는 문제가 없었습니다. 예를 들어 사운드 파일을 wmv로 바꾸려고했습니다. (내가 정확히 문제가있는 파일 형식을 기억하지 못합니다.) –
/raw – eduyayo
wav로 바꿔서 원본을 제거하려고 시도했지만 작동하지 않았습니다. 약간의 결과가 있습니다. 경로가 잘못되어 있으면 뭔가를 알아낼 수 있습니다. D/NotificationManager : 알리미 : notification.sound android.resource : // * packagename (숨겨야 함) */raw/alert –