0

私はカスタムビュー通知を表示していますが、マシュマロを除いて完全に動作しています。私は24x24,36x36、 48×48、72x72のピクセルアイコンAPIレベル23でアプリケーションクラッシュ:例外java.lang.IllegalArgumentException:無効な通知(有効な小さなアイコンなし):

android.support.v7.app.NotificationCompat.Builder builder = new android.support.v7.app.NotificationCompat.Builder(m_context); 
    Intent i = new Intent(m_context, RunningAppsActivity.class); 
    i.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP); 
    PendingIntent intent = PendingIntent.getActivity(m_context, 0, i, PendingIntent.FLAG_UPDATE_CURRENT); 
    builder.setTicker(m_context.getResources().getString(com.soopermo.batterybooster.R.string.click_to_optimize)); 
    builder.setSmallIcon(R.drawable.battry_notify); 
    builder.setAutoCancel(true); 
    Notification notification = builder.build(); 
    RemoteViews contentView = new RemoteViews(m_context.getPackageName(),R.layout.status_bar); 
    // Set text on a TextView in the RemoteViews programmatically. 
    final String text = m_context.getResources().getString(com.soopermo.batterybooster.R.string.draining_apps) ; 
    contentView.setTextViewText(com.soopermo.batterybooster.R.id.status_bar_content_desc2, text); 
    contentView.setOnClickPendingIntent(com.soopermo.batterybooster.R.id.optimization, intent); 
    notification.contentView = contentView; 

    // Add a big content view to the notification if supported. 
    // Support for expanded notifications was added in API level 16. 
    // (The normal contentView is shown when the notification is collapsed, when expanded the 
    // big content view set here is displayed.) 
    if (Build.VERSION.SDK_INT >= 16) { 
     // Inflate and set the layout for the expanded notification view 
     RemoteViews expandedView = 
       new RemoteViews(m_context.getPackageName(), com.soopermo.batterybooster.R.layout.status_bar); 
     notification.bigContentView = expandedView; 
     expandedView.setOnClickPendingIntent(com.soopermo.batterybooster.R.id.optimization, intent); 
    } 
    NotificationManager nm = (NotificationManager) m_context.getSystemService(NOTIFICATION_SERVICE); 
    nm.notify(POWER_ISSUES_ID, notification); 
    //........................................................... 
+0

Image Assetから通知アイコンを作成するのがよい方法です。 – Wizard

+0

@Wizardそれを行う方法のサンプルコードを私に教えてください。 – Sam

+0

回答を追加する。 – Wizard

答えて

0

これが原因lollypop(21)の上に起こっているアンドロイドは小さいアイコンのための任意のカラー化画像をサポートしていません。

白い前景と透明な背景を持つ画像を使用する必要があります。

このように使用してください。

private int getNotificationSmallIcon() 
{ 
    boolean useWhiteIcon = (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP); 
    return useWhiteIcon ? R.drawable.icon_for_above_lollypop : R.drawable.normal_icon; 
} 

編集

はここで良い練習になりImage Assetオプションからの通知アイコンの作成21 https://material.io/icons/

0

上でサポートされていたアイコンです。あなたがベクトルで作業している場合は、ユーザVector Asset
Androidスタジオのスクリーンショットを添付してください。

enter image description here

次の画面のドロップダウンから通知アイコンを選択します。

+0

ええ、そこにはいくつかのデフォルトアイコンがアクセス可能で、私は自分のアプリアイコンを使用したいので、何とか自分のアプリアイコンをそのクリップアートオプションに追加できますか? – Sam

+0

そのためには、Asset type as imageを選択します。そこには閲覧オプションがあります。 – Wizard

+0

まだ同じ問題 – Sam

関連する問題