展会信息港展会大全

Notification用法代码 android开发学习
来源:互联网   发布日期:2015-10-02 21:42:34   浏览:1114次  

导读:1.[代码]API 1private void showNotification(Context context, String ticker, String title, String describe, int icon, Intent intent) { int id = mIncrement++; NotificationManager ......

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

}

赞助本站

人工智能实验室

相关热词: Notification 用法 代码

AiLab云推荐
展开

热门栏目HotCates

Copyright © 2010-2024 AiLab Team. 人工智能实验室 版权所有    关于我们 | 联系我们 | 广告服务 | 公司动态 | 免责声明 | 隐私条款 | 工作机会 | 展会港