通过此代码从用户创建时间并从数据库中存储和检索,但它显示用户上次输入时间的通知
MainActivity
DBhelp dbHeleper= new DBhelp(getApplicationContext());
SQLiteDatabase db=dbHeleper.getReadableDatabase();
String querString="select hours,minutes FROM Time";
Cursor cursor=db.rawQuery(querString, null);
hours=new String[cursor.getCount()];
minutes=new String[cursor.getCount()];
if(cursor.getCount()>0){
int i=0;
while(cursor.moveToNext()){
hours[i]=cursor.getString(0);
minutes[i]=cursor.getString(1);
i++;
}
}
cursor.close();
db.close();
dbHeleper.close();
btnSaveNotification=(Button)findViewById(R.id.button1);
btnSaveNotification.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent myIntent = new Intent(ShowNotificationSetTime.this, MyReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(ShowNotificationSetTime.this,1, myIntent,0);
AlarmManager alarmManager = (AlarmManager)getSystemService(ALARM_SERVICE);
alarmManager.setRepeating(AlarmManager.RTC, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingIntent);
finish();
}
});
小时得到时间格式,如14,15,16和分钟20,30,40
我的广播接收课
public class MyReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent)
{
Intent service1 = new Intent(context, MyAlarmService.class);
context.startService(service1);
}
}
服务类..
NotificationManager mManager =(NotificationManager)getApplicationContext().getSystemService(getApplicationContext().NOTIFICATION_SERVICE);
Intent intent1 = new Intent(getApplicationContext(),DialogBoxNotification.class);
intent1.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP| Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingNotificationIntent = PendingIntent.getActivity( getApplicationContext(),1, intent1,PendingIntent.FLAG_UPDATE_CURRENT);
Notification notification = new Notification(R.drawable.ic_launcher,"msg.", System.currentTimeMillis());
notification.defaults |= Notification.DEFAULT_SOUND;
notification.setLatestEventInfo(getApplicationContext(),"title","msg", pendingNotificationIntent);
mManager.notify(1, notification);
mManager.notify(0, notification);