8

Oreoではなく古いAPIで通知を受け取ることができました。通知を作成すると、私のアプリは正常に動作します(logcatではメッセージは表示されません)。ただし、アクティビティの実行中にSystemUIがクラッシュしてリブートする回数が増えます。 systemuiプロセスのlogcatでエラーです:私は、私が作成したMediaPlayerServiceののonCreateでmNotificationUtilsを初期化Android Oreoの通知でシステムUIがクラッシュする

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()); 
} 

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

私のコード。アイコンのmipmapからdrawable

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

問題は、単に古典的なアイコンで、すべての適応のアイコンを置き換え、それを解決するためのAndroid O.

の新しい適応アイコンに関連しています。 どんなにミップマップや描画可能

場合はいくつかの参照:私は通知を作成しようとしたときに Link 1 Link 2

0

は私のアプリがクラッシュしていました。 私の場合は、Androidスタジオのサンプルプロジェクト "Basic Activity"(AndroidManifest.xml)を使用していました。 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.xmlic_launcher_round.xml上記適応アイコンが含まれています。クラッシュする問題を解決するには、両方のファイルを削除する必要がありました。適応型アイコンファイルを削除した後、pngファイルをアプリアイコンとして使用する必要があります。

関連する問題