欢迎访问移动开发之家(rcyd.net),关注移动开发教程。移动开发之家  移动开发问答|  每日更新
页面位置 : > > > 内容正文

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);
}

用户评论