之前网上看了下自己定义消息栏,通知栏,了解到了Notification这个控件。发现UC浏览器等都是这样的类型,今天写个demo实现下。如图:

当中每一个button都有不同的功能。代码例如以下:

package com.example.textwsjdemo;

import android.app.Activity;

import android.app.Notification;

import android.app.NotificationManager;

import android.app.PendingIntent;

import android.content.BroadcastReceiver;

import android.content.Context;

import android.content.Intent;

import android.content.IntentFilter;

import android.os.Bundle;

import android.view.KeyEvent;

import android.view.View;

import android.view.View.OnClickListener;

import android.widget.Button;

import android.widget.RemoteViews;

import android.widget.Toast;

public class MainActivity extends Activity {

private Button bt_hehe;

private NotificationManager notificationManager;

private Notification notification;

private int icon;

private CharSequence tickerText;

private long when;

RemoteViews contentView;

private Intent intent;

private PendingIntent pendingIntent;

private int notification_id = 0;

private MyBroadCast receiver;

private static String ACTION = "a";

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

receiver = new MyBroadCast();

IntentFilter filter = new IntentFilter();

filter.addAction("a");

filter.addAction("b");

filter.addAction("c");

filter.addAction("d");

registerReceiver(receiver, filter);

initView();

initData();

}

private void initData() {

icon = R.drawable.ic_launcher; // 通知图标

tickerText = "Hello"; // 状态栏显示的通知文本提示

when = System.currentTimeMillis(); // 通知产生的时间,会在通知信息里显示

}

private void initView() {

bt_hehe = (Button) findViewById(R.id.bt_hehe);

bt_hehe.setOnClickListener(new OnClickListener() {

@Override

public void onClick(View v) {

// TODO Auto-generated method stub

// 启动提示栏

createNotification();

}

});

}

private void createNotification() {

notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

notification = new Notification();

notification.icon = icon;

notification.tickerText = tickerText;

notification.when = when;

/***

* 在这里我们用自定的view来显示Notification

*/

contentView = new RemoteViews(getPackageName(),

R.layout.notification_item);

contentView.setTextViewText(R.id.text11, "小说");

contentView.setTextViewText(R.id.text22, "视频");

contentView.setTextViewText(R.id.text33, "新闻");

contentView.setTextViewText(R.id.text44, "扯淡");

// contentView.setTextViewText(R.id.notificationPercent, "0%");

// contentView.setProgressBar(R.id.notificationProgress, 100, 0, false);

// //进度条

// contentView.setImageViewResource(R.id.image,R.drawable.more_advice);

// //载入图片

// contentView.setImageViewResource(R.id.image,R.drawable.more_attention);

// contentView.setImageViewResource(R.id.image,R.drawable.more_evaluate);

// contentView.setImageViewResource(R.id.image,R.drawable.more_about);

// contentView.setTextViewText(R.id.text,"Hello,this message is in a custom expanded view");

// //文本

notification.flags = Notification.FLAG_ONGOING_EVENT; // 设置常驻。不能滑动取消

//默认跳转的主界面

intent = new Intent(this, MainActivity.class);

intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);

pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);

//自己定义跳转

contentView.setOnClickPendingIntent(R.id.ll_11, PendingIntent.getBroadcast(MainActivity.this, 11, new Intent().setAction("a"), PendingIntent.FLAG_UPDATE_CURRENT));

contentView.setOnClickPendingIntent(R.id.ll_22, PendingIntent.getBroadcast(MainActivity.this, 11, new Intent().setAction("b"), PendingIntent.FLAG_UPDATE_CURRENT));

contentView.setOnClickPendingIntent(R.id.ll_33, PendingIntent.getBroadcast(MainActivity.this, 11, new Intent().setAction("c"), PendingIntent.FLAG_UPDATE_CURRENT));

contentView.setOnClickPendingIntent(R.id.ll_44, PendingIntent.getBroadcast(MainActivity.this, 11, new Intent().setAction("d"), PendingIntent.FLAG_UPDATE_CURRENT));

notification.contentView = contentView;

notification.contentIntent = pendingIntent;

notificationManager.notify(notification_id, notification);

}

// 取消通知

private void cancelNotification() {

notificationManager.cancelAll();

}

@Override

