8

이전 API에서는 작동하지만 Oreo에서는 작동하지 않는 알림을 얻을 수있었습니다. 알림을 생성하면 내 응용 프로그램이 계속 정상적으로 작동하지만 (logcat에서는 메시지가 표시되지 않음), Activity가 실행되는 동안 SystemUI가 충돌하고 무한 순환으로 재부팅됩니다.Android Oreo 알림이 시스템 UI를 충돌 함

java.lang.IllegalArgumentException: width and height must be > 0 

내 코드 :

private void showPlayingNotification() { 
     NotificationCompat.Builder builder = mNotificationUtils.getAndroidChannelNotification(this, "Play", mMediaSessionCompat); 
     if(builder == null) { 
      Log.i("Play Notification","No notification found!"); 
      return; 
     } 

     mNotificationUtils.getManager().notify(101,builder.build()); 
} 

은 내가 만든 MediaPlayerService의에서 onCreate에 mNotificationUtils을 초기화는 systemui 과정에 대한 로그 캣에서 오류가 발생합니다. 아이콘에 대한 drawablemipmap에서

public class NotificationUtils extends ContextWrapper { 

    private NotificationManager mManager; 
    public static final String AUDIO_CHANNEL_ID = "com.liftyourheads.dailyreadings.dailyReadingsAudio"; 
    public static final String AUDIO_CHANNEL_NAME = "Daily Readings Audio Stream"; 

    public NotificationUtils(Context base) { 
     super(base); 
     createChannels(); 
    } 

    public void createChannels() { 

     if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { 
      // create android channel 
      NotificationChannel dailyReadingsAudioChannel = new NotificationChannel(AUDIO_CHANNEL_ID, 
        AUDIO_CHANNEL_NAME, NotificationManager.IMPORTANCE_HIGH); 
      getManager().createNotificationChannel(dailyReadingsAudioChannel); 

     } 
    } 

    public NotificationManager getManager() { 
     if (mManager == null) { 
      mManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); 
     } 
     return mManager; 
    } 

    public NotificationCompat.Builder getAndroidChannelNotification(Context context, String action, MediaSessionCompat mediaSession) { 

     if (action.equals("Play")) { 
      return MediaStyleHelper.from(context, mediaSession) 
        .addAction(new NotificationCompat.Action(android.R.drawable.ic_media_pause, "Pause", MediaButtonReceiver.buildMediaButtonPendingIntent(this, PlaybackStateCompat.ACTION_PLAY_PAUSE))) 
        .setStyle(
          new android.support.v4.media.app.NotificationCompat.MediaStyle() 
            .setShowActionsInCompactView(0) 
            .setMediaSession(mediaSession.getSessionToken())) 
        .setSmallIcon(R.mipmap.ic_launcher) 
        .setContentText("Content Text") 
        .setContentTitle("Content Title") 
        .setChannelId(AUDIO_CHANNEL_ID); 

     } else if (action.equals("Pause")) { 

      return MediaStyleHelper.from(context, mediaSession) 
        .addAction(new NotificationCompat.Action(android.R.drawable.ic_media_play, "Play", MediaButtonReceiver.buildMediaButtonPendingIntent(this, PlaybackStateCompat.ACTION_PLAY_PAUSE))) 
        .setStyle(
          new android.support.v4.media.app.NotificationCompat.MediaStyle() 
            .setShowActionsInCompactView(0) 
            .setMediaSession(mediaSession.getSessionToken())) 
        .setSmallIcon(R.mipmap.ic_launcher) 
        .setContentText("Content Text") 
        .setContentTitle("Content Title") 
        .setChannelId(AUDIO_CHANNEL_ID); 

     } 

     return null; 

    } } 

답변

12

전환합니다. 자세한 내용은 this issue을 참조하십시오.

+0

고마워요! 이것이 이유였습니다. –

3

문제는, 그것을 해결 단지 고전적인 아이콘 모든 적응 아이콘을 교체하려면 안드로이드 O.

의 새로운 적응 아이콘에

관련된다. 상관없이 밉맵 또는

당김 일부 참조하는 경우 : 내가 알림을 만들려고 할 때 Link 1 Link 2

0

내 애플 충돌했다. 저의 경우, 아래에 AndroidManifest.xml이 포함 된 Android Studio 샘플 프로젝트 인 "기본 활동"을 사용하고있었습니다. mipmap/ic_launcher 및 mipmap/ic_launcher_round는 앱 아이콘으로 사용됩니다.

<application 
    android:name=".DriveMeApp" 
    android:allowBackup="true" 
    android:icon="@mipmap/ic_launcher" 
    android:label="@string/app_name" 
    android:roundIcon="@mipmap/ic_launcher_round" 
    android:supportsRtl="true" 
    android:theme="@style/AppTheme"> 

이 프로젝트는 ic_launcher.xml 및 적응 아이콘 위 ic_launcher_round.xml가 포함되어 있습니다. 충돌 문제를 해결하기 위해 두 파일을 모두 삭제해야했습니다. 적응 형 아이콘 파일을 삭제 한 후, png 파일을 앱 아이콘으로 사용해야합니다.