Notification :可以设置 icon message 或者声音播放等提示

NotificationManager :系统服务,执行或管理所有状态通知栏,不能够实例化:(NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

具体实例:

/**获得mNotificationManager**/
mNotificationManager = (NotificationManager) getSystemService(ns);

/**定义notification****/
int icon = R.drawable.ic_launcher;
CharSequence tickerText = "Hello";
long when = System.currentTimeMillis();

notification = new Notification(icon, tickerText, when);

/***定义丰富的提示方式**/
notification.defaults |= Notification.DEFAULT_LIGHTS;
notification.ledARGB = 0xff00ff00;

notification.ledOnMS = 300;

notification.ledOffMS = 1000;

notification.flags |= Notification.FLAG_SHOW_LIGHTS;



/**定义notification 消息 和 pendingIntent****/
Context context = getApplicationContext();
CharSequence contentTitle = "My notification";
CharSequence contentText = "Hello World!";

Intent notificationIntent = new Intent(this, AndroidBroadcastActivity.class);

PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);

/**内容View 定义消息***/
RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.custom_notification);
contentView.setImageViewResource(R.id.image, R.drawable.ic_launcher);
contentView.setTextViewText(R.id.title, "Custom notification");
contentView.setTextViewText(R.id.text, "This is a custom layout");
notification.contentView = contentView;
//
//notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
notification.contentIntent = contentIntent;

//开启消息通知

mNotificationManager.notify(HELLO_ID, notification);


更多相关文章

  1. 安装APK文件的错误码定义
  2. android log使用
  3. Android(安卓)上使用library时xml使用自定义属性提示 error: Err
  4. Android(安卓)Retrofit 入门教程
  5. Android中显示消息通知栏
  6. Android(安卓)dialog 对话框自定义布局
  7. android 自定义标题栏 titleBar自定义
  8. Android(安卓)camera 设置聚焦区域
  9. android Launcher:AllApps的更新分析

随机推荐

  1. java版 android遥控电脑关机
  2. Android开发之天气预报(四)UI界面实现
  3. Android笔面试
  4. Android参考书籍
  5. 聊聊 Android(安卓)中的三大框架
  6. Android中使用socket使底层和framework通
  7. Android(安卓)View体系(一)视图坐标系
  8. Android画图--Matrix
  9. Android(安卓)NDK开发Crash错误定位
  10. 基于Android10的Activity的启动流程简析