Android中使用Notifaction无反应

时间:2016-4-20 11:07:29

使用Notifaction.Builder()触发时无反应,是否设置图标Icon?
  1. builder.setSmallIcon(R.drawable.ic_launcher);
如果没有设置Icon就会出现触发时无反应。

完整地code样式:
  1. Intent intent = new Intent(context, XXActivity.class);
  2. intent.putExtra("recFile", recName);
  3. PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
  4. NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
  5. Notification.Builder builder = new Notification.Builder(context);
  6. builder.setTicker("新的通知");
  7. builder.setSmallIcon(R.drawable.ic_launcher);
  8. builder.setContentTitle("收到新的通知");
  9. builder.setContentText("您有一条新的通知");
  10. builder.setContentIntent(pendingIntent);
  11. Notification notification = builder.build();
  12. notification.flags = Notification.FLAG_AUTO_CANCEL;
  13. manager.notify(NOTIFACTION_FLAG_CODE, notification);





posted @ 2016-04-20 14:32  五月的雨  阅读(757)  评论(0编辑  收藏  举报