protected void onDestroy() {

cancelNotification();

unregisterReceiver(receiver);

}

@Override

public boolean onKeyDown(int keyCode, KeyEvent event) {

if ((keyCode == KeyEvent.KEYCODE_BACK)) {

System.out.println("按下了back键 onKeyDown()");

cancelNotification();

}

return super.onKeyDown(keyCode, event);

}

class MyBroadCast extends BroadcastReceiver {

@Override

public void onReceive(Context context, Intent intent) {

if(intent.getAction().equals("a")){

Toast.makeText(MainActivity.this, "11111111111111",

Toast.LENGTH_LONG).show();

startActivity(new Intent(MainActivity.this, ActivityText1.class));

}

if(intent.getAction().equals("b")){

Toast.makeText(MainActivity.this, "222222222222222",

Toast.LENGTH_LONG).show();

startActivity(new Intent(MainActivity.this, ActivityText2.class));

}

if(intent.getAction().equals("c")){

Toast.makeText(MainActivity.this, "333333333333",

Toast.LENGTH_LONG).show();

startActivity(new Intent(MainActivity.this, ActivityText3.class));

}

if(intent.getAction().equals("d")){

Toast.makeText(MainActivity.this, "4444444444444",

Toast.LENGTH_LONG).show();

startActivity(new Intent(MainActivity.this, ActivityText4.class));

}

}

}

}

下面是一些属性的设置:

/*

* 加入声音

* notification.defaults |=Notification.DEFAULT_SOUND;

* 或者使用下面几种方式

* notification.sound = Uri.parse("file:///sdcard/notification/ringer.mp3");

* notification.sound = Uri.withAppendedPath(Audio.Media.INTERNAL_CONTENT_URI, "6");

* 假设想要让声音持续反复直到用户对通知做出反应,则能够在notification的flags字段添加"FLAG_INSISTENT"

* 假设notification的defaults字段包含了"DEFAULT_SOUND"属性,则这个属性将覆盖sound字段中定义的声音

*/

/*

* 加入振动

* notification.defaults |= Notification.DEFAULT_VIBRATE;

* 或者能够定义自己的振动模式:

* long[] vibrate = {0,100,200,300}; //0毫秒后開始振动,振动100毫秒后停止,再过200毫秒后再次振动300毫秒

* notification.vibrate = vibrate;

* long数组能够定义成想要的不论什么长度

* 假设notification的defaults字段包含了"DEFAULT_VIBRATE",则这个属性将覆盖vibrate字段中定义的振动

*/

/*

* 加入LED灯提醒

* notification.defaults |= Notification.DEFAULT_LIGHTS;

* 或者能够自己的LED提醒模式:

* notification.ledARGB = 0xff00ff00;

* notification.ledOnMS = 300; //亮的时间

* notification.ledOffMS = 1000; //灭的时间

* notification.flags |= Notification.FLAG_SHOW_LIGHTS;

*/

/*

* 很多其它的特征属性

* notification.flags |= FLAG_AUTO_CANCEL; //在通知栏上点击此通知后自己主动清除此通知

* notification.flags |= FLAG_INSISTENT; //反复发出声音,直到用户响应此通知

* notification.flags |= FLAG_ONGOING_EVENT; //将此通知放到通知栏的"Ongoing"即"正在执行"组中

* notification.flags |= FLAG_NO_CLEAR; //表明在点击了通知栏中的"清除通知"后。此通知不清除,

* //常常与FLAG_ONGOING_EVENT一起使用

* notification.number = 1; //number字段表示此通知代表的当前事件数量,它将覆盖在状态栏图标的顶部

* //假设要使用此字段,必须从1開始

* notification.iconLevel = ; //

*/

