Notification 模拟收到短信

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical"android:layout_width="fill_parent"android:layout_height="fill_parent"><Buttonandroid:id="@+id/btn"android:layout_width="match_parent"android:layout_height="wrap_content"android:text="单击发送Notification信息"/>
</LinearLayout>

功能代码实现

package com.ncsyeyy.YeyyNotificaton;import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.media.AudioManager;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;public class MyActivity extends Activity implements OnClickListener {private Button btn;/*** Called when the activity is first created.*/@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);findView();setOnClick();}private void findView(){btn = (Button) findViewById(R.id.btn);}private void setOnClick(){btn.setOnClickListener(this);}@Overridepublic void onClick(View v) {switch (v.getId()){case R.id.btn:sendNotification();break;}}private void sendNotification(){
//        得到系统的Notification服务对象NotificationManager manager=(NotificationManager)this.getSystemService(Context.NOTIFICATION_SERVICE);
//        创建一个Notification对象图标Notification notification=new Notification();
//        设置显示的Notification对象图标notification.icon=R.drawable.ic_launcher;
//        设置显示Notification对象的内容notification.tickerText="您有一条新的短信!";
//        设置显示Notification对象的声音模式notification.audioStreamType= AudioManager.ADJUST_LOWER;
//        定义单击Notification的事件IntentIntent intent=new Intent(this,MyActivity.class);PendingIntent pendingIntent=PendingIntent.getActivity(this,0,intent,PendingIntent.FLAG_ONE_SHOT);//        单击状态栏的图标出现的提示信息设置notification.setLatestEventInfo(this,"短信提示内容","我是一个短消息,愚人节快乐!",pendingIntent);
//        发送pendingIntent消息manager.notify(1,notification);}}

Notification数据下载的状态栏提示

思路:
第一:定义布局按钮
第二:定义消息通知的布局,进度条显示
第三:代码实现
监听按钮
得到NotificationManager的服务对象
初始化并得到Notification的视图对象,设置progressBar对象
定义单击通知事件。取消事件

第一:定义布局按钮

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical"android:layout_width="fill_parent"android:layout_height="fill_parent"><Buttonandroid:id="@+id/btnSend"android:layout_width="match_parent"android:layout_height="wrap_content"android:text="发送下载Notification"/><Buttonandroid:id="@+id/btnClean"android:layout_width="match_parent"android:layout_height="wrap_content"android:text="清除Notification"/>
</LinearLayout>

第二:定义消息通知的布局,进度条显示

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical"android:layout_width="match_parent"android:layout_height="match_parent"><!--定义通知布局的文本框--><TextViewandroid:id="@+id/tv"android:layout_width="wrap_content"android:layout_height="wrap_content"android:text="下载中……"android:textSize="20sp"android:textColor="@android:color/white"/><!--定义下载进度progressbar控件--><ProgressBarandroid:id="@+id/pb"style="?android:attr/progressBarStyleHorizontal"android:layout_width="260dp"android:layout_height="wrap_content"android:layout_gravity="center_vertical"/>
</LinearLayout>

第三:代码实现
监听按钮
得到NotificationManager的服务对象
初始化并得到Notification的视图对象,设置progressBar对象
定义单击通知事件。取消事件

package com.ncsyeyy.YeyyNotificationDownload;import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.RemoteViews;public class MyActivity extends Activity implements OnClickListener {
//    定义notification的idprivate int notification_id=1;
//    定义主线程的handlerprivate Handler handler=new Handler() ;
//    记录进度条进度private int count=0;
//    记录是否进度条取消private Boolean isclean=false;private Button btnSend;private Button btnClean;private NotificationManager nm;private Notification notification;/*** Called when the activity is first created.*/@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);findView();setClick();
//        得到NotificationManager的服务对象nm = (NotificationManager)getSystemService(NOTIFICATION_SERVICE);
//        初始化notification对象notification = new Notification(R.drawable.ic_launcher,"开始下载",System.currentTimeMillis());
//        得到Notification的视图对象notification.contentView=new RemoteViews(getPackageName(),R.layout.layout_notification);
//        设置视图中的ProgressBar对象notification.contentView.setProgressBar(R.id.pb,100,0,false);
//        定义单击通知事件Intent notificationIntent=new Intent(this,MyActivity.class);PendingIntent contentIntent= PendingIntent.getActivity(this,0,notificationIntent,0);notification.contentIntent=contentIntent;}private void findView(){btnSend = (Button) findViewById(R.id.btnSend);btnClean = (Button) findViewById(R.id.btnClean);}private void setClick(){btnSend.setOnClickListener(this);btnClean.setOnClickListener(this);}@Overridepublic void onClick(View v) {
//        自定义按钮单击监听器switch (v.getId()){case R.id.btnClean:
//                取消notificationnm.cancel(notification_id);isclean=true;break;case R.id.btnSend:
//                显示notificationshowNotification();handler.post(run);break;default:break;}}//    定义Runnable对象进行进度更新Runnable run=new Runnable() {@Overridepublic void run() {
//        判断通知是否被取消if (!isclean){
//            如果没有取消就进行进度的更新count++;notification.contentView.setProgressBar(R.id.pb,100,count,false);
//            200毫秒count加1if (count<100)handler.postDelayed(run,200);}}
};
//    显示notificationpublic void showNotification(){nm.notify(notification_id,notification);}
}

        

