android alarm sound not working - android

I have created an app where a user can insert various subjects and their day of exam.my app provides a time span for each subjects stored in database. when time allocated for each subject reaches,an alarm should play along with a notification.notification is coming properly,but alarm sound is not playing.please help me.
My alarm manager class is :
public class AlarmManager extends BroadcastReceiver {
sampleDatabase appdb;
SQLiteDatabase sqldb;
Cursor cursor;
int today,prev;
Intent in;
#Override
public void onReceive(Context context, Intent intent)
{
NotificationManager manger = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = new Notification(R.drawable.icon , "Yahrzeit" , System.currentTimeMillis());
in = new Intent(context,FirstAppActivity.class);
in.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, in, 0);
notification.setLatestEventInfo(context, "ALERT!!!!", "Time Over" , contentIntent);
notification.flags = Notification.FLAG_INSISTENT;
appdb = new sampleDatabase(context);
sqldb = appdb.getReadableDatabase();
cursor = sqldb.query(sampleDatabase.TABLE_SEC, null, null, null, null, null, null);
cursor.moveToFirst();
Calendar cal = Calendar.getInstance();
cal.set(Calendar.SECOND, 0);
today = (int)(cal.getTimeInMillis()/1000);
Log.e("Naga","Alarm");
Log.e("today",Integer.toString(today));
prev = 0;
cursor.moveToPrevious();
while(cursor.moveToNext())
{
int dbdate = cursor.getInt(cursor.getColumnIndex(sampleDatabase.ALARMSET));
int id = cursor.getInt(cursor.getColumnIndex(sampleDatabase.ROW_ID));
Log.e("dbdate",Integer.toString(dbdate));
if((dbdate<=today)&&(dbdate>prev))
{
manger.cancelAll();
manger.notify(1, notification);
sqldb.execSQL("DELETE from " + sampleDatabase.TABLE + " where " + sampleDatabase.ROW_ID + "=" + id);
sqldb.execSQL("DELETE from "+sampleDatabase.TABLE_SEC + " where " + sampleDatabase.ROW_ID + "=" + id);
}
prev = dbdate;
}
cursor.close();
sqldb.close();
}
code which i used to call this alarm manager is like this:
alarmintent = new Intent(getApplicationContext(),com.nagainfo.firstAp.AlarmManager.class);
sender = PendingIntent.getBroadcast(getApplicationContext() , 0 , alarmintent , PendingIntent.FLAG_CANCEL_CURRENT | Intent.FILL_IN_DATA);
am = (AlarmManager) getSystemService(ALARM_SERVICE);
am.cancel(sender);
alarmintent = new Intent(getApplicationContext(), com.nagainfo.firstAp.AlarmManager.class);
//alarmintent.putExtra("note","Hebrew");
sender = PendingIntent.getBroadcast(getApplicationContext() , 0 , alarmintent , PendingIntent.FLAG_CANCEL_CURRENT | Intent.FILL_IN_DATA);
am = (AlarmManager) getSystemService(ALARM_SERVICE);
am.setRepeating(AlarmManager.RTC_WAKEUP, alarmtime, 60000, sender);

You have not specified to use sound. Use this :
notification.defaults=Notification.DEFAULT_SOUND|Notification.DEFAULT_VIBRATE;
If you do not want the vibrate remove it. The point is you have to bit wise OR them. So, if you want lights also -
notification.defaults=Notification.DEFAULT_SOUND|Notification.DEFAULT_VIBRATE|Notification.DEFAULT_LIGHTS;

If someone are using NotificationCompat.Builder, you can use:
Uri sound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
notifyBuilder.setSound(sound);

Related

Unable to Cancel the Alarm through broadcast Receiver

