1

I have been trying to get notifications to launch on Android at the correct time. I want them to go off 2 mins in the future from App launch. If I can get it working here I can easily get it working where I really need to do it. The logs show that the needed lines of code are running but the notification never launches. I am up to over 8 hours of trying to debug this and getting no where. Any help would be great.

Here is the Reminder code I have created:

    final PendingIntent pi = PendingIntent.getBroadcast(this.mContext,
            0,
            i,
            PendingIntent.FLAG_ONE_SHOT);

    TimeZone timeZone= TimeZone.getDefault();
    Calendar time= Calendar.getInstance(timeZone);
    time.add(Calendar.MINUTE, 2);

    this.mAlarmManager.set(AlarmManager.RTC_WAKEUP,
            time.getTimeInMillis(),
            pi);

    Log.d ("setReminder",time.getTime().toLocaleString());

Now below is my OnAlarmRecieve code that is never running 2 mins later according to the logs. The class extends BroadcastReceiver

@Override
public void onReceive(final Context context,
        final Intent intent) {
    Log.d(TAG, "Recieved wake up cal from Alarm Manger");


    final String tableName = intent.getStringExtra(IntentExtraStringStorage.TABLE_NAME);
    final long rowID = intent.getLongExtra(IntentExtraStringStorage.ROW_ID,
            -1);
    final String titleString = intent.getStringExtra(IntentExtraStringStorage.NOTIFICATION_TITLE);
    final String notificationString=intent.getStringExtra(IntentExtraStringStorage.NOTIFICATION_NOTE);

    WakeUpReminderIntentService.acuireStaticLock(context);

    /*if (tableName== Task.TABLE_NAME) {
        launchTaskView(context, rowID);
    }
    else {
        Log.e (TAG, "Did not Launch");
        Toast.makeText(context, "Did not work right", Toast.LENGTH_SHORT).show();
    }*/
    Intent i = new Intent (context, ReminderService.class);
    i.putExtra("taskID", rowID);
    i.putExtras(intent.getExtras());
    Log.d(TAG, "Launched task");
    //TODO Added code to build the screen correctly
    //FIXIT this need to be finished.
    context.startService(i);
}]=
Stewbob
  • 16,759
  • 9
  • 63
  • 107
Timeless
  • 41
  • 7
  • Dunno if it's your problem or not, but I had a similar problem and it turned out that while onReceive() was being called, the device would go straight back to sleep as soon as onReceive() returned, and thus any code that should have run after onReceive() returned wouldn't run. My solution was to call PowerManager.userActivity() from within onReceive() to force the device fully awake. – Jeremy Friesner Apr 10 '12 at 22:36
  • For reference, see: http://stackoverflow.com/questions/9650974/how-to-programatically-dismiss-the-screensaver-lock-screen-on-android-nook-simp and/or https://github.com/jfriesne/Electric-Sign/blob/master/src/com/sugoi/electricsign/ElectricSignActivity.java – Jeremy Friesner Apr 10 '12 at 22:37
  • Problem I am having is it seems like the onReceive() never is even running at all. Do I need to make sure something is added to the manifest to make sure it happens? – Timeless Apr 10 '12 at 22:58
  • Have you added the receiver to manifest.xml? – Rafael Carrillo Apr 11 '12 at 00:16
  • That was the problem. It was left out of the manifest file. Put it in and solved the problem completely – Timeless Apr 11 '12 at 00:47

1 Answers1

1

The problem was not putting the OnAlarmReciever in the mainfest as a receiver, and there was something not being put into the services as well.

ErikE
  • 48,881
  • 23
  • 151
  • 196
Timeless
  • 41
  • 7