ABOUT ME

Today
Yesterday
Total
  • 버전 8 및 9의 일부 Android 장치에서 작동하지 않는 알림 예약
    카테고리 없음 2020. 8. 15. 12:25

    질문

    버전 8의 일부 실제 Android 장치에서 알림이 작동하지 않습니다. 9 가지 알림 설정이 활성화되었지만 정상적으로 작동합니다. 에뮬레이터. 알림을 트리거하도록 알람 관리자를 예약했습니다. 알림이있는 브로드 캐스트 수신기를 사용하는 시간 생성.

    private void generateNotification(Context context, String message) {
    
            NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
            createNotificationChannel(notificationManager);
            RemoteViews view = new RemoteViews(context.getPackageName(), R.layout.notification_main);
            view.setImageViewResource(R.id.ImageView1, R.drawable.tenkey_icon);
            view.setTextViewText(R.id.title1, Utils.NOTIFICATION_TITLE);
            view.setTextViewText(R.id.message1, message);
            view.setTextViewText(R.id.time1, notificationTiming);
            Intent notificationIntent = new Intent(context, MainActivity.class);
            notificationIntent.putExtra("content", message);
            notificationIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
    
            Notification.Builder builder=new Notification.Builder(context)
                    .setSmallIcon(R.drawable.ic_launcher)
                    .setOngoing(true)
                    .setContentIntent(PendingIntent.getActivity(context, 0, notificationIntent, 0))
                    .setContent(view);
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                builder.setChannelId(CHANNEL_ID);
            }
            Notification notification = builder.build();
            notification.flags |= Notification.FLAG_AUTO_CANCEL;
            notification.defaults |= Notification.DEFAULT_SOUND;
            notification.defaults |= Notification.DEFAULT_VIBRATE;
            notificationManager.notify((int)System.currentTimeMillis() % 1000000, notification);
        }
    
    
    
    private void createNotificationChannel(NotificationManager manager) {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                NotificationChannel serviceChannel = new NotificationChannel(
                        CHANNEL_ID,
                        "Shankaram",
                        NotificationManager.IMPORTANCE_DEFAULT
                );
                manager.createNotificationChannel(serviceChannel);
            }
        }

    에뮬레이터에서 잘 작동하며 모든 실제 장치가 없습니다. 이 시점에서 임 테스트 및 디버그. 무엇이든 처리해야합니다. 안드로이드 파이의 알람 관리자? 제안하십시오


    답변1

    Android 8 이상에서는 알림 채널 을 사용해야합니다.

    Android 8.0 (API 레벨 26)부터 모든 알림은 채널에 할당되어야합니다. 그렇지 않으면 표시되지 않습니다. 알림을 채널로 분류하면 사용자는 앱에 대한 특정 알림 채널을 비활성화 할 수 있으며 (모든 알림을 비활성화하는 대신), 사용자는 각 채널의 시각 및 청각 옵션을 제어 할 수 있습니다 (모두 Android 시스템 설정에서) (그림 11). 사용자는 알림을 길게 눌러 관련 채널의 동작을 변경할 수도 있습니다.



    답변2

    모든 알림을 자세히 확인하여이 문제를 해결했습니다. 전화에서 설정하고 모든 설정을 활성화하고 마지막으로 일했다. 코드가 변경되지 않았습니다.



     

     

     

     

    출처 : https://stackoverflow.com/questions/58281918/scheduling-notifications-not-working-on-some-android-devices-of-version-8-and-9

    댓글

Designed by Tistory.