- 浏览: 507580 次
- 性别:
- 来自: 广州
文章分类
最新评论
-
lin_kk:
最近正在学,请问LZ有源码事例吗,如果有能发一下我邮箱吗,万分 ...
使用libgdx及其中的box2d 2.1的注意事项 -
ahong520:
编译都通不过
ffmpeg对音频解码的一般步骤 -
辽东小小:
yajun_soft 写道XXX@XXX:~$ adb she ...
adb push的Permission denied -
cdtdx:
好文, 相当不错啊. 收了.
什么是app2sd,app2ext,data2ext?app移动到SD卡哪里去了? /mnt/asec /mnt/secure -
dickycat:
学习了,最近正在学这一块,年纪大了,学起来有点吃亏!
使用libgdx及其中的box2d 2.1的注意事项
Notification是通知单的意思,在windows中任务栏右边的系统状态栏就经常会弹出一个”气泡”,这个气泡就和android中Notification中是一样的概念。这种Notification 模式经常被应用在系统运行一些后台程序,当需要通知或提示前台一些信息的场景。比如在windows中,开机时如果防火墙是关闭状态,系统会在任务栏右边弹出一个“气泡”提示用户:防火墙未开启,如果点击那个气泡则会弹出防火墙设置菜单。在Android中也差不多是这样处理的,不过它有个更好的功能就是:将所有的Notification保存在列表中,当你点击列表中的条目时,系统就会启用这个条目相关的Notification中的Intent,然后切换Intent定义的Activity。而且Android中的Notification还允许用户可以定义它出现时伴随着手机闪烁、震动或铃声。 Notification的主要用途是给后台程序通知前台一些信息,或者要求前台做一些选择响应。使用Notification系统会在屏幕的上方的状态栏上显示提示信息,就在这里: 当系统有出现Notification时,用户可以通过将屏幕上方的状态栏往下拉的方式看到所有的Notification信息: 我们看看如何使用Notification。首先由上面的图我们可以发现,Notification只是整个NotificationManger的一部分,一个NotificationManager里可以有多个Notification,所以先要获取NotificationManager对象,使用它来管理Notification。 NotificationManager跟LayoutInflater一样是系统的service,所以你不需要创建它,而是调用Activity.getSystemService来获取: 获取之后就需要创建Notification了,并配置它的属性: 上面创建一个Notification,配置它的icon,显示内容和弹出Notification的时间。接着你需要定义一个当你点击Notification时需要启用的intent: 配置完Intent后,就将这个配置完的Intent与Notification关联,然后将Notification提交给NotificationManager,让其弹出Notification: 综上代码我们总结出创建Notification需要下面几个步骤: 现在我们写一个测试例子,测试弹出Notification,因为它需要intent来弹出一个Activity,所以我们先定义一个Activity: 然后在AndroidMenifest.xml文件中声明这个Activity: NotificationDemoActivity.java: 当点击TextView时: 我们可以看到在系统的状态栏上显示了一条信息,将状态栏往下拉动时可以看到: 当系统接收到多个Notification时,在状态栏上会上下滚动的显示这些Notification。NotificationManager为每个Notification赋上一个id值: 所以每个Notification都是独立的。你还可以更新Notification在状态栏的显示信息和它本身的信息,因为它们都有一个唯一的id值,只要你notifiy一个存在的id值,那么原来的Notification就被修改成新的Notification,达到了更新的效果。 这样做总比添加一个新的Notification好,节省了内容空间和NotificationManager的显示空间。 你可以修改Notification的很多配置如控制它的提示音、震动频率和显示效果。 1. 修改提示音: 2. 修改震动频率: 上面的vibrate中的数值是ms值,数组表示的是震动和等待时间的交替间隔,如上面数组的意思是:等待0ms,震动100ms,等待200ms,震动300ms。 3. LED屏 闪光效果: 上面代码中的ledARGB是指LED闪的光的颜色,用ARGB表示,ledOnMS是指闪光持续多少ms,上面为例是持续300ms,同理ledOffMS是指关掉闪光的时间,最后那行是开启闪光效果。上面三种控制效果都可以使用默认值: Notification中的flags还提供了其他有用的功能: Notification被选中(点击)就消失,即一点击执行内部的PendingIntent后就从NotificationManager中移除。 Notification持续重复提示音,直到用户做出响应。(除非情况紧急,否则别用这个吧,都烦死用户了。) 提示用户这个Notification的应用正在运行,比如后台音乐播放。 指示这个Notification不能被clear,这个一般用在“FLAG_ONGOING_EVENT”,因为“FLAG_ONGOING_EVENT”持续运行在后台,所以不能被clear掉。 默认Notification由一个icon、一个title和contentText三个区域组成,但是它支持自定义布局,在这边它使用的是RemoteView。我们创建一个RemoteView对象,然后将它赋给Notification.contentView,然后配置它的Intent,最后由NotificationManager通过notify将其显示出来。 custom_notification_layout.xml:
String ns = Context.NOTIFICATION_SERVICE;
NotificationManager mNotificationManager = (NotificationManager) getSystemService(ns);
int
icon = R.drawable.notification_icon;
CharSequence tickerText =
"Hello"
;
long
when = System.currentTimeMillis();
Notification notification =
new
Notification(icon, tickerText, when);
Intent notificationIntent =
new
Intent(
this
, MyClass.
class
);
PendingIntent contentIntent = PendingIntent.getActivity(
this
,
0
, notificationIntent,
0
);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
package
com.android777.demo.uicontroller;
import
android.app.Activity;
import
android.os.Bundle;
import
android.view.View;
import
android.widget.Button;
import
android.widget.CheckBox;
import
android.widget.ImageButton;
import
android.widget.RadioButton;
import
android.widget.Toast;
import
android.widget.ToggleButton;
public
class
ButtonActivity
extends
Activity {
@Override
protected
void
onCreate(Bundle savedInstanceState) {
super
.onCreate(savedInstanceState);
setContentView(R.layout.button);
Button btn = (Button) findViewById(R.id.button1);
btn.setOnClickListener(
new
View.OnClickListener() {
@Override
public
void
onClick(View v) {
Toast.makeText(ButtonActivity.
this
,
"Button点击事件"
, Toast.LENGTH_LONG).show();
}
});
}
}
<?
xml
version
=
"1.0"
encoding
=
"utf-8"
?>
<
manifest
xmlns:android
=
"http://schemas.android.com/apk/res/android"
package
=
"com.android777.demo.uicontroller"
android:versionCode
=
"1"
android:versionName
=
"1.0"
>
<
application
android:icon
=
"@drawable/icon"
android:label
=
"@string/app_name"
>
<
activity
android:name
=
".notification.NotificationDemoActivity"
android:label
=
"@string/app_name"
>
<
intent-filter
>
<
action
android:name
=
"android.intent.action.MAIN"
/>
<
category
android:name
=
"android.intent.category.LAUNCHER"
/>
</
intent-filter
>
</
activity
>
<
activity
android:name
=
".ButtonActivity"
/>
</
application
>
</
manifest
>
package
com.android777.demo.uicontroller.notification;
import
com.android777.demo.uicontroller.ButtonActivity;
import
com.android777.demo.uicontroller.R;
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.os.Bundle;
import
android.view.View;
import
android.view.View.OnClickListener;
import
android.view.ViewGroup.LayoutParams;
import
android.widget.Button;
import
android.widget.TextView;
public
class
NotificationDemoActivity
extends
Activity
implements
OnClickListener{
private
final
int
NOTIFY_ID =
1
;
@Override
protected
void
onCreate(Bundle savedInstanceState) {
super
.onCreate(savedInstanceState);
TextView btn =
new
TextView(
this
);
btn.setText(
"点击我显示Notification"
);
btn.setLayoutParams(
new
LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
setContentView(btn);
btn.setOnClickListener(
this
);
}
@Override
public
void
onClick(View v) {
//1.获取NotificationManager对象
NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
//2.创建Notification,配置它的属性
Notification n =
new
Notification();
n.icon = R.drawable.icon ;
//配置icon
n.tickerText =
"这是显示在状态的信息"
;
n.when = System.currentTimeMillis() ;
//创建点击Notification时 启用的intent
Intent intent =
new
Intent(
this
, ButtonActivity.
class
);
PendingIntent pendingIntent = PendingIntent.getActivity(
this
,
0
,
//requestCode
intent,
0
);
//flags
//将创建的PendingIntent 配置到Notification中
n.setLatestEventInfo(
this
,
"这个是标题"
,
"这是显示的内容"
, pendingIntent);
//将之前配置的Notification提交给NotificationManager,显示出来
nm.notify(NOTIFY_ID, n);
}
}
nm.notify(NOTIFY_ID, n);
notification.sound = Uri.parse(
"file:///sdcard/notification/ringer.mp3"
);
long
[] vibrate = {
0
,
100
,
200
,
300
};
notification.vibrate = vibrate;
notification.ledARGB =
0xff00ff00
;
notification.ledOnMS =
300
;
notification.ledOffMS =
1000
;
notification.flags |= Notification.FLAG_SHOW_LIGHTS;
notification.defaults |= Notification.DEFAULT_LIGHTS;
notification.defaults |= Notification.DEFAULT_VIBRATE;
notification.defaults |= Notification.DEFAULT_SOUND;
notification.flags |= Notification.FLAG_AUTO_CANCEL;
notification.flags |= Notification.FLAG_INSISTENT;
notification.flags |= Notification.FLAG_ONGOING_EVENT;
notification.flags |= Notification.FLAG_NO_CLEAR;
在Notification中创建自定义的View视图
<
LinearLayout
xmlns:android
=
"http://schemas.android.com/apk/res/android"
android:orientation
=
"horizontal"
android:layout_width
=
"fill_parent"
android:layout_height
=
"fill_parent"
android:padding
=
"3dp"
>
<
ImageView
android:id
=
"@+id/image"
android:layout_width
=
"wrap_content"
android:layout_height
=
"fill_parent"
android:layout_marginRight
=
"10dp"
/>
<
TextView
android:id
=
"@+id/text"
android:layout_width
=
"wrap_content"
android:layout_height
=
"fill_parent"
android:textColor
=
"#000"
/>
</
LinearLayout
>
//设置View
RemoteViews contentView =
new
RemoteViews(getPackageName(), R.layout.custom_notification_layout);
contentView.setImageViewResource(R.id.image, R.drawable.notification_image);
contentView.setTextViewText(R.id.text,
"Hello, this message is in a custom expanded view"
);
notification.contentView = contentView;
//设置Intent
Intent notificationIntent =
new
Intent(
this
, MyClass.
class
);
PendingIntent contentIntent = PendingIntent.getActivity(
this
,
0
, notificationIntent,
0
);
notification.contentIntent = contentIntent;
//弹出Notification
mNotificationManager.notify(CUSTOM_VIEW_ID, notification);
发表评论
-
编译XT720 gingerbread
2013-05-04 11:18 826在android根目录下执行". build/env ... -
编译mx 内核成功
2013-03-18 17:48 826转 : http://hi.baidu.com/_xi ... -
ubuntu下面找不到ZTE V880设备
2012-12-06 16:22 784两种方法:第一种方法是你连上你的手机,重启电脑,再adb de ... -
Android中解决图像解码导致的OOM问题
2012-10-01 18:41 796http://7dot9.com/2011/08/androi ... -
编译Android下纯C的静态程序,undefined reference to raise
2012-07-08 23:28 2336尝试在Android下编译纯C的静态程序,执行gcc -v - ... -
开发Android下纯C程序时,打开时提示not found
2012-07-08 20:09 1342这个问题烦了我一天了..郁闷.本人想试验一下使用ndk里面的t ... -
NDK报错:make: *** 没有规则可以创建“obj/local/armeabi/objs/a/a.o”需要的目标“/a.c”。 停止。
2012-07-05 21:02 2144android开发用ndk编译so库时,有时直接从别的地 ... -
adb push的Permission denied
2012-05-30 17:19 3577遇到的问题是 zhanglanyun@zhanglan ... -
adb pull失败问题解决方法
2012-05-30 17:03 2115问题:使用adb pull命令从android系统中读取文件失 ... -
关于app2sd、a2sd、data2sd、a2sd+的区别的解释
2012-05-17 11:47 1031因为看到很多机友对这个概念不理解。首先解释一下这些缩写,全部的 ... -
什么是app2sd,app2ext,data2ext?app移动到SD卡哪里去了? /mnt/asec /mnt/secure
2012-05-17 10:56 3326Google Android手机的软件为了安全性和稳定性 ... -
android 如何自定义ProgressBar
2012-04-22 15:39 1896原文:http://blog.sina.com.cn/s/bl ... -
修改MAC,没有nvs_map.bin时该怎么做
2012-04-10 16:53 1783Basically: nvs_map.bin is what ... -
Android Activity LaunchMode 验证
2012-03-31 11:23 876在Android中,每个Activity有4种LaunchMo ... -
Android改变MAC地址
2012-03-30 13:42 21451.Find out your original MAC ad ... -
C通过JNI 层调用Java的静态和非静态方法
2012-03-26 09:47 39181、主要流程 1、 新建一个测试类TestProv ... -
使用ndk或linux下独立交叉编译(ffmpeg)
2012-03-18 21:48 22711、ndk 编译程序 在NDK的apps目录下创建he ... -
android-ndk-r7 编译 ffmpeg-0.10
2012-03-18 21:46 4564看了这篇文章 http://blog.sina.com ... -
android2.3 MODIFY_PHONE_STATE
2012-02-27 22:14 3033一直被一些莫名其妙的电话骚扰,而且只响两声就断了,一直 ... -
Androidmanifest.xml里的<uses-feature>
2011-12-27 17:10 1319如果你是一个Android用户,而且你有一个老旧的安装有and ...
相关推荐
安卓通知栏实现,通过 NotificationManager实现管理 notification ,包括 发送通知和 取消通知;
使用RemoteView发送通知栏信息,模拟下载进度,可暂停、继续
当app让系统发送一个消息的时候,消息首先以图表的形式显示在通知栏。要查看消息的详情需要进入通知抽屉(notificationdrawer)中查看。通知栏和通知抽屉(notificationdrawer)都是系统层面控制的,你可以随时查看,不...
而NotificationManager则是用于发送Notification通知的系统服务。 使用Notification和NotificationManager类发送和显示通知也比较简单,大致可分为以下4个步骤。 (1)调用getSystemService()方法获取系统的...
Android中实现发送状态栏通知案例
以下为程序启动流程: 1.开机启动AlarmService 2.AlarmActivity一秒后发送一条系统广播 ...5.单击消息,取消通知栏信息 6.但程序关闭时,单击消息,重启程序 小知识:BroadCast、Service、Notification,初学者适用
其中,Notification代表的是具有全局效果的通知,而NotificationManager则是用于发送Notification通知的系统服务。 使用Notification和NotificationManager类发送和显示通知也比较简单,大致可以分为以下四个步骤 (1...
Android Notification通知 简单使用 demo下载。 解决问题:兼容高低版本,帮助用户打开通知开关,android5.x手机状态栏icon是白块问题。 详细文章请参考 ...
当app让系统发送一个消息的时候,消息首先以图表的形式显示在通知栏。要查看消息的详情需要进入通知抽屉(notificationdrawer)中查看。(notificationdrawer)都是系统层面控制的,你可以随时查看,不限制于app。 ...
实现三种通知状态栏的方式
这样一个通知就发送成功了,通知栏上也会显示出SmallIcon图标,之后是进行点击通知进行下载处理,首先Notification发送一个Broadcast广播,但是广播里面不能做耗时操作,所以在广播里开启一个Service服务,通过在...
本篇文章主要介绍了android使用NotificationListenerService监听通知栏消息,具有一定的参考价值,感兴趣的小伙伴们可以参考一下。
Notifications(通知栏学习),就是安卓软件,发送通知栏消息的demo
点击界面中心的“点击发送消息”TextView控件,模拟发送通知消息,通知栏接收消息,点击几次则发送几次,点击通知栏消息,跳转到详情界面。 1.activity_main.xml: <LinearLayout xmlns:android=...
2.发送notification的application的icon或者发送者的image。 3.notification的message 4.notification的数目显示 5.当main icon用来显示sender’s image时 Secondary icon用来显示发送application的icon。 6.时间戳...
首先,发送一个状态栏通知必须用到两个类: NotificationManager 、 Notification。 NotificationManager : 是状态栏通知的管理类,负责发通知、清楚通知等。 NotificationManager 是一个系统Service,必须通过 ...
首先,发送一个状态栏通知必须用到两个类:NotificationManager、Notification。 NotificationManager:是状态栏通知的管理类,负责发通知、清楚通知等。 NotificationManager是一个系统Service,必须通过...
js chrome Notification 在windows任务栏上显示消息框
背景知识:可以用Activity和Service来开始消息通知,两者的区别在于一个是在前台触发,一个是...效果 :代码: 代码如下://消息通知栏 //定义NotificationManager String ns = Context.NOTIFICATION_SERVICE; Noti
如果将通知发送到多个组件,则它们的状态将在这些组件之间同步。 因此,取消一个组件中的通知将触发其他组件中的取消事件。演示版此存储库中也提供了示例代码。本地通知全局通知公告板通知远端编程指南