Android_通知(Notification)
来源:互联网 发布:天心软件和金蝶软件 编辑:程序博客网 时间:2024/06/05 23:56
通知:显示在手机的通知栏上
通知的基本用法:
1 创建一个NotificationManager 对通知进行管理
NotificationManager manager =
(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
2 创建Notification
Notification notification = new NOtification
(R.drawable.icon,”This is tiket text”,System.currentTimeMills());
3 对通知的布局进行设定
notification.
setLatestEventInfo(context,”This is Title”,”This is content”,null);
4 让通知显示出来 ,第一个参数为一个任意id
manager.notify(1,notification);
案例: public class MianActivity extends Activity implements OnClickListener{ protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); Button sendNotice = (Button)findViewById(R.id.send_button); sendNotice.setOnClickListener(this); } @Override public void onClick(View v) { // TODO Auto-generated method stub switch(v.getId()){ case R.id.send_button: //创建通知管理器 NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); //创建通知对象 Notification notification = new Notification(R.drawable.ic_launcher, "This is ticker text", System.currentTimeMillis()); Intent intent = new Intent(MianActivity.this,NotificationActivity.class); //相当于通知中的Intent,点击通知就会传送至NotificationActivity.class PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); notification.setLatestEventInfo(this, "This is the Title", "This is the Text", pendingIntent); //高级功能 //声音 Uri soundUri = Uri.fromFile(new File("/system/media/audio/ringtones/nubia_mile.ogg")); notification.sound=soundUri; //震动 long[] vibrates = {0,1000,1000,1000}; notification.vibrate=vibrates; //颜色 notification.ledARGB=Color.GREEN; notification.ledOnMS=1000; notification.ledOffMS=1000; notification.flags=Notification.FLAG_SHOW_LIGHTS; //默认声音led 震动 颜色效果// notification.defaults=Notification.DEFAULT_ALL; notificationManager.notify(1,notification); break; default: break; } }}
public class NotificationActivity extends Activity { protected void onCreate(Bundle savedInstanceState){ super.onCreate(savedInstanceState); setContentView(R.layout.notification_layout); NotificationManager notificationManager = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); notificationManager.cancel(1); //notificationManager.notify(1,notification); }}
0 0
- Android_通知(Notification)
- android_自定义notification
- Android_基础 Notification
- Notification通知
- Notification通知
- Notification(通知)
- Notification通知
- Notification通知
- notification通知
- Notification 通知
- 通知(Notification)
- Notification通知
- 通知notification
- 通知Notification
- 通知 ------- Notification
- 通知Notification
- Notification--通知
- Notification通知
- 用Workbench迁移MySQL小数据库
- 定制bootstrap的按钮btn-primary
- cassandra 监控方案评估
- php.ini配置文件详解
- 频繁改动下的回归测试
- Android_通知(Notification)
- JS全局变量与局部变量的理解
- Java图形界面开发—简易登录注册小程序
- 【Struts2】:Interceptor实战之权限控制
- 汇编学习(九)8086汇编拾遗 (8)
- SDNUOJ1014
- 互联网安全(一)摘要认证
- 项目上线有感
- python 小概念日常总结