发布《学习计划》android应用
2012-05-16 18:07
260 查看
本应用具有如下功能:
新增学习计划,设置计划开始时间,结束时间。一起到达计划开始时间,系统会自动提醒。
批量删除学习计划
设置提醒方式,振动或声音或闪亮等
原理:
1 .在新加计划时,设置提醒时间,到时后转到AlarmBroadReceiver类,核心代码如下:
Intent intent = new Intent(context, AlarmReceiver.class);
Bundle bundle = new Bundle();
bundle.putString("info", planEntity.getContent());
bundle.putInt("id", planEntity.getId());
intent.putExtras(bundle);
//PendingIntent这个类用于处理即将发生的事情
////通过getBroadcast第二个参数区分闹钟,将查询得到的ID值作为第二个参数。
PendingIntent pIntent = PendingIntent.getBroadcast(context, planEntity.getId(), intent, 0);
AlarmManager am = (AlarmManager) context.getSystemService(Activity.ALARM_SERVICE);
Date selectedDate = DateUtils.parseString(planEntity.getStartDate(), "yyyy-MM-dd HH:mm");
am.set(AlarmManager.RTC_WAKEUP, selectedDate.getTime(), pIntent);
2.并将计划id和提醒时间保存到数据库,为了在开机重启,重新设置提醒
BootBroadcastReceiver
public class BootBroadcastReceiver extends BroadcastReceiver {
public static final LogContext LCTX = PlanLogContext.ROOT.lctx(BootBroadcastReceiver.class);
@Override
public void onReceive(Context context, Intent intent) {
if(intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)){
IPlanDao planDao=DaoFactory.getInstance().getDaoInstance(PlanDaoImpl.class);
List<AlarmEntity> result =planDao.queryAlarmRecords();
if(CollectionUtils.isEmpty(result)){
return;
}
for(AlarmEntity alarmEntity : result){
PlanEntity planEntity=planDao.queryPlanDataById(alarmEntity.getPlanId());
//重新记录闹钟
AlarmHelper.recordAlarm(context, planEntity);
LCTX.d("rerecord alarm . id = " + alarmEntity.getPlanId() +",alarmTime = "+ new Date(alarmEntity.getAlarmTime()));
}
}
}
}
3. 到提醒时间后,弹出notifictaion 信息
AlarmReceiver
ic void onReceive(Context context, Intent intent) {
// 获取传递的信息
Bundle bundle = intent.getExtras();
String info = bundle.getString("info");
int planId = bundle.getInt("id");
NotificationManager notiManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
// 定义Notification的各种属性
int icon = R.drawable.icon; // 通知图标
CharSequence tickerText = info; // 状态栏显示的通知文本提示
long when = System.currentTimeMillis(); // 通知产生的时间,会在通知信息里显示
// 用上面的属性初始化Nofification
Notification notification = new Notification(icon, tickerText, when);
String selectedAlarmType = PreferencesUtils.getStringPreference(context, "config", "alarmType", "");
if (selectedAlarmType.equals(context.getString(R.string.alarmTye_sound))) {
//notification.defaults |= Notification.DEFAULT_SOUND;
//notification.sound = Uri.parse("file:///sdcard/notification/ringer.mp3");
notification.sound = Uri.withAppendedPath(Audio.Media.INTERNAL_CONTENT_URI, "6");
}
else if (selectedAlarmType.equals(context.getString(R.string.alarmTye_vibrate))) {
//notification.defaults |= Notification.DEFAULT_VIBRATE;
long[] vibrate = {0,100,200,300};
notification.vibrate = vibrate;
}
else if (selectedAlarmType.equals(context.getString(R.string.alarmTye_light))) {
//notification.defaults |= Notification.DEFAULT_LIGHTS;
notification.ledARGB = 0xff00ff00;
notification.ledOnMS = 300;
notification.ledOffMS = 1000;
notification.flags |= Notification.FLAG_SHOW_LIGHTS;
}else{
notification.defaults = Notification.DEFAULT_SOUND;
}
// 设置提示框的状态
notification.flags = Notification.FLAG_AUTO_CANCEL; // //在通知栏上点击此通知后自动清除此通知
Intent intentTarget = new Intent(context, PlanMainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent contentIntent = PendingIntent.getActivity(context, planId, intentTarget,
PendingIntent.FLAG_UPDATE_CURRENT);
notification.setLatestEventInfo(context, "计划开始提醒" + planId, info, contentIntent);
notiManager.notify(planId, notification);
DaoFactory.getInstance().getDaoInstance(PlanDaoImpl.class).deleteAlarmRecord(planId);
界面:
应用下载地址:http://download.csdn.net/detail/pengchua/4312844
新增学习计划,设置计划开始时间,结束时间。一起到达计划开始时间,系统会自动提醒。
批量删除学习计划
设置提醒方式,振动或声音或闪亮等
原理:
1 .在新加计划时,设置提醒时间,到时后转到AlarmBroadReceiver类,核心代码如下:
Intent intent = new Intent(context, AlarmReceiver.class);
Bundle bundle = new Bundle();
bundle.putString("info", planEntity.getContent());
bundle.putInt("id", planEntity.getId());
intent.putExtras(bundle);
//PendingIntent这个类用于处理即将发生的事情
////通过getBroadcast第二个参数区分闹钟,将查询得到的ID值作为第二个参数。
PendingIntent pIntent = PendingIntent.getBroadcast(context, planEntity.getId(), intent, 0);
AlarmManager am = (AlarmManager) context.getSystemService(Activity.ALARM_SERVICE);
Date selectedDate = DateUtils.parseString(planEntity.getStartDate(), "yyyy-MM-dd HH:mm");
am.set(AlarmManager.RTC_WAKEUP, selectedDate.getTime(), pIntent);
2.并将计划id和提醒时间保存到数据库,为了在开机重启,重新设置提醒
BootBroadcastReceiver
public class BootBroadcastReceiver extends BroadcastReceiver {
public static final LogContext LCTX = PlanLogContext.ROOT.lctx(BootBroadcastReceiver.class);
@Override
public void onReceive(Context context, Intent intent) {
if(intent.getAction().equals(Intent.ACTION_BOOT_COMPLETED)){
IPlanDao planDao=DaoFactory.getInstance().getDaoInstance(PlanDaoImpl.class);
List<AlarmEntity> result =planDao.queryAlarmRecords();
if(CollectionUtils.isEmpty(result)){
return;
}
for(AlarmEntity alarmEntity : result){
PlanEntity planEntity=planDao.queryPlanDataById(alarmEntity.getPlanId());
//重新记录闹钟
AlarmHelper.recordAlarm(context, planEntity);
LCTX.d("rerecord alarm . id = " + alarmEntity.getPlanId() +",alarmTime = "+ new Date(alarmEntity.getAlarmTime()));
}
}
}
}
3. 到提醒时间后,弹出notifictaion 信息
AlarmReceiver
ic void onReceive(Context context, Intent intent) {
// 获取传递的信息
Bundle bundle = intent.getExtras();
String info = bundle.getString("info");
int planId = bundle.getInt("id");
NotificationManager notiManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
// 定义Notification的各种属性
int icon = R.drawable.icon; // 通知图标
CharSequence tickerText = info; // 状态栏显示的通知文本提示
long when = System.currentTimeMillis(); // 通知产生的时间,会在通知信息里显示
// 用上面的属性初始化Nofification
Notification notification = new Notification(icon, tickerText, when);
String selectedAlarmType = PreferencesUtils.getStringPreference(context, "config", "alarmType", "");
if (selectedAlarmType.equals(context.getString(R.string.alarmTye_sound))) {
//notification.defaults |= Notification.DEFAULT_SOUND;
//notification.sound = Uri.parse("file:///sdcard/notification/ringer.mp3");
notification.sound = Uri.withAppendedPath(Audio.Media.INTERNAL_CONTENT_URI, "6");
}
else if (selectedAlarmType.equals(context.getString(R.string.alarmTye_vibrate))) {
//notification.defaults |= Notification.DEFAULT_VIBRATE;
long[] vibrate = {0,100,200,300};
notification.vibrate = vibrate;
}
else if (selectedAlarmType.equals(context.getString(R.string.alarmTye_light))) {
//notification.defaults |= Notification.DEFAULT_LIGHTS;
notification.ledARGB = 0xff00ff00;
notification.ledOnMS = 300;
notification.ledOffMS = 1000;
notification.flags |= Notification.FLAG_SHOW_LIGHTS;
}else{
notification.defaults = Notification.DEFAULT_SOUND;
}
// 设置提示框的状态
notification.flags = Notification.FLAG_AUTO_CANCEL; // //在通知栏上点击此通知后自动清除此通知
Intent intentTarget = new Intent(context, PlanMainActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
PendingIntent contentIntent = PendingIntent.getActivity(context, planId, intentTarget,
PendingIntent.FLAG_UPDATE_CURRENT);
notification.setLatestEventInfo(context, "计划开始提醒" + planId, info, contentIntent);
notiManager.notify(planId, notification);
DaoFactory.getInstance().getDaoInstance(PlanDaoImpl.class).deleteAlarmRecord(planId);
界面:
应用下载地址:http://download.csdn.net/detail/pengchua/4312844
相关文章推荐
- 脚本ANT自动打包Android应用(方便多渠道发布)
- android轻松管理安卓应用中的log日志 发布应用时log日志全部去掉的方法
- Android应用市场发布经验总结
- 发布 Android 应用-攻略
- Android应用发布市场平台
- unity3d项目文件目录发布后,对应的ios/android应用目录
- Android Gradle 相同应用多包名打包,实现测试发布包分离,不同服务器地址以生成不同安装包
- 索尼即将针对iPhone, Android发布官方应用
- Android 发布应用到市场
- Google发布Android应用外观模板网站
- Android学习系列(34)--App应用之发布各广告平台版本
- 如何发布打包并发布自己的Android应用(APP)
- 华为权威发布国内首份千款主流应用Android P版本兼容性测试报告
- Android安卓应用发布平台汇总
- 发布 Android 应用-攻略
- Unity3D项目文件目录发布后对应的ios/android应用目录
- Android应用市场和发布流程参考
- Android申请google开发者账号并发布应用市场流程
- 如何发布android应用
- [Android应用]《幽默笑话》V2.0 正式版震撼发布!