Android中简单的通知
来源:互联网 发布:中国联通网络测速 编辑:程序博客网 时间:2024/04/18 04:44
先理理思维:
然后我具体代码实现:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.g160628_android30_notification.MainActivity"> <Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:onClick="send" android:text="发送通知"/></LinearLayout>
MainActivity.java 类
package com.example.g160628_android30_notification;import android.app.Notification;import android.app.NotificationManager;import android.support.v7.app.AppCompatActivity;import android.os.Bundle;import android.support.v7.app.NotificationCompat;import android.view.View;public class MainActivity extends AppCompatActivity { private NotificationManager notificationManager; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); //获取通知管理器 notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); } public void send(View view){ NotificationCompat.Builder builder=new NotificationCompat.Builder(this); builder.setContentTitle("提示"); builder.setContentText("中奖啦!请先汇款到XXX账号激活"); builder.setSmallIcon(android.R.drawable.star_on); builder.setDefaults(NotificationCompat.DEFAULT_ALL); builder.setAutoCancel(true); Notification notification=builder.build(); //发送通知 notificationManager.notify(0x101,notification); }}
简单的看看效果:
阅读全文
0 0
- Android中简单的通知
- Android中通知的简单使用和自定义通知样式
- 简单的Android通知
- Android中通知(Notification)的简单使用
- android中通知的使用
- Android中通知的使用
- Android的Notification通知的简单实用
- Android API- Notification(通知)的简单使用
- android -- 通知栏的简单应用
- Android简单的消息通知栏
- Android中通知的使用-----Notification详解
- Android中通知的使用-----Notification详解
- Android中通知的使用-----Notification详解
- Android中通知的使用-----Notification详解
- android中通知栏notification的使用
- Android中通知的使用-----Notification详解
- Android中通知栏的使用方法
- Android中通知的使用-----Notification详解
- 【OpenStack源码分析之十】虚机启动流程中Nova Compute与周边组件的交互
- win10下python中的easy_install和pip的安装方法
- 为了安全~
- 学习心得——数组作为函数参数后sizeof获取不到数组在内存中所占字节数的问题
- POJ-3278 Catch That Cow (BFS入门题
- Android中简单的通知
- Win10环境下.NET连接Oracle数据库进行开发,编译报错175
- MFC原理简介,新手看懂MFC代码
- qt5.5版本的creator构建套件自动检测为警告
- Ubuntu16.04LTS安装Tensorflow篇
- Day01 安装虚拟机
- 使用jsencrypt实现参数的前端加密
- Ubuntu 安装Cuda8后,分辨率不能调节的解决方案
- mysql 1136错误 Column count doesn't match value count at row 1