BroadcastReceiver是抽象类,需要自定义一个类来继承它。该类自身不实现图形用户界面,生命周期一般只有10秒以内,通过重写onReceive()方法判断所收到的intent的action是否等于在AndroidManifest.xml中receiver设置的intentfliter所设定的action,成立的话,进行显示(消息处理代码,不能超过10s)。
也可以不使用AndroidManifest.xml中设置的intentfliter所设定的action,而是在新建一个继承Activity的BatteryActivity的java类,在设置好setContentView和创建一个按键后,在单击事件监听器内,用registerReceiver(new BatteryReceiver(),new IntentFilter(Intent.ACTION_BATTERY_CHANGED))注册IntentFilter。【这里的Battery是举例说明。。】
Notification用于下拉状态栏的通知。
Notification 的使用需要导入 3 个类
1
2
3
|
import
android.app.PendingIntent;
import
android.app.NotificationManager;
import
android.app.Notification;
|
代码示例及说明
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
NotificationManager nm = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
Notification n =
new
Notification(R.drawable.chat,
"Hell
|