I'm trying to cancel the repeating notifications on a particular date, so I'm setting it in a broadcast receiver which is fired on that particular time cancelling the repeating notifications through that unique id. but it is not cancelling the notifications. I have tried two techniques both are mentioned below.
mainActivity's code where I'm setting the Alarm.
Log.v("setting range alarm","key range id = " + keyIds[j] + "time = " + RangeTimes[j]);
// Setting the alarm for repeating notifications, with different broadcast Receiver (alertIntent).
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, RangeTimes[j], AlarmManager.INTERVAL_DAY,
PendingIntent.getBroadcast(this, keyIds[j], alertIntent, PendingIntent.FLAG_UPDATE_CURRENT)); // for exact repeating THIS
Log.v("setting range alarm","key range id = " + keyIds[j] + "Cancel time = " + CancelRangeTimes[j]);
// Setting the alarm for cancellin the repeating notifications, with different broadcast Receiver(cancelIntent).
cancelIntent.putExtra("CancelID", keyIds[j]);
cancelIntent.putExtra("key", pendingIntent);
AlarmManager alarmManager1 = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
alarmManager1.set(AlarmManager.RTC_WAKEUP, CancelRangeTimes[j],
PendingIntent.getBroadcast(this, keyIds[j], cancelIntent, PendingIntent.FLAG_UPDATE_CURRENT)); // for exact repeating THIS
here is the cancelling broadcast reciver which is not working even though it is getting called on the right time.
#Override
public void onReceive(Context context, Intent intent) {
String pleaseText = intent.getStringExtra("text");
// Methid # 1 ( By getting the Alarm id through intent and trying to cancel on the same id
/*
int cancelReqCode = intent.getIntExtra("CancelID", 0);
Log.v("setting the cancel", "inside broadCast reciver " + cancelReqCode);
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, cancelReqCode, intent, PendingIntent.FLAG_UPDATE_CURRENT);
Log.v("setting the cancel", "inside broadCast reciver " + pendingIntent);
AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
am.cancel(pendingIntent);
*/
// Methid # 2
Log.i("okk", "please text insode cancel" + pleaseText);
PendingIntent pendingIntent = intent.getParcelableExtra("key");
Log.v("setting the cancel","inside broadCast reciver " + pendingIntent );
AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
am.cancel(pendingIntent);
}
// below is the mainActvity's code where i'm setting alaram managers, alertIntent, CancelIntent and Pending Intents. I have omitted the code where it is getting the array values and setting them because it was useless here, but every date value is correct. this setAlarm() is getting called in the onCreate method.
public class MainActivity extends ActionBarActivity implements AsyncResponse, View.OnClickListener {
AlarmManager alarmManager;
PendingIntent pendingIntent;
public void setAlarm1() {
long[] RangeTimes = new long[C.getCount()];
long[] CancelRangeTimes = new long[C.getCount()];
String rangeCheck = "false" ;
int[] KeyRangeIds = new int[C.getCount()];
Intent alertIntent = new Intent(this, AlertReceiver.class);
Intent cancelIntent = new Intent(this, CancelAlarmBroadcastReceiver.class);
alertIntent.putExtra("strings", DealTimes);
cancelIntent.putExtra("strings", DealTimes);
// ------------------------- SETTING ALARM --------------------------------
for (int i = 0; i < UserFoodType.length; i++) {
for (int j = 0; j < C.getCount(); j++) {
RangeTimes[j] = calendar.getTimeInMillis();
CancelRangeTimes[j] = calendar1.getTimeInMillis();
}
if(FoodType[j].equals(UserFoodType[i]))
{
for (int k = 0; k < UserDealZone.length; k++) {
if(DealZone[j].equals(UserDealZone[k]))
{
Log.v("setting range alarm","key range id = " + keyIds[j] + "time = " + RangeTimes[j]);
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, RangeTimes[j], AlarmManager.INTERVAL_DAY,
PendingIntent.getBroadcast(this, keyIds[j], alertIntent, PendingIntent.FLAG_UPDATE_CURRENT)); // for exact repeating THIS
Log.v("setting range alarm","key range id = " + keyIds[j] + "Cancel time = " + CancelRangeTimes[j]);
// alertIntent.putExtra("cancelID", keyIds[j]);
cancelIntent.putExtra("CancelID", keyIds[j]);
cancelIntent.putExtra("key", pendingIntent);
AlarmManager alarmManager1 = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
alarmManager1.set(AlarmManager.RTC_WAKEUP, CancelRangeTimes[j],
PendingIntent.getBroadcast(this, keyIds[j], cancelIntent, PendingIntent.FLAG_UPDATE_CURRENT)); // for exact repeating THIS
}
}
}
You are putting an extra in cancelIntent, like this:
cancelIntent.putExtra("key", pendingIntent);
however, pendingIntent is never initialized, so it will be null.
When CancelAlarmBroadcastReceiver.onReceive() is called, this code:
PendingIntent pendingIntent = intent.getParcelableExtra("key");
is probably returning null. You are logging that, you should be able to check.
In any case, if pendingIntent is null, calling AlarmManager.cancel() won't do anything.

Scheduling multiple future notifications

I am currently debugging an issue with notifications inside my application. For some context, what I'd like to do is schedule notifications that should popup whenever a rocket launch is occurring. What I was doing was, after getting a list of scheduled launches from an API, I would take the launch date (in milliseconds since Jan 1 1970) and subtract the System.currentTimeMillis() from it. I would then use the resulting time to schedule the notification in the future, represented as System.currentTimeMillis() + timeDifference. I noticed that for whatever reason, only 1 notification is ever displayed.
I've tried debugging by scheduling notifications at 2, 4, and 6 minutes in the future, however a notification is only displayed at the 6 minute mark.
Some relevant code is below:
public void scheduleNotifications(List<Launch> launches) {
for(int i = 0; i < launches.size(); i++) {
SimpleDateFormat format = new SimpleDateFormat("MMMM dd, yyyy HH:mm:ss z");
Date date = null;
try {
date = format.parse(launches.get(i).getWindowstart());
} catch (ParseException e) {
e.printStackTrace();
}
long timeBetween = date.getTime() - System.currentTimeMillis();
Integer id = Long.valueOf(date.getTime()).intValue();
Intent notificationIntent = new Intent(this, NotificationPublisher.class);
notificationIntent.putExtra(NotificationPublisher.NOTIFICATION_ID, id);
notificationIntent.putExtra(NotificationPublisher.NOTIFICATION, getNotification(launches.get(i).getRocket().getName(), launches.get(i).getLocation().getPads().get(0).getName()));
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, notificationIntent, 0);
AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
//Debug. Schedule at 2, 4, 6 minutes.
if (i == 0) {
alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 120000, pendingIntent);
}
if (i == 1) {
alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 240000, pendingIntent);
}
if (i == 2) {
alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 360000, pendingIntent);
}
}
}
private Notification getNotification(String rocketName, String padName) {
Notification.Builder builder = new Notification.Builder(this);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, MainActivity.class), 0);
builder.setContentIntent(pendingIntent);
builder.setContentTitle("Upcoming Launch");
builder.setContentText("A launch of a " + rocketName + " is about to occur at " + padName + ". Click for more info.");
builder.setSmallIcon(R.drawable.rocket_icon);
return builder.build();
}
Broadcast Receiver:
public class NotificationPublisher extends BroadcastReceiver {
public static String NOTIFICATION_ID = "notification_id";
public static String NOTIFICATION = "notification";
public void onReceive(Context context, Intent intent) {
NotificationManager notificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
Notification notification = intent.getParcelableExtra(NOTIFICATION);
int id = intent.getIntExtra(NOTIFICATION_ID, 0);
notificationManager.notify(id, notification);
}
}
I'd like to know why only a single notification is ever presented, as well as what I need to add to achieve the previously stated goal.
When you set an alarm using AlarmManager, it automatically cancels any existing alarm that has a matching PendingIntent. Since all your PendingIntents contain the same components, every time you set an alarm, the previously set ones are automatically cancelled.
If you want to set multiple alarms, you must make sure that each of the PendingIntents is unique. You can do this in one of the following ways:
Use a different requestCode (second parameter to PendingIntent.getBroadcast()) for each PendingIntent
Use a different ACTION in the Intent you pass to PendingIntent.getBroadcast() for each PendingIntent

Repeating alarm wont work in Android

User can set their own repeat interval, for example he/she selected 5 minutes to be reminded of the new goal she set. The reminder will start on the goal's start date which is also set by the user.
No problem with setting goal, and setting the repeat interval. The problem is it wont work.
What i would like to happen: This is an example
Goal 1 starts tomorrow. User will get reminder of Goal 1 in every 1 hour tomorrow.
Here's my code:
public void setReminder(){
List<Goals> oneGoal = dbhandler.getLatestGoal(goal_id);
for (final Goals goals : oneGoal) {
if (repeat.isChecked()) {
long futureInMillis = 0;
dbhandler.updateReminders("true",choiceNumber,choiceRepeat,goal_id);
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(System.currentTimeMillis());
cal.set(Calendar.DATE,Integer.parseInt(goals.getSDay())); //1-31
cal.set(Calendar.MONTH,Integer.parseInt(goals.getSMonth())-1); //first month is 0!!! January is zero!!!
cal.set(Calendar.YEAR, Integer.parseInt(goals.getSYear()));//year...
//assigned a unique id to notifications
Random random = new Random();
int m = random.nextInt(9999 - 1000) + 1000;
//Create a new PendingIntent and add it to the AlarmManager
Intent intent3 = new Intent(this, TimeAlarm.class);
intent3.putExtra("goalid", Integer.toString(goal_id));
PendingIntent pendingIntent = PendingIntent.getActivity(this,
goals.getGoalId(), intent3, PendingIntent.FLAG_CANCEL_CURRENT);
AlarmManager am =
(AlarmManager) getSystemService(Activity.ALARM_SERVICE);
if (choiceRepeat.equalsIgnoreCase("Seconds")) {
am.setRepeating(AlarmManager.RTC_WAKEUP, SystemClock.elapsedRealtime(), 1000 * choiceNumber,
pendingIntent);
} else if (choiceRepeat.equalsIgnoreCase("Minutes")) {
am.setRepeating(AlarmManager.RTC_WAKEUP, SystemClock.elapsedRealtime(), 1000 * 60 * choiceNumber,
pendingIntent);
} else if (choiceRepeat.equalsIgnoreCase("Hours")) {
am.setRepeating(AlarmManager.RTC_WAKEUP, SystemClock.elapsedRealtime(), 1000 * 60 * 60 * choiceNumber,
pendingIntent);
}
MessageTo.message(SetReminderActivity.this, "You will be reminded every "+choiceNumber+" "+choiceRepeat+" for the new goal.");
//am.cancel(pendingIntent);
}else{
MessageTo.message(SetReminderActivity.this, "You've chosen not to set reminder for the new goal.");
}
}
}
TimeAlarm.java // for the notifications
public class TimeAlarm extends BroadcastReceiver {
NotificationManager nm;
MyDBAdapter dbhandler;
#Override
public void onReceive(Context context, Intent intent) {
int goal_id = Integer.parseInt(intent.getStringExtra("goalid"));
Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0,
new Intent(), 0);
//assigned a unique id to notifications
Random random = new Random();
int m = random.nextInt(9999 - 1000) + 1000;
List<Goals> oneGoal = dbhandler.getLatestGoal(goal_id);
for (final Goals goals : oneGoal) {
Notification mNotification = new Notification.Builder(context)
.setContentTitle("A Reminder from GSO")
.setContentText(goals.getGoalName())
.setSubText(goals.getStartDate() + " - " + goals.getEndDate())
.setSmallIcon(R.drawable.gsoicon)
.setContentIntent(contentIntent)
.setSound(soundUri)
.build();
nm = (NotificationManager) context
.getSystemService(Context.NOTIFICATION_SERVICE);
// If you want to hide the notification after it was selected, do the code below
mNotification.flags |= Notification.FLAG_AUTO_CANCEL;
nm.notify(m, mNotification);
}
}
}
in Android Manifest:
<receiver android:name=".TimeAlarm" />
I can't tell what wrong with my code. Pls. help.
You are only setting the alarm using AlarmManager's set() method. You should use setRepeating() method for repeating the alarm events.
So, your below line
am.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, futureInMillis, pendingIntent);
should be replaced with
am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, futureInMillis, pendingIntent);
You can also refer this Example : Create Repeating Alarm .
Example to repeat event on every two minutes
AlarmManager am = (AlarmManager)getSystemService(Activity.ALARM_SERVICE);
am.setRepeating(AlarmManager.ELAPSED_REALTIME, SystemClock.elapsedRealtime(),2*60*60,pendingIntent);
You have to declare the receiver in your AndroidManifest.xml
<receiver android:name="TimeAlarm" >
See: http://developer.android.com/guide/topics/manifest/receiver-element.html

multiple status bar notification, unique ID not working

I have an app that sends notifications to the status bar as a reminder to take a pill. If two pills need to be taken at the same time. then two separate notifications shall be sent. I know you need to use an unique id for this to happen in the .notify(int id, notification notification) function. However it doesn't seem to be working. I know for sure my ids are different as I've tested them by displaying a toast. I would appreciate any suggestions. Heres my code:
Alarm class:
DatabaseHelper notiDb = new DatabaseHelper(this);
notiDb.open();
final String dataName = notiDb.getDataName(pushed_name);
String dataDaily = notiDb.getDataDaily(pushed_name);
String dataWeekly = notiDb.getDataWeekly(pushed_name);
String dataTwice = notiDb.getDataTwice(pushed_name);
String dataDosage = notiDb.getDataDosage(pushed_name);
String dataStart = notiDb.getDataStart(pushed_name);
String dataID = notiDb.getDataID(pushed_name);
notiDb.close();
ID = Integer.parseInt(dataID);
Calendar uncalendar = Calendar.getInstance();
String unID = dataID +uncalendar;
Toast toast=Toast.makeText(this, "Alarm class, Notification for " +dataName +" has been set id: " +ID, Toast.LENGTH_LONG);
toast.show();
Intent intent_unique = new Intent(this, NotiScenario.class);
intent_unique.putExtra("ID", ID);
intent_unique.setData(Uri.parse(intent_unique.toUri(Intent.URI_INTENT_SCHEME)));
PendingIntent pIntent = PendingIntent.getActivity(this, ID, intent_unique, 2);
// Build notification
Notification noti = new Notification.Builder(this)
.setContentTitle("MedScan")
.setContentText("3. You should take "+dataDosage +" pills of " +dataName)
.setSmallIcon(R.drawable.original)
.setContentIntent(pIntent)
.build();
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
noti.defaults |= Notification.DEFAULT_ALL;
//Hide the notification after its selected
noti.flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(ID, noti);
Info class:
DatabaseHelper notiDb = new DatabaseHelper(this);
notiDb.open();
final String dataName = notiDb.getDataName(pushed_name);
String dataDaily = notiDb.getDataDaily(pushed_name);
final String dataWeekly = notiDb.getDataWeekly(pushed_name);
String dataTwice = notiDb.getDataTwice(pushed_name);
final String dataDosage = notiDb.getDataDosage(pushed_name);
String dataStart = notiDb.getDataStart(pushed_name);
String dataID = notiDb.getDataID(pushed_name);
notiDb.close();
ID = Integer.parseInt(dataID);
int value_Weekly = Integer.parseInt(dataWeekly);
int value_Daily = Integer.parseInt(dataDaily);
int value_Twice = Integer.parseInt(dataTwice);
int value_Start = Integer.parseInt(dataStart);
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, value_Start);
calendar.set(Calendar.MINUTE, 46);
calendar.set(Calendar.SECOND, 00);
int setTime = (value_Daily*value_Twice)/value_Weekly;
Intent intent_noti = new Intent(this,Alarm.class);
intent_noti.putExtra("ID", ID);
intent_noti.setData(Uri.parse(intent_noti.toUri(Intent.URI_INTENT_SCHEME)));
PendingIntent pendingIntent = PendingIntent.getActivity(this, ID, intent_noti, PendingIntent.FLAG_ONE_SHOT);
AlarmManager am = (AlarmManager)getSystemService(Activity.ALARM_SERVICE);
am.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), setTime, pendingIntent);
The problem isn't in your Alarm class which creates the notification but in your Info class which creates an alarm to call the Info class on a regular basis.
The two lines creating the pending intent for your alarm are:
Intent intent_noti = new Intent(this,Alarm.class);
PendingIntent pendingIntent = PendingIntent.getActivity(this, ID, intent_noti, PendingIntent.FLAG_CANCEL_CURRENT);
Because the Intent is the same regardless of your ID, a newly created PendingIntent will just cancel the previously created one.
In order for your code to work the Intent has to be different according to the Intent.filterEquals() method: http://developer.android.com/reference/android/content/Intent.html#filterEquals(android.content.Intent)
To get a unique Intent you could do:
intent_noti.setAction(""+System.currentTimeMillis());
or:
intent_noti.putExtra("ID", ID);
intent_noti.setData(Uri.parse(intent_noti.toUri(Intent.URI_INTENT_SCHEME)));

how to display two separate notifications at same time?

My app needs to display notifications in the status bar whenever it is time to take some pills. If two pills are to be taken at the same time, then two notifications shall appear. Right now my app can display separate notifications if the pill times are different. The problem is if they are at the same time it only displays the one that was created (when I press a button) most recently. However it still vibrates twice. Any suggestions?
Info class:
DatabaseHelper notiDb = new DatabaseHelper(this);
notiDb.open();
final String dataName = notiDb.getDataName(pushed_name);
String dataDaily = notiDb.getDataDaily(pushed_name);
final String dataWeekly = notiDb.getDataWeekly(pushed_name);
String dataTwice = notiDb.getDataTwice(pushed_name);
final String dataDosage = notiDb.getDataDosage(pushed_name);
String dataStart = notiDb.getDataStart(pushed_name);
String dataID = notiDb.getDataID(pushed_name);
notiDb.close();
ID = Integer.parseInt(dataID);
int value_Weekly = Integer.parseInt(dataWeekly);
int value_Daily = Integer.parseInt(dataDaily);
int value_Twice = Integer.parseInt(dataTwice);
int value_Start = Integer.parseInt(dataStart);
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, value_Start);
calendar.set(Calendar.MINUTE, 00);
calendar.set(Calendar.SECOND, 00);
int setTime = (value_Daily*value_Twice)/value_Weekly;
Intent intent_noti = new Intent(this,Alarm.class);
intent_noti.putExtra("ID", ID);
intent_noti.setData(Uri.parse(intent_noti.toUri(Intent.URI_INTENT_SCHEME)));
PendingIntent pendingIntent = PendingIntent.getActivity(this, ID, intent_noti, PendingIntent.FLAG_ONE_SHOT);
AlarmManager am = (AlarmManager)getSystemService(Activity.ALARM_SERVICE);
am.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), setTime, pendingIntent);
Alarm Class:
DatabaseHelper notiDb = new DatabaseHelper(this);
notiDb.open();
final String dataName = notiDb.getDataName(pushed_name);
String dataDaily = notiDb.getDataDaily(pushed_name);
String dataWeekly = notiDb.getDataWeekly(pushed_name);
String dataTwice = notiDb.getDataTwice(pushed_name);
String dataDosage = notiDb.getDataDosage(pushed_name);
String dataStart = notiDb.getDataStart(pushed_name);
String dataID = notiDb.getDataID(pushed_name);
notiDb.close();
ID = Integer.parseInt(dataID);
Intent intent_unique = new Intent(this, NotiScenario.class);
intent_unique.putExtra("ID", ID);
intent_unique.setData(Uri.parse(intent_unique.toUri(Intent.URI_INTENT_SCHEME)));
PendingIntent pIntent = PendingIntent.getActivity(this, ID, intent_unique, 0);
// Build notification
Notification noti = new Notification.Builder(this)
.setContentTitle("MedScan")
.setContentText("3. You should take "+dataDosage +" pills of " +dataName)
.setSmallIcon(R.drawable.original)
.setContentIntent(pIntent)
.build();
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
noti.defaults |= Notification.DEFAULT_ALL;
//Hide the notification after its selected
noti.flags |= Notification.FLAG_AUTO_CANCEL;
notificationManager.notify(ID, noti);
Is the id of the notification the same? If that's true I think that causes an override of the notification. Use different id's if you to show multiple notifications alongside each other.

Categories

Resources