Combine Value From DatePicker and TimePicker? working With Alarm

April 07, 2016 , 0 Comments

Set Globally Calender Intance.

Calendar calendar = Calendar.getInstance();


Call Date Picker =======>

public void callDatePicker(final EditText edt) {
Calendar cal = Calendar.getInstance();
int day = cal.get(Calendar.DAY_OF_MONTH);
int month = cal.get(Calendar.MONTH);
int year = cal.get(Calendar.YEAR);

DatePickerDialog dpd = new DatePickerDialog(MyTodoActivity.this, new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker datePicker, int year, int monthOfYear, int dayOfMonth) {
selectedDate = new Date(year, monthOfYear, dayOfMonth);
SimpleDateFormat dateFormatter = new SimpleDateFormat("MMMM-dd");
calendar.set(Calendar.MONTH, monthOfYear);
calendar.set(Calendar.DAY_OF_MONTH, dayOfMonth);
calendar.set(Calendar.YEAR, year);

String strDate = dateFormatter.format(selectedDate);


}
}, year, month, day);

dpd.show();
}

TimePicker ====>

public void callTimePicker(final EditText edt) {
final Calendar c = Calendar.getInstance();
Log.i("result", "=>first" + c.getTimeInMillis());
int mHour = c.get(Calendar.HOUR_OF_DAY);
int mMinute = c.get(Calendar.MINUTE);

TimePickerDialog tpd = new TimePickerDialog(MyTodoActivity.this,
new TimePickerDialog.OnTimeSetListener() {

@Override
public void onTimeSet(TimePicker view, int hourOfDay,
int minute) {

calendar.set(Calendar.HOUR_OF_DAY, hourOfDay);
calendar.set(Calendar.MINUTE, minute);
long startTime = calendar.getTimeInMillis();
Log.i("result", "=>Selected" + calendar.getTime() + "-" + calendar.get(Calendar.HOUR_OF_DAY) + "--" +
calendar.get(Calendar.MINUTE) + "---" + calendar.get(Calendar.DAY_OF_MONTH) + "--" + calendar.get(Calendar.MONTH));
Log.i("result", "=>Selected" + startTime + "=>Current" + new Date().getTime());

scheduleNotification(getNotification(title_txt.getText().toString(), description_txt.getText().toString()), startTime);

}
}, mHour, mMinute, false);
tpd.show();

}

Notification Schedual Time ===>

private void scheduleNotification(Notification notification, long futureInMilli) {

Intent notificationIntent = new Intent(this, NotificationPublisher.class);
notificationIntent.putExtra(NotificationPublisher.NOTIFICATION_ID, 1);
notificationIntent.putExtra(NotificationPublisher.NOTIFICATION, notification);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
// long futureInMillis = SystemClock.elapsedRealtime() + delay;
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP, futureInMilli, pendingIntent);
}

Create Notification Method it return to notification object ==>

private Notification getNotification(String title, String content) {
Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);

Notification.Builder builder = new Notification.Builder(this);
builder.setContentTitle(title);
builder.setContentText(content);
builder.setSmallIcon(R.drawable.appicon);
builder.setSound(soundUri);
builder.setVibrate(new long[]{1000, 1000, 1000, 1000, 1000});
builder.setLights(Color.RED, 3000, 3000);

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
return builder.build();
} else {
return builder.build();
}

}

Contributer

Some say he’s half man half fish, others say he’s more of a seventy/thirty split. Either way he’s a fishy bastard. Google

0 comments:

Hot-product

Best Watch Store

Popular Posts

Contact Form

Name

Email *

Message *