Android通知栏消息(基本文字通知)
来源:互联网 发布:mac air 电池循环次数 编辑:程序博客网 时间:2024/05/21 09:40
结合官方文档:
https://developer.android.com/index.html
https://developer.android.com/reference/android/app/NotificationManager.html
https://developer.android.com/reference/android/app/Notification.html
调用需要2个最基本的元素
1、NotificationManager:是状态栏通知管理类,负责发送和清除通知
2、Notification:具体的状态栏通知对象,设置内容包含标题、文字、图片等
使用场景:用户成功登录之后,通知栏提示消息
需要改造的代码:
/** * 发送网络请求不能在主线程,需要新开一个线程 */ Runnable requestAPI = new Runnable() { @Override public void run() { Form form = new Form().add("user_name",login_username.getText().toString()) .add("user_pass",login_pwd.getText().toString()); try { Request request = Bridge.post("http://192.168.15.138/user.php").body(form).request(); Response response = request.response(); if (response.isSuccess()){ // 服务器响应的数据转json JSONObject jsonObject = response.asJsonObject(); Looper.prepare(); //创建消息队列 // 对话框 AlertDialog.Builder builder = new AlertDialog.Builder(LoginActivity.this); builder.setTitle("登录结果"); builder.setMessage(jsonObject.get("message").toString()); builder.setPositiveButton("知道了", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialogInterface, int i) { dialogInterface.dismiss(); // 关闭对话框 } }); // 如果登录成功 if (jsonObject.get("status").toString().equals("success")){ NotificationManager notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); NotificationCompat.Builder notice = new NotificationCompat.Builder(LoginActivity.this); notice.setTicker("欢迎回来"); notice.setContentTitle("今日登录奖励"); notice.setContentText("5积分,更多请点击"); notice.setDefaults(Notification.DEFAULT_SOUND); //声音 //notice.setSmallIcon() //设置小图标 //notice.setLargeIcon() //设置大图标 notice.setNumber(3); notificationManager.notify(123,notice.build()); }else{ builder.show(); // 不要忘记最后展示对话框 } Looper.loop(); //进入消息循环 }else{ // http请求失败 } } catch (BridgeException e) { e.printStackTrace(); }catch (JSONException e) { e.printStackTrace(); } } };
0 0
- Android通知栏消息(基本文字通知)
- Android 通知栏消息
- Android 通知栏消息
- android 通知栏消息
- android通知栏区分多通知消息
- android通知栏的消息通知(Notification)
- 通知栏消息通知详解(Notification)
- Android消息通知栏应用
- android的消息通知栏
- Android消息通知栏开发
- Android显示通知栏消息
- Android Notification通知栏消息
- Android发送通知栏消息
- Android发送通知栏消息
- Android 通知栏推送消息
- Android通知栏通知
- Android 消息通知-Notification
- Android 消息通知机制
- ListView与不同模板视图适配器Adapter兼容问题
- Windows环境下Composer的安装教程
- iOS应用架构谈 组件化方案
- 资料链接
- BZOJ 1293: [SCOI2009]生日礼物 链表模拟
- Android通知栏消息(基本文字通知)
- 在Java Web项目中引入Mondrian多维分析框架
- docker配置文件
- cc2541 gpio通用gpio和adc的使用
- python 迭代器
- BaseServlet 的实现解析
- c++实验4-项目7
- 利用FFmpeg合成视频、提取视频帧
- Unity3D中C#使用指针(Unsafe)报错处理