Notification的一些简单的设置和简单的用法
2015-08-14 16:17
288 查看
关于通知的一些简单的设置和方法介绍
import android.os.Bundle;
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.graphics.Color;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
/**
*
* @项目名:NotificationTest_demo1
* @类名称:MainActivity
* @类描述:通知基本方法
* @创建人:HXF
* @修改人:
* @创建时间:2015-8-13 上午10:20:04
* @version
*
*/
public class MainActivity extends Activity implements OnClickListener {
}
实现点击通知的界面的跳转,并且取消通知栏中的通知。
import android.app.Activity;
import android.app.NotificationManager;
import android.os.Bundle;
public class NotificationActivity extends Activity{
}
MainActivity中的布局
import android.os.Bundle;
import android.app.Activity;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Intent;
import android.graphics.Color;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.widget.Button;
/**
*
* @项目名:NotificationTest_demo1
* @类名称:MainActivity
* @类描述:通知基本方法
* @创建人:HXF
* @修改人:
* @创建时间:2015-8-13 上午10:20:04
* @version
*
*/
public class MainActivity extends Activity implements OnClickListener {
private Button sendNotice; private NotificationManager manager; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); setContentView(R.layout.activity_main); sendNotice = (Button) findViewById(R.id.send_notice); sendNotice.setOnClickListener(this); } @SuppressWarnings("deprecation") @Override public void onClick(View v) { switch (v.getId()) { case R.id.send_notice: manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); Notification notification = new Notification( R.drawable.ic_launcher, "这是Notification通知", System.currentTimeMillis()); /** 实现通知能被点击并跳转界面 */ Intent intent = new Intent(this,NotificationActivity.class); PendingIntent pi = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); long[] vibrate = {0,1000,1000,1000}; /** 发送通知的让手机震动的时间设置 */ notification.vibrate = vibrate; /** 可以设置通知来的时候有LED提示灯显示亮度 */ notification.ledARGB = Color.GREEN; notification.ledOnMS = 1000; notification.ledOffMS = 1000; notification.flags = Notification.FLAG_SHOW_LIGHTS; /** 一行搞定所有以上繁琐工作(设置声音,设置震动,设置LED光亮) */ notification.defaults = Notification.DEFAULT_ALL; notification.setLatestEventInfo(this, "这是Notification通知标题", "这是Notification通知内容", pi); /** 1代表id,可供后面取消的时候使用 */ manager.notify(1, notification); break; default: break; } }
}
实现点击通知的界面的跳转,并且取消通知栏中的通知。
import android.app.Activity;
import android.app.NotificationManager;
import android.os.Bundle;
public class NotificationActivity extends Activity{
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.notification_layout); /** 这边取消通知栏的通知,实在被跳转的界面*/ NotificationManager manager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); /** 1代表id,这里传入1是要取消MainActivity方法中的发出的那个通知 */ manager.cancel(1); }
}
MainActivity中的布局
相关文章推荐
- width:100%
- rsync安装部署
- SEAndroid的各种策略文件
- AC自动机算法
- Android Fragment 真正的完全解析(下)
- ICP算法与RANSAC算法描述
- POJ 1094-Sorting It All Out(拓扑排序)
- 设计模式之 工厂模式
- javaweb学习总结(十)——HttpServletRequest对象(一)
- SpringMVC Controller 介绍
- hdu 1848 博弈
- 网贷系统架构——前端框架的选择
- JS 对象(Object)和字符串(String)互转
- HDU 2222
- LayoutInflater作用及使用
- 根据已知的日期获取星期
- 图结构练习——最小生成树
- STM32的USART DMA传输(转)
- UIButton的发现
- Stars(树状数组或线段树)