MobileReceiver.java
public class MobileReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
if(intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)){
Intent myIntent = new Intent();
myIntent.setAction("android.intent.service.TASKSERVICE");
context.startService(myIntent);
}
}
}
ToDoTaskService.java
public class ToDoTaskService extends Service {
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public void onCreate() {
Intent intent = new Intent(this, ToDoTaskActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setAction("android.intent.action.TASK");
if(MainActivity.m_NotificationManager == null){
MainActivity.m_NotificationManager = (NotificationManager)this.getSystemService(Context.NOTIFICATION_SERVICE);
}
MainActivity.setNotiActivity(MainActivity.taskName, MainActivity.TO_DO_TASK,android.R.drawable.presence_online, "您有代办任务...", "您有3个未审批任务...", intent, this.getApplicationContext(), false);
super.onCreate();
}
}
<receiver android:name=".receiver.MobileReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"></action>
</intent-filter>
</receiver>
<service android:enabled="true" android:name=".service.ToDoTaskService">
<intent-filter>
<action android:name="android.intent.service.TASKSERVICE"></action>
</intent-filter>
</service>
public static void setNotiActivity(String str,int nID,int iconId, String info ,String content,Class<? extends Activity> activity,Context context, boolean sound){
Intent notifyIntent = new Intent(context,activity);
notifyIntent.setFlags( Intent.FLAG_ACTIVITY_SINGLE_TOP);
setNotiActivity(str,nID,iconId,info,content,notifyIntent,context,sound);
}
public static void setNotiActivity(String str,int nID,int iconId, String info ,String content,Intent intent,Context context, boolean sound){
PendingIntent appIntent=PendingIntent.getActivity(context,0,intent,0);
setNotiType(str,nID,iconId,info,content,appIntent,context,sound);
}
public static void setNotiService(String str,int nID,int iconId, String info ,String content,Intent intent,Context context, boolean sound){
PendingIntent appIntent=PendingIntent.getService(context,0,intent,0);
setNotiType(str,nID,iconId,info,content,appIntent,context,sound);
}
public static void removeNoti(String str,int nID){
m_NotificationManager.cancel(str, nID);
}
public static void setNotiType(String str,int nID,int iconId, String info ,String content,PendingIntent appIntent , Context context, boolean sound){
Notification myNoti=new Notification();
//禁止用户清除通知
myNoti.flags = Notification.FLAG_NO_CLEAR;
myNoti.icon=iconId;
myNoti.tickerText=content;
if(sound){
myNoti.defaults=Notification.DEFAULT_SOUND;
}
myNoti.setLatestEventInfo(context,info,content,appIntent);
m_NotificationManager.notify(str,nID,myNoti);
}
分享到:
相关推荐
android service Notification ...安装的服务开机自启动,service定时的打印消息,消息同时显示在通知栏,窗体界面的跳转,自定义控件的开发。系统广播,定时广播,轮询广播等。BroadcastReceiver轮询广播
以下为程序启动流程: 1.开机启动AlarmService 2.AlarmActivity一秒后发送一条系统广播 ...5.单击消息,取消通知栏信息 6.但程序关闭时,单击消息,重启程序 小知识:BroadCast、Service、Notification,初学者适用
6.13 指定时间置换桌面背景——多AlarmManager事件处理 6.14 判断发送短信后的状态——BroadcastReceiver聆听PendingIntent 6.15 后台服务送出广播信息——sendBroadcast与BroadcastReceiver 6.16 开机程序设计——...
2.2.3 service介绍 2.2.4 broadcastintentreceiver 2.2.5 contentprovider 2.3 android应用项目文件组成 2.3.1 androidmanifest.xml文件 2.3.2 src目录 2.3.3 常量的定义文件 2.4 程序生命周期 2.4.1 android周期 ...
5.8 状态栏的图标与文字提醒——NotificationManager与Notification对象的应用 5.9 搜索手机通讯录自动完成——使用ContentResolver 5.10 取得联系人资料——Provider.Contact的使用 5.11 制作有图标的文件资源管理...
5.8 状态栏的图标与文字提醒——NotificationManager与Notification对象的应用 5.9 搜索手机通讯录自动完成——使用ContentResolver 5.10 取得联系人资料——Provider.Contact的使用 5.11 制作有图标的文件资源管理...
5.8 状态栏的图标与文字提醒——NotificationManager与Notification对象的应用 5.9 搜索手机通讯录自动完成——使用ContentResolver 5.10 取得联系人资料——Provider.Contact的使用 5.11 制作有图标的文件资源管理...
5.8 状态栏的图标与文字提醒——NotificationManager与Notification对象的应用-p178 5.9 搜索手机通讯录自动完成——使用ContentResolver-p82 5.10 取得联系人资料——Provider.Contact的使用 5.11 制作有图标的文件...
5.8 状态栏的图标与文字提醒——NotificationManager与Notification对象的应用 5.9 搜索手机通讯录自动完成——使用ContentResolver 5.10 取得联系人资料——Provider.Contact的使用 5.11 制作有图标的文件资源...
Web Service存取服务:内嵌网页浏览器、Ajax网页特效、手机气象局、网络播放mp3、网络安装apk程序、远程下载手机铃声、XML-RPC移动博客发布器、手机RSS阅读器、地震速报、网页快照等。 完备的Google网络服务:Google...
Web Service存取服务:内嵌网页浏览器、Ajax网页特效、手机气象局、网络播放mp3、网络安装apk程序、远程下载手机铃声、XML-RPC移动博客发布器、手机RSS阅读器、地震速报、网页快照等。 完备的Google网络服务:Google...
5.8 状态栏的图标与文字提醒——NotificationManager与Notification对象的应用-p178 5.9 搜索手机通讯录自动完成——使用ContentResolver-p82 5.10 取得联系人资料——Provider.Contact的使用 5.11 制作有图标的文件...
5.8 状态栏的图标与文字提醒——NotificationManager与Notification对象的应用-p178 5.9 搜索手机通讯录自动完成——使用ContentResolver-p82 5.10 取得联系人资料——Provider.Contact的使用 5.11 制作有图标的文件...
5.8 状态栏的图标与文字提醒——NotificationManager与Notification对象的应用-p178 5.9 搜索手机通讯录自动完成——使用ContentResolver-p82 5.10 取得联系人资料——Provider.Contact的使用 5.11 制作有图标的文件...
Web Service存取服务:内嵌网页浏览器、Ajax网页特效、手机气象局、网络播放mp3、网络安装apk程序、远程下载手机铃声、XML-RPC移动博客发布器、手机RSS阅读器、地震速报、网页快照等。 完备的Google网络服务:Google...
Web Service存取服务:内嵌网页浏览器、Ajax网页特效、手机气象局、网络播放mp3、网络安装apk程序、远程下载手机铃声、XML-RPC移动博客发布器、手机RSS阅读器、地震速报、网页快照等。 完备的Google网络服务:Google...