Android中使用Notifaction无反应
时间:2016-4-20 11:07:29
使用Notifaction.Builder()触发时无反应,是否设置图标Icon?
builder.setSmallIcon(R.drawable.ic_launcher);
如果没有设置Icon就会出现触发时无反应。
完整地code样式:
Intent intent = new Intent(context, XXActivity.class);
intent.putExtra("recFile", recName);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification.Builder builder = new Notification.Builder(context);
builder.setTicker("新的通知");
builder.setSmallIcon(R.drawable.ic_launcher);
builder.setContentTitle("收到新的通知");
builder.setContentText("您有一条新的通知");
builder.setContentIntent(pendingIntent);
Notification notification = builder.build();
notification.flags = Notification.FLAG_AUTO_CANCEL;
manager.notify(NOTIFACTION_FLAG_CODE, notification);