Notification用法,
投稿于 被查看 33459 次 评论:108
Notification用法,
<无详细内容>1.API 1
private void showNotification(Context context, String ticker, String title, String describe, int icon, Intent intent) { int id = mIncrement++; NotificationManager nm = (NotificationManager)context.getSystemService( Context.NOTIFICATION_SERVICE); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0); Notification notification = new Notification(icon, ticker,System.currentTimeMillis()); notification.setLatestEventInfo(context, title, describe, pendingIntent); notification.flags |= Notification.FLAG_AUTO_CANCEL; nm.notify(id, notification); }
2.API 11
private void showNotificaion(Context context, int id) { NotificationManager nm = (NotificationManager) context.getSystemService( Context.NOTIFICATION_SERVICE); Intent intent = new Intent(Intent.ACTION_MAIN); PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0); Notification notification = new Notification.Builder(context) .setAutoCancel(true) .setContentTitle("title") .setContentText("describe") .setContentIntent(pendingIntent) .setSmallIcon(R.drawable.ic_launcher) .setWhen(System.currentTimeMillis()) .build(); nm.notify(id, notification); }
用户评论