android获取通知栏消息源代码,Android高仿UC浏览器和360手机卫士消息常驻栏(通知栏)(示例代码)...相关推荐

  1. android 360状态栏显示,Android高仿UC浏览器和360手机卫士消息常驻栏(通知栏)

    之前网上看了下自定义消息栏,通知栏,了解到了Notification这个控件,发现UC浏览器等都是这种类型,今天写个demo实现下,如图: 其中每个按钮都有不同的功能,代码如下: package co ...

  2. android项目uc浏览器,Android项目仿UC浏览器和360手机卫士消息常驻栏(通知栏)

    之前网上看了下自定义消息栏,通知栏,了解到了Notification这个控件,发现UC浏览器等都是这种类型,今天写个demo实现下,如图: 其中每个按钮都有不同的功能,代码如下: package co ...

  3. android 高仿UC浏览器首页上拉面板效果

    最近在项目中,产品经理看见uc浏览器首页的上拉面板的效果做的非常不错,于是希望我们的项目的首页也做成这样的效果.于是经过思考后,实现了一个仿uc浏览器的上拉面板效果. 接下来说一下实现的思路吧 . 首 ...

  4. 一款非常不错的高仿UC浏览器源码下载

    今天给大家分享一款非常不错的android源码,这是我刚刚在网上找到的源码,高仿UC浏览器源码下载,希望大家能够喜欢. 源码下载: http://code.662p.com/view/1634.htm ...

  5. 360 android系统 流量,360手机卫士Android版增流量监控

    2011-3-15 10:52 [天极网IT新闻频道]目前,随着Android手机系统大热,低价智能手机越来越普及,而智能机最大的特点就是软件丰富和可随时随地可以上网.地铁里发微博,看新闻甚至看视频都 ...

  6. 360 android系统 流量,警惕天价流量费 360手机卫士Android版增流量监控

    目前,随着Android手机系统大热,低价智能手机越来越普及,而智能机最大的特点就是软件丰富和可随时随地可以上网.地铁里发微博,看新闻甚至看视频都成为很多朋友的一大爱好.但是,也有不少初次使用智能手机 ...

  7. android 今日头条加载动画,高仿今日头条加载动画

    01 每每浏览手机app时,发现有的效果体验不错,作为一位程序员,总想要是自己来做,怎么实现. 今天我们来模仿今日头条的加载动画. 首先我们来看一下我们这个demo最终效果,有图有真相. 高仿今日头条 ...

  8. 高仿360手机卫士——Android源码

    高仿360手机卫士 高仿360手机卫士界面android源码,左右滑动效果,超炫. 下载地址:http://www.devstore.cn/code/info/1173.html 运行截图:    热 ...

  9. Android桌面悬浮窗效果实现,仿360手机卫士悬浮窗效果

    转载自:http://blog.csdn.net/guolin_blog/article/details/8689140 大家好,今天给大家带来一个仿360手机卫士悬浮窗效果的教程,在开始之前请允许我 ...

最新文章

  1. [OS复习]操作系统综述1
  2. 儒林外史每回概括简短10字_早安心语正能量经典短句 一句话的简短励志语录
  3. 设计灵感|电商美工,年年都能借鉴的新年
  4. vue router children 路由变了 组件没变_Vue.js从零开始——路由(2)
  5. vSAN架构解析与6.7功能介绍
  6. 【linux】sed -e 's/-//g'
  7. PHP 解决session 死锁
  8. 食堂饭卡管理系统C语言——课程设计实习
  9. 转载:EditPlus下载安装及使用
  10. [Linux]CentOS修改YUM镜像地址提高下载速度
  11. 编写Shell脚本实现用户管理
  12. 更新 TKK 失败,请检查网络连接 报错处理
  13. 验证码爬取并识别-云大urp教务系统大作战(1)
  14. 设计分享|基于单片机电子密码锁(汇编)
  15. WatchGuard Firebox X50硬件防火墙
  16. Skleran-线性模型-最小角回归(LARS)
  17. 恭喜EDG 夺得冠军
  18. 想要入行web前端要知道web前端的的基本工作职责
  19. 【2016-05-09】程序员的日常:咖啡
  20. BUU CTF刷题之旅(Web第一页)

热门文章

  1. 3D人体姿态估计综述 - 《3D Human pose estimation: A review of the literature and analysis of covariates》
  2. SpringBoot整合RPC框架---Thrift
  3. 高速公路发展趋势,智慧高速公路解决方案
  4. 数据分析,主成分分析例题
  5. MySQL面试2:一张学生表,一张教师表,里面都有Name和Code,写出张三的老师有多少名学生的SQL语句。
  6. 瑞萨RH850 FCL库的使用
  7. CVTE硬件岗面试经历
  8. 雷曼兄弟:次贷中的又一大“牺牲品”
  9. 没有足够的内存继续执行程序.(mscorlib)
  10. 侧重于讲述前端的网站开发流程