문제

쓰을 사용하여 응용 프로그램을 알림.Google 개발자 가이드라인을 장려하는 개발자가 설정을 제공하는 사용자 정의 알림(비활성화 진동,설정 notification 사운드...),그래서 내가 노력하는 진동을 해제에 대한 알림을 경우에는 사용자 설정하는 방법입니다.

내가 사용하고 NotificationCompat.Builder 하여 알림을 만들은 다음과 같습니다.

NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(Application.getContext())
            .setDefaults(Notification.DEFAULT_ALL)
            .setPriority(Notification.PRIORITY_MAX)
            .setSmallIcon(R.drawable.ic_launcher)
            .setLargeIcon(largeIconBitmap)
            .setAutoCancel(true)
            .setContentIntent(resultPendingIntent)
            .setContentTitle(title)
            .setContentText(content);

나는 여러 가지 방법을 시도하는 알림을 사용하지 않도록 설정:

notificationBuilder.setVibrate(null);

notificationBuilder.setVibrate(new long[]{0l, 0l});

notificationBuilder.setDefaults(Notification.DEFAULT_ALL | ~Notification.DEFAULT_VIBRATE);

notificationBuilder.setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_SOUND);`

또한 나를 구축하기 위해 노력하는 통지하고 값을 변경에 결과 개체:

Notification notification = notificationBuilder.build();
notification.vibrate = null;

하지만 전 여전히 진동될 때 알림이 표시됩니다.

활성화할 수 있는 방법은 진동에 대한 통?

도움이 되었습니까?

해결책

오류 세션을,나는 마지막으로 이해 무엇을 잘못했다.

문제 속에서 이 교육 notificationBuilder.setDefaults(Notification.DEFAULT_ALL).

상관없이 무엇을 전달하는 매개 변수를 notificationBuilder.setVibrate() 후 설정 DEFAULT_ALLDEFAULT_VIBRATE 될 것이 자동으로 삭제됩니다.에서 누군가가 구글이 있어야합을 포기하기로 결정 더 높은 우선 순위를 setDefaultssetVibrate.

이것은 어떻게 결국 사 진동 알림을 위해 내용:

notificationBuilder.setDefaults(Notification.DEFAULT_LIGHT | Notification.DEFAULT_SOUND)
                   .setVibrate(new long[]{0L}); // Passing null here silently fails

이 작지만 생각하지 않는 자를 초기화하는 새로운 long[] 단지 사용하지 않은 진동입니다.

다른 팁

"setDefaults(Notification.DEFAULT_ALL)"를 사용하고 있기 때문에 멈추지 않으므로 진동과 사운드를 제거해야합니다. 또는 기본 사운드를 사용해야합니다. 기본 사운드를 사용해야하고 진동을 중지 해야하는 경우 setDefaults(Notification.DEFAULT_SOUND) 등을 사용해야합니다 ...

.setVibrate(null)가 나를 위해 작동 - 불필요한 긴 []를 만드는 것보다 더 나은 해결책 [].

결과 : 장치가 진동되지 않고 logcat에서 논스함이 아닙니다.:)

notification.vibrate = new long[] { -1 };
.

이 코드는 나를 위해 작동합니다.

private void removeSoundAndVibration(Notification notification) {
        notification.sound = null;
        notification.vibrate = null;
        notification.defaults &= ~DEFAULT_SOUND;
        notification.defaults &= ~DEFAULT_VIBRATE;
.

이 코드는 알림 호환 API 클래스에서입니다.이 작업이 작동해야하며,이 모든 것을 빌더에 추가하십시오.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top