第八章 通知的使用
来源:互联网 发布:线性优化模型 编辑:程序博客网 时间:2024/06/05 15:41
主页面点击一按钮发送通知,通知显示在状态栏上,点开状态栏,跳到通知的页面,并且通知在状态栏消失
public class MainActivity extends ActionBarActivity implements View.OnClickListener { private Button btnSendNotification; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); btnSendNotification = (Button) findViewById(R.id.btn_send_notification); btnSendNotification.setOnClickListener(this); } @Override public void onClick(View v) { switch (v.getId()) { case R.id.btn_send_notification: NotificationManager manager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); Notification notification = new Notification(R.mipmap.ic_launcher, "This is tickeText", System.currentTimeMillis()); Intent intent = new Intent(MainActivity.this, NotificationActivity.class); PendingIntent pendingIntent = PendingIntent.getActivity(MainActivity.this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); notification.setLatestEventInfo(MainActivity.this, "This is content title", "This is content text", pendingIntent); manager.notify(1, notification); break; } }}布局就一个按钮,下面通知的代码,看取消通知,用cancle(id)来取消
public class NotificationActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_notification_text); NotificationManager manger = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE); manger.cancel(1); }}
通知的高级使用
//振动设置long[] vibrate = {0, 1000, 1000, 1000};notification.vibrate = vibrate;//Led灯光提示notification.ledARGB = Color.RED;notification.ledOnMS=1000;notification.ledOffMS = 1000;notification.flags = Notification.FLAG_SHOW_LIGHTS;//声音提示Uri soundUri = Uri.fromFile(new File("/system/media/audio/ringtones/Basic_tone.ogg"));notification.sound = soundUri;//默认提示notification.defaults = Notification.DEFAULT_ALL;
0 0
- 第八章 通知的使用
- 《第一行代码》第八章 通知的使用(NotificationTest)
- 《第一行代码》第八章 通知的高级技巧
- 第八章—对话框、通知(一)
- android通知的使用
- Android 通知的使用
- 通知的简单使用
- 通知机制的使用
- 通知的使用
- 本地通知的使用
- 通知中心的使用
- 通知的使用
- IOS通知的使用
- ios 通知的使用
- NSNotification通知的使用
- 通知的使用
- iOS通知的使用
- NSNotificationCenter 通知的使用
- 解决matplotlib中文乱码问题
- HDFS追本溯源:租约,读写过程的容错处理及NN的主要数据结构
- iOS面试题五
- windows资源管理(内核对象/GDI对象/user对象)
- [HDU 2926]I Speak Whales[递归][划分]
- 第八章 通知的使用
- c++第1次实验-2
- Java之——将 jsonObject 转换成 对象
- iOS面试题六
- Android事件处理之基于监听的事件处理
- 重整晋商雄风,再现汇通天下 -------《晋商》阅读笔记第5-6章
- 追根溯源---length、length()和size()
- MTK问题总结-----工作中遇到的
- iOS面试题八