android点击通知栏之后消失,为什么noftifications出现在android通知栏中一段时间然后消失...
我正在使用BroadCastReceiver,其中接收BOOT_COMPLETED操作.收到此广播后,会设置AlarmManager,此AlarmManager会触发通知:
广播接收器的代码:
package pit.opensource.events;
import java.util.Calendar;
import android.app.AlarmManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;
public class BootReciver extends BroadcastReceiver {
Context c;
@Override
public void onReceive(Context context,Intent intent) {
// TODO Auto-generated method stub
// Intent i = new Intent(context,SetAlarmService.class);
// context.startService(i);
setAlarm(context);
Log.d("Alarm","Boot Reciver");
}
private void setAlarm(Context c){
Log.d("Alarm","Set alarm service--------------");
AlarmManager alarm = (AlarmManager)c.getSystemService(Service.ALARM_SERVICE);
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(System.currentTimeMillis());
cal.clear();
cal.set(2012,5,11,11);
Intent i = new Intent(c,ShowNotificationService.class);
PendingIntent pendingIntent = PendingIntent.getService(c,12345,i,0);
// alarm.set(AlarmManager.RTC_WAKEUP,dateNotif.getTime(),pendingIntent);
//alarm.set(AlarmManager.RTC_WAKEUP,cal.getTimeInMillis(),pendingIntent);
alarm.set(AlarmManager.RTC_WAKEUP,5000,pendingIntent);
Log.d("Alarm","Alarm is alreday set*****************");
}
}
ShowNotificationService的代码:
package pit.opensource.events;
import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.util.Log;
import android.widget.Toast;
public class ShowNotificationService extends Service {
@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
@Override
public void onStart(Intent intent,int startId){
Toast.makeText(getApplicationContext(),"Alaraaaaaaaam",Toast.LENGTH_LONG).show();
Log.d("Alarm","Notification Service");
showNotification();
}
private void showNotification(){
Intent i = new Intent(getApplicationContext(),DetailsActivity.class);
Toast.makeText(getApplicationContext(),"Dowanlod finished!",Toast.LENGTH_LONG).show();
int notificationID = 1;
NotificationManager nm = (NotificationManager) getSystemService(getApplicationContext().NOTIFICATION_SERVICE);
Log.d("Notification","Notification is set--------------------");
PendingIntent contentIntent = PendingIntent.getActivity(getApplicationContext(),0);
CharSequence tickerText = "Alaraaaaaaaam!";
long when = System.currentTimeMillis();
int icon = R.drawable.ic_launcher;
Notification notification = new Notification(icon,tickerText,when);
CharSequence contentTitle = "Alarm Alarm Alarm Alarm !!";
CharSequence contentText = "Please click here to display more details";
notification.setLatestEventInfo(getApplicationContext(),contentTitle,contentText,contentIntent);
//---100ms delay,vibrate for 250ms,pause for 100 ms and
// then vibrate for 500ms---
notification.vibrate = new long[] { 100,250,100,500}; // Needs vibrate permissions
nm.notify(notificationID,notification);
}
}
android点击通知栏之后消失,为什么noftifications出现在android通知栏中一段时间然后消失...相关推荐
- android通知 自动消失了,为什么通知会在android通知栏中显示一段时间然后消失
我正在使用BroadCastReceiver,接收BOOT_COMPLETED动作.收到此广播后,AlarmManager将被设置,并且此AlarmManager会触发通知: 广播接收者代码: pac ...
- 提示框一段时间以后消失setTimeout
<!DOCTYPE html> <html lang="en"> <head><meta charset="UTF-8" ...
- 使用JAVASCRIPT实现弹出框,过一段时间自动消失
分享一下我老师大神的人工智能教程!零基础,通俗易懂!http://blog.csdn.net/jiangjunshow 也欢迎大家转载本篇文章.分享知识,造福人民,实现我们中华民族伟大复兴! < ...
- android中点击空白处隐藏软键盘
在android中点击EditText的时候会弹出软键盘,这时候如果想隐藏软键盘或者填完内容后点其他的地方直接隐藏软键盘,可以按一下方法处理. 首先获得软键盘Manager InputMethodMa ...
- android 点击震动,Android 实现为点击事件添加震动效果
Android 点击Button 实现震动效果教程 Overview 在Android 的点击效果中,遇到震动效果的还是很多的. 接下来就让我们看一下如何实现震动效果. 所需要的权限 如果我们在开发中 ...
- android四种点击事件,android点击事件的四种方式
android点击事件的四种方式 第一种方式:创建内部类实现点击事件 代码如下: package com.example.dail; import android.text.TextUtils; im ...
- 可设置指定时间自动消失的 MessageBox实现
本文主要是讲如何实现可设置指定时间自动消失的 MessageBox提示框ShowMessageBoxTimeout实现: 在开发客户端应用程序的时候,经常用得WinForm中MessageBox提示框 ...
- android点击通知栏消失,手机通知栏不见了怎么办
手机通知栏不见了怎么办 手机通知栏不见了的情况大多出现在安卓的设备中,手机通知栏不见了的情况出现时,大家不要急于刷机操作,或许很多人以刷机来一答了之,其实手机通知栏不见了的问题很好解决,有其他方式重启 ...
- android开发之Intent.setFlags()_让Android点击通知栏信息后返回正在运行的程序
android开发之Intent.setFlags()_让Android点击通知栏信息后返回正在运行的程序 在应用里使用了后台服务,并且在通知栏推送了消息,希望点击这个消息回到activity, ...
最新文章
- 基于相交线的立体平面SLAM
- linux命名管道 c版本 python版本
- 韦老师的开发板和嵌入式书籍赠送
- win10更改mac地址
- 20-100-040-安装-Centos 7.5 安装MYSQL
- 美团的大数据产品,互联网的数字化转型,如何从0做到100?
- 得到进程id_GDB调试多进程程序
- 能识别nvme的pe启动_学用系列|Mathpix,送给理科老师们的公式识别神器
- 产品功能树图_新版PFMEA培训之第三步功能分析,理清结构,梳理思路
- Python:利用Entrez库筛选下载PubMed文献摘要
- 软件测试黑马程序员课后答案_(完整版)软件测试技术基础课后习题答案
- BIMC品牌整合营销:电子商务外包是中小企业未来发展方向
- Postgresql skip locked跳过行锁消除行锁冲突等待
- 利用PS的磁性套索工具进行抠图
- 过年了JAVA类编写烟花爆竹——学习分享下笔者的经验_文伟_新浪博客
- ESP32-IDF开发笔记 | 01 - ESP-IDF开发环境搭建(2023.04.08更新)
- 康耐视Visionpro-3D Tools 总览
- 3个5相乘列乘法算式_三年级下册期中数学17个考点专题复习资料
- linux 内核启动Initramfs与initrd 及其挂载
- linux ATT汇编 输出hello world
热门文章
- 给plt.axvline设置图例(label)
- python清空文件夹
- 将tensor转array
- python+OpenCV图像处理(二)图像像素的访问、通道的合并与分离
- 快速转 TypeScript 指南
- Windows10 下搭建汇编语言开发环境( 利用 DOSBOX 和 MASM32 )
- 华为鸿蒙麒麟玉兔_华为P50除了麒麟9000,还预装鸿蒙系统,比iPhone12值得买
- C++学习之路 | PTA乙级—— 1089 狼人杀-简单版(精简)
- vscode php断点,VSCode中设置断点调试PHP(示例代码)
- python的socket模块_python模块:socket模块