SHARE
TWEET

Untitled

a guest Jun 16th, 2019 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. private void startAlarm(Calendar c) {
  2.         AlarmManager alarmManager = (AlarmManager) getContext().getSystemService(Context.ALARM_SERVICE);
  3.         Intent intent = new Intent(getContext(), AlarmReceiver.class);
  4.         PendingIntent pendingIntent = PendingIntent.getBroadcast(getContext(), 0, intent, 0);
  5.         alarmManager.set(AlarmManager.RTC_WAKEUP, c.getTimeInMillis(), pendingIntent);
  6.     }
  7.      
  8. mSaveAssessBtn.setOnClickListener(new View.OnClickListener() {
  9.             @Override
  10.                 public void onClick(View v) {
  11.                 if (mSetAlert.isChecked()) {
  12.                     Calendar c = Calendar.getInstance();
  13.                     c.setTime(mAssessment.getGoalDate());
  14.                     startAlarm(c);
  15.                 }
  16.                 mAssessment.setAssessType(assessmentType);
  17.                 Intent myIntent = new Intent(getActivity(), AssessmentListActivity.class);
  18.                 startActivity(myIntent);
  19.             }
  20.         });
  21.      
  22. private void startAlarm2(Calendar c2) {
  23.         AlarmManager alarmManager2 = (AlarmManager) getContext().getSystemService(Context.ALARM_SERVICE);
  24.         Intent intent2 = new Intent(getContext(), AlarmReceiver.class);
  25.         PendingIntent pendingIntent2 = PendingIntent.getBroadcast(getContext(), 0, intent2, 0);
  26.         alarmManager2.set(AlarmManager.RTC_WAKEUP, c2.getTimeInMillis(), pendingIntent2);
  27.     }
  28.      
  29. submitStatusBtn.setOnClickListener(new View.OnClickListener() {
  30.                 @Override
  31.                 public void onClick(View v) {
  32.                     Calendar c2 = Calendar.getInstance();
  33.                     c2.setTime(mCourse.getStartDate());
  34.                     startAlarm2(c2);
  35.                     mCourse.setTitle(mTitleField.getText().toString());
  36.                     mCourse.setCourseStatus(mCourseStatus.getText().toString());
  37.                     //mCourse.setCourseStatus(radioButton.getText().toString());
  38.                     mCourse.setCourseNote(mOptonalNote.getText().toString());
  39.                     mCourse.setCourseMentorName(mMentorName.getText().toString());
  40.                     mCourse.setCourseMentorPhone(mMentorPhone.getText().toString());
  41.                     mCourse.setCourseMentorEmail(mMentorEmail.getText().toString());
  42.                     Intent myIntent = new Intent(getActivity(), CourseListActivity.class);
  43.                     startActivity(myIntent);
  44.                 }
  45.             });
  46.      
  47. public class AlarmReceiver extends BroadcastReceiver {
  48.  
  49.     @Override
  50.     public void onReceive(Context context, Intent intent) {
  51.         //first notification AssessmentFragment
  52.         NotificationHelper notificationHelper = new NotificationHelper(context);
  53.         NotificationCompat.Builder nb = notificationHelper.getChannelNotification();
  54.         notificationHelper.getManager().notify(0, nb.build());
  55.         //second notification CourseFragment
  56.         NotificationHelper2 notificationHelper2 = new NotificationHelper2(context);
  57.         NotificationCompat.Builder nb2 = notificationHelper2.getChannelNotification();
  58.         notificationHelper2.getManager().notify(1, nb2.build());
  59.     }
  60. }
  61.      
  62. public NotificationCompat.Builder getChannelNotification() {
  63.         return new NotificationCompat.Builder(getApplicationContext(), channelID)
  64.                 .setContentTitle("Assessment Goal today!")
  65.                 .setContentText("Your assessment Goal Date is today!")
  66.                 .setSmallIcon(R.drawable.alert);
  67.     }
  68.      
  69. public NotificationCompat.Builder getChannelNotification() {
  70.         return new NotificationCompat.Builder(getApplicationContext(), channelID2)
  71.                 .setContentTitle("Course Starts today!")
  72.                 .setContentText("Your Course Start Date is today!")
  73.                 .setSmallIcon(R.drawable.alert);
  74.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top