Android开发之Notification
2015-06-25 10:55
417 查看
package com.linxiaosheng.pro6127; import android.annotation.SuppressLint; import android.app.Activity; import android.app.Notification; import android.app.Notification.Builder; import android.app.NotificationManager; import android.app.PendingIntent; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; @SuppressLint("NewApi") public class Pro6127_3_2 extends Activity{ private Button button1; private Button button2; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.pro6127_3_2); button1=(Button)findViewById(R.id.button1); button2=(Button)findViewById(R.id.button2); button1.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub sendNotification(); } }); button2.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // TODO Auto-generated method stub removeNotification(); } }); } public void sendNotification(){ Builder builder=new Builder(this); builder.setSmallIcon(R.drawable.ic_launcher); builder.setTicker("hello"); builder.setWhen(System.currentTimeMillis()); builder.setContentTitle("通知"); builder.setContentText("通知栏"); builder.setDefaults(Notification.DEFAULT_ALL); Intent intent=new Intent(this,Pro6127_3_2.class); PendingIntent pendingIntent=PendingIntent.getActivity(this, 0, intent, 0); builder.setContentIntent(pendingIntent); NotificationManager manager=(NotificationManager) getSystemService(NOTIFICATION_SERVICE); Notification notification=builder.build(); manager.notify(1, notification); } public void removeNotification(){ NotificationManager manager=(NotificationManager) getSystemService(NOTIFICATION_SERVICE); manager.cancel(1); } }
相关文章推荐
- android 读取properties文件
- android 左滑显示删除按钮SwipeMenuListView
- Android外部存储设备状态
- Android 调用系统相机以及相册源码
- 2: mac 下真机调试 android 手机
- Android使用Handler造成的内存泄露问题的解决
- Mac Android开发1:MAC中设置android adb环境变量
- Android中notifyDataSetInvalidated()和notifyDataSetChanged()有什么区别
- Android开源项目分类汇总
- android ListView中item中两个重叠view,一个显示另一个隐藏的方法
- android 自定义弹出框Dialog
- 【Android】滑动屏幕效果GestureDetector、OnGestureListener、ViewFlipper
- Android 使用Scroller实现绚丽的ListView左右滑动删除Item效果
- Android笔记:百度地图与高德地图坐标转换问题
- Android之断点续传下载
- Android Design Support Library使用详解
- Android字体Font相关知识
- android 安装新的sdk后,R文件不会自动生成问题
- android 保存bitmap到SD卡
- android 压缩图片尺寸