我已经创建了一个适用于所有Android版本的通知,但Android 3.x
除外我在没有自定义远程视图的情况下使用NotificationCompat。 ContentIntent已设置。
这是堆栈跟踪:
final NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context);
notificationBuilder.setSmallIcon(R.drawable.ic_update_white_24dp);
notificationBuilder.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), resIdIconaNotifica));
notificationBuilder.setContentTitle(context.getString(R.string.notif_upd_aggiornamento_disponibile));
final String contentText = String.format("%s \"%s\"…", context.getString(R.string.notif_upd_tap_per_aggiornare), context.getString(resIdAppName));
notificationBuilder.setContentText(contentText);
notificationBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(contentText));
notificationBuilder.setAutoCancel(true);
final Intent marketIntent = storeManager.getIntentMarket(context.getPackageName());
final PendingIntent aggiornaPendingIntent = PendingIntent.getActivity(context, 0, marketIntent, PendingIntent.FLAG_CANCEL_CURRENT);
final Intent annullaIntentReceiver = new Intent(NotificationUpdateCancelReceiver.NAME);
annullaIntentReceiver.putExtra(KEY_NOTIFICATION_ID, notificationId);
annullaIntentReceiver.putExtra(KEY_AZIONE, AZIONE_ANNULLA);
final PendingIntent annullaPendingIntentReceiver = PendingIntent.getBroadcast(context, 0, annullaIntentReceiver, PendingIntent.FLAG_CANCEL_CURRENT);
final Intent marketIntentReceiver = new Intent(NotificationUpdateCancelReceiver.NAME);
marketIntentReceiver.putExtra(KEY_NOTIFICATION_ID, notificationId);
marketIntentReceiver.putExtra(KEY_AZIONE, AZIONE_AGGIORNA);
marketIntentReceiver.putExtra(Intent.EXTRA_INTENT, marketIntent);
final PendingIntent aggiornaPendingIntentReceiver = PendingIntent.getBroadcast(context, 1, marketIntentReceiver, PendingIntent.FLAG_CANCEL_CURRENT);
notificationBuilder.setContentIntent(aggiornaPendingIntent);
notificationBuilder.addAction(new NotificationCompat.Action(R.drawable.ic_clear_white_24dp, context.getString(R.string.notif_upd_annulla), annullaPendingIntentReceiver));
notificationBuilder.addAction(new NotificationCompat.Action(R.drawable.ic_update_white_24dp, context.getString(R.string.notif_upd_aggiorna), aggiornaPendingIntentReceiver));
final Notification notification = notificationBuilder.build();
notification.flags |= Notification.FLAG_AUTO_CANCEL;
final NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(notificationId, notification);
这是我的代码:
if(Build.VERSION.SDK_INT >= 14) {
notificationBuilder.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), resIdIconaNotifica));
}
非常感谢你的帮助
更新
我已经解决了:
sed