源码地址:http://download.csdn.net/detail/csdnyuandaimaxuexi/9214261

Notification 模拟收到短信,数据下载的状态栏提示相关推荐

  1. Android 系统(170)----收到短信,FM外放自动切回耳机

    收到短信,FM外放自动切回耳机 测试步骤: [步骤] 1.播放FM,声音选择扬声器播放 2.收到notification [结果] FM扬声器播放被关闭,声音转到耳机播放 [期望] 扬声器不应被关闭 ...

  2. hello python jpush_Python人脸识别 + 手机推送,老板来了你就会收到短信提示

    原标题:Python人脸识别 + 手机推送,老板来了你就会收到短信提示 前言 在你上班的时候刷知乎,看视频,玩手机的时候,老板来了!不用担心,不用着急,基于最新的人脸识别 + 手机推送做出的 Boss ...

  3. SQLite实现获取本机短信数据

    利用sqlite想要实现从本机获取短信的信息,我们就必须找到本机存储短信数据的位置 一.使用真机 打开studio -- Device-File-Explorer--data-data--com.an ...

  4. xposed伪造收到短信

    Android 4.4 之后,开发者不能直接往短信数据库添加短信了,只有系统默认的短信应用才能在收件箱中添加短信,除非将自己的应用设置为默认短信应用,当这种方法不太实用,因为没有那个用户愿意修改自己的 ...

  5. 安卓手机来电防火墙_手机号拉黑了能收到短信吗

    现在很多人把一些手机号码拉黑,以免受到电话或信息的骚扰,不过手机号拉黑了能收到短信吗?这里和大家简单介绍一下,供大家参考. 手机号拉黑了能收到短信吗 1.如果是苹果手机,则不能收到来电和短信息,也不会 ...

  6. 获取短信数据 并且备份

    配置权限 <uses-permission android:name="android.permission.READ_SMS" /><uses-permissi ...

  7. 手机短信验证码登录功能的开发实录(机器识别码、短信限流、错误提示、发送验证码倒计时60秒)

    短信验证码登录功能 项目分析 核心代码 1.外部js库调用 2.HTML容器构建 3.javaScript业务逻辑验证 4.后端验证逻辑 总结 短信验证码是通过发送验证码到手机的一种有效的验证码系统, ...

  8. 一个软件网络连接异常_飞鸽传书软件下载-飞鸽传书短信平台下载

    飞鸽传书是一款非常好用的.操作简单.便捷的互动界面,用户们可以在这里进行最方便的短信通信等,软件中,用户们还可以进行文件的快速的传输使用等,有需要的用户们就来下载吧~ 飞鸽传书介绍: 1.通过WiFi ...

  9. android 360短信拦截短信验证码,莫名收到短信验证码?360借条安全专家提醒小心新骗局...

    日常生活中,许多人在注册.登陆APP时往往都会选用短信验证码的方式来进行,这样不仅方便,也可以避免因为账号过多而遗忘登陆密码.然而,这样的方式却也成为不法分子眼中的漏洞,围绕短信验证码来展开的电信诈骗 ...

  10. 无法进入系统的三星Android手机恢复联系人、短信数据并重置手机的过程

    领导的一台双卡双待的Samsung Grand DUOS(i9082)联通合约手机前一阵子突然坏了,按开机键之后,显示Woo和三星商标,喊一句"欢迎进入Woo的世界",就开始在Wo ...

最新文章

  1. 浏览器加载、解析、渲染的过程
  2. 【工具软件】webstorm如何使用快捷键生成固定代码
  3. 11.6 java中jar包使用
  4. titit 切入一个领域的方法总结 attilax这里,机器学习为例子
  5. 华为鸿蒙系统电脑有那些,华为鸿蒙系统上线,仅2家国产品牌支持,爆冷?
  6. IDEA集成SVN插件及SVN使用 - 超详细
  7. 拉钩网前端项目实战01
  8. 中国与印度的GDP深层剖析
  9. Table is marked as crashed and should be repaire
  10. 文件压缩原理是什么?
  11. 怎么制作U盘启动盘来安装系统
  12. pip install时timeout设置
  13. java实现excel导入导出,对象图片读取,上传七牛云
  14. 袁宝华 oracle,关键词优化难易分析_SEO优化难度分析 - 站长工具
  15. 在git clone报错
  16. java poi打印excel_POI打印Excel报表
  17. const int,int const,const int*,int const*,int* const有什么不一样?
  18. python中list的意思_python中的list函数什么意思
  19. JSP同步请求和html+ajax异步请求的两种方式
  20. MIT6.S081操作系统实验——操作系统是如何在qemu虚拟机中启动的?

热门文章

  1. Mac 软件和学习经验分享
  2. 一切皆是映射:浅谈操作系统内核的缺页异常(Page Fault)
  3. 【2016.11.10】百度云离线下载迅雷链接
  4. 详谈PC端软件 - 加壳与脱壳
  5. 虚拟机服务器扩容,vmware虚拟机 ubuntu根目录磁盘扩容
  6. 【看看这长尾效应】长尾效应综述
  7. iOS - Safe iOS 加密安全
  8. panic recovered, err: runtime error: invalid memory address or nil pointer dereference 怎么排查问题
  9. 揭秘淘宝搜索量快速暴增的秘密
  10. 关于 Windows 设置tomcat开机自动启动