Commit d8480377 authored by RAUSHAN RAJ's avatar RAUSHAN RAJ

[Raushan] - alarm working

parent 0d1b3b42
...@@ -53,6 +53,7 @@ dependencies { ...@@ -53,6 +53,7 @@ dependencies {
// Lombok Dependencies // Lombok Dependencies
compileOnly 'org.projectlombok:lombok:1.18.10' compileOnly 'org.projectlombok:lombok:1.18.10'
annotationProcessor 'org.projectlombok:lombok:1.18.10' annotationProcessor 'org.projectlombok:lombok:1.18.10'
implementation 'org.jetbrains:annotations-java5:15.0'
// add the Firebase SDK Dependencies // add the Firebase SDK Dependencies
// implementation 'com.google.firebase:firebase-analytics:17.2.0' // implementation 'com.google.firebase:firebase-analytics:17.2.0'
......
...@@ -53,6 +53,9 @@ ...@@ -53,6 +53,9 @@
<action android:name="android.intent.action.BOOT_COMPLETED"/> <action android:name="android.intent.action.BOOT_COMPLETED"/>
</intent-filter> </intent-filter>
</receiver> </receiver>
<service
android:name=".AlarmService"
android:enabled="true" />
</application> </application>
......
...@@ -41,9 +41,9 @@ public class AlarmReceiver extends BroadcastReceiver { ...@@ -41,9 +41,9 @@ public class AlarmReceiver extends BroadcastReceiver {
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
int mReceivedID = Integer.parseInt(intent.getStringExtra(ReminderEditActivity.EXTRA_REMINDER_ID)); int mReceivedID = Integer.parseInt(intent.getStringExtra(ReminderEditActivity.EXTRA_REMINDER_ID));
//
// Get notification title from Reminder Database //Get notification title from Reminder Database
ReminderDatabase rb = new ReminderDatabase(context); ReminderDatabase rb = new ReminderDatabase(context);
Reminder reminder = rb.getReminder(mReceivedID); Reminder reminder = rb.getReminder(mReceivedID);
String mTitle = reminder.getTitle(); String mTitle = reminder.getTitle();
...@@ -53,20 +53,23 @@ public class AlarmReceiver extends BroadcastReceiver { ...@@ -53,20 +53,23 @@ public class AlarmReceiver extends BroadcastReceiver {
editIntent.putExtra(ReminderEditActivity.EXTRA_REMINDER_ID, Integer.toString(mReceivedID)); editIntent.putExtra(ReminderEditActivity.EXTRA_REMINDER_ID, Integer.toString(mReceivedID));
PendingIntent mClick = PendingIntent.getActivity(context, mReceivedID, editIntent, PendingIntent.FLAG_UPDATE_CURRENT); PendingIntent mClick = PendingIntent.getActivity(context, mReceivedID, editIntent, PendingIntent.FLAG_UPDATE_CURRENT);
// Create Notification // // Create Notification
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context) // NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context,"MyChannelId_01")
.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher)) // .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher))
.setSmallIcon(R.drawable.ic_alarm_on_white_24dp) // .setSmallIcon(R.drawable.ic_alarm_on_white_24dp)
.setContentTitle(context.getResources().getString(R.string.app_name)) // .setContentTitle(context.getResources().getString(R.string.app_name))
.setTicker(mTitle) // .setTicker(mTitle)
.setContentText(mTitle) // .setContentText(mTitle)
.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION)) // .setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
.setContentIntent(mClick) // .setContentIntent(mClick)
.setAutoCancel(true) // .setAutoCancel(true)
.setOnlyAlertOnce(true); // .setOnlyAlertOnce(true);
//
NotificationManager nManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); // NotificationManager nManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
nManager.notify(mReceivedID, mBuilder.build()); // nManager.notify(mReceivedID, mBuilder.build());
NotificationHelper notificationHelper = new NotificationHelper(context,intent);
NotificationCompat.Builder nb = notificationHelper.getChannelNotification();
notificationHelper.getManager().notify(mReceivedID, nb.build());
} }
public void setAlarm(Context context, Calendar calendar, int ID) { public void setAlarm(Context context, Calendar calendar, int ID) {
......
package com.blanyal.remindme;
//package com.example.application.alarmmanagerproject;
import androidx.core.app.NotificationCompat;
import android.annotation.TargetApi;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.ContextWrapper;
import android.content.Intent;
import android.os.Build;
import android.graphics.BitmapFactory;
import android.media.RingtoneManager;
public class NotificationHelper extends ContextWrapper {
public static final String channelID = "channelID";
public static final String channelName = "Channel Name";
String mTitle;
PendingIntent mClick;
private NotificationManager mManager;
public NotificationHelper(Context base,Intent intent) {
super(base);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
createChannel();
}
int mReceivedID = Integer.parseInt(intent.getStringExtra(ReminderEditActivity.EXTRA_REMINDER_ID));
//
//Get notification title from Reminder Database
ReminderDatabase rb = new ReminderDatabase(base);
Reminder reminder = rb.getReminder(mReceivedID);
mTitle = reminder.getTitle();
// Create intent to open ReminderEditActivity on notification click
Intent editIntent = new Intent(base, ReminderEditActivity.class);
editIntent.putExtra(ReminderEditActivity.EXTRA_REMINDER_ID, Integer.toString(mReceivedID));
mClick = PendingIntent.getActivity(base, mReceivedID, editIntent, PendingIntent.FLAG_UPDATE_CURRENT);
}
@TargetApi(Build.VERSION_CODES.O)
private void createChannel() {
NotificationChannel channel = new NotificationChannel(channelID, channelName, NotificationManager.IMPORTANCE_HIGH);
getManager().createNotificationChannel(channel);
}
public NotificationManager getManager() {
if (mManager == null) {
mManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
}
return mManager;
}
public NotificationCompat.Builder getChannelNotification() {
return new NotificationCompat.Builder(getApplicationContext(), channelID)
.setLargeIcon(BitmapFactory.decodeResource(getApplicationContext().getResources(), R.mipmap.ic_launcher))
.setSmallIcon(R.drawable.ic_alarm_on_white_24dp)
.setContentTitle(getApplicationContext().getResources().getString(R.string.app_name))
.setTicker(mTitle)
.setContentText(mTitle)
.setSound(RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION))
.setContentIntent(mClick)
.setAutoCancel(true)
.setOnlyAlertOnce(true);
}
}
...@@ -231,6 +231,7 @@ public class ReminderAddActivity extends AppCompatActivity { ...@@ -231,6 +231,7 @@ public class ReminderAddActivity extends AppCompatActivity {
mYear = year; mYear = year;
mDate = mDay + "/" + mMonth + "/" + mYear; mDate = mDay + "/" + mMonth + "/" + mYear;
mDateText.setText(mDate); mDateText.setText(mDate);
//mMonth = monthOfYear+1;
} }
}, mYear, mMonth, mDay); }, mYear, mMonth, mDay);
datePickerDialog.show(); datePickerDialog.show();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment