私はカスタムビュー通知を表示していますが、マシュマロを除いて完全に動作しています。私は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);
//...........................................................
Image Assetから通知アイコンを作成するのがよい方法です。 – Wizard
@Wizardそれを行う方法のサンプルコードを私に教えてください。 – Sam
回答を追加する。 – Wizard