Android 8.0 알림 표시줄에 맞춤법 표시(Notification에 문제가 표시되지 않음)

3082 단어 프로젝트 문제
테스트 피드백으로 이전에 작성한 알림판 다운로드 업데이트가 일부 휴대전화에 나타나지 않아 사용자가 업데이트할 수 없다는 것을 발견했다.처음에는 샤오미 핸드폰이라고 강조해서 안드로이드 8로 가지 않았어요.0의 방향으로 생각하면, 묵묵히 업데이트 방법이 잘못되었다고 생각하고, 로그 로그를 본 후 정상적으로 업데이트할 수 있지만, 업데이트 다운로드의 진도표를 알림 표시줄에 표시할 수 없기 때문에 안드로이드8.0 알림 표시줄의 권한 관리에 대해 자료를 조회한 후 8.0버전의 문제에 적합합니다.
먼저 공식 통지 문서를 붙이다.https://developer.android.google.cn/training/notify-user/build-notification
Android O(SDK26 버전)는 공지 채널(Notification Channels)을 도입하여 다음과 같은 여러 속성을 추가했습니다.
 
  • 중요성
  • 사운드
  • 진동
  • 잠금 화면에 표시
  • 무중단 모드 교체
  •  
    중요도 수준: IMPORTANCENONE、IMPORTANCE_MIN、IMPORTANCE_MAX、IMPORTANCE_LOW、IMPORTANCE_HIGH(유사한 내용은 위에서 표시한 링크를 참조하여 공식적으로 모두 설명함)
    그래서 API를 보고 나서야 안드로이드 8을 발견했어요.0에서 알림 표시줄의 다운로드 업데이트 표시를 다시 정의해야 합니다. 개인이 정의한 도구 클래스로 설명하려면 애플리케이션의 유일한 ID와Name
     
    private static final int YOUR_NOTIFICATION_ID = 0x002;
    private static final String YOUR_CHANNEL_ID = "YOUR_NOTIFY_ID";
    private static final String YOUR_CHANNEL_NAME = "YOUR_NOTIFY_NAME";
            ,     ID Name      ,    ,      .

     
    @RequiresApi(api = Build.VERSION_CODES.O)
    public void CreateNotificationChannel(NotificationManager notificationManager) {
        NotificationChannel channel = new NotificationChannel(YOUR_CHANNEL_ID,YOUR_CHANNEL_NAME,Notifi  cationManager.IMPORTANCE_HIGH);
        notificationManager.createNotificationChannel(channel);
    }
  • public void CreateNotification(String title, String content){
  •     if (Build.VERSION.SDK_INT >= 26) {
            createNotificationChannel(getManager());
            notification = new Notification.Builder(getApplicationContext(), YOUR_CHANNEL_ID).build();
    
        } else {
            notification = new Notification();
        }

     
    //       
    notification.icon = ;
    notification.flags = ;
    notification.tickerText = ;
    notification.when = ;
    notification.defaults = ;
    notification.contentView = ;

    }
    상용 필드:contentIntent 설정 PendingIntent 대상, 클릭할 때 이 Intentdefaults를 보내서 기본 효과 flags 설정 flag 위치를 추가합니다(예를 들어 FLAGNO_CLEAR 등 icon 설정 아이콘 sound 설정 사운드tickerText 상태막대에 표시되는 텍스트
    when 이 알림을 보내는 시간 스탬프
    도구 클래스 NotificationUtils에 선언된 내용:
         private NotificationManager manager;
     
  • private NotificationManager getManager(){
  • if (manager == null){
  • manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
  • }
  • return manager;
  • }

  • 2. 알림 표시줄 다운로드 업데이트 완료 후 설치에 대해서도 주의해야 한다.
     
    8.0 여부를 판단하려면 '알 수 없는 출처 허용' 을 검사해야 합니다
     
  • 명세서 파일인 안드로이드 매니페스트에 다음과 같은 권한을 추가해야 한다
  • //알 수 없는 응용 프로그램의 원본을 설치할 권한을 요청합니다
  • ActivityCompat.requestPermissions(this, new String[]{ Manifest.permission.REQUEST_INSTALL_PACKAGES}, INSTALL_PACKAGES_REQUESTCODE);}
  • //알 수 없는 응용 프로그램의 원본을 설치할 권한을 요청
  • ActivityCompat.requestPermissions(this, new String[]{ Manifest.permission.REQUEST_INSTALL_PACKAGES}, INSTALL_PACKAGES_REQUESTCODE);}
  • 좋은 웹페이지 즐겨찾기