0

What I want to do

I want to call the receiver from the other receiver at the particular time. so to do this I am using alarmManager but it is not working. I have tried every possible solution listed on the internet. I am try to solve this from last 4 days but no luck.

 @SuppressLint("NewApi")
    private void setAlarmToCallNotificationService(Context context, int request_code, String notificationText, String notificationTitle) {
            init(context);

        Log.i("Inside notification,","Yes");

        Intent intent = new Intent(context, notificationService.class);
        intent.putExtra("Notification_title",notificationTitle);
        intent.putExtra("Notification_text",notificationText);


        //hit the notification At the 8.00 in the morning
        Calendar notificationCalendar=Calendar.getInstance();
        notificationCalendar.set(Calendar.HOUR_OF_DAY,12);
        notificationCalendar.set(Calendar.MINUTE,51);
        notificationCalendar.set(Calendar.SECOND,0);

        Long time=notificationCalendar.getTimeInMillis();

        System.out.println("NOTIFICATION Time is "+notificationCalendar.get(Calendar.HOUR_OF_DAY)+" "+notificationCalendar.get(Calendar.MINUTE));
        Log.i("Target",time.toString());

        //final int _id = (int) System.currentTimeMillis();
        PendingIntent pendingIntent = PendingIntent.getBroadcast(context, request_code, intent, PendingIntent.FLAG_ONE_SHOT);

        int currentapiVersion = android.os.Build.VERSION.SDK_INT;
        if (currentapiVersion < android.os.Build.VERSION_CODES.KITKAT){
            alarmManager.set(AlarmManager.RTC_WAKEUP, time, pendingIntent);
        } else {
            if (currentapiVersion < android.os.Build.VERSION_CODES.M) {
                alarmManager.setExact(AlarmManager.RTC_WAKEUP, time, pendingIntent);
            } else {
                alarmManager.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP, time, pendingIntent);
            }
        }

    }

I am setting the alarm in updateTables and on Alarm rang notificationservice class calls.

Manifest file:

 <receiver android:name=".notificationService"
            android:enabled="true"
            android:exported="true">

            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
            </intent-filter>

        </receiver>



 <receiver android:name=".UpdateTables"
            android:enabled="true"
            android:exported="true">

            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
            </intent-filter>

        </receiver>

./adb shell dumpsys alarm output.

RTC #5: Alarm{2f5fc896 type 1 when 1484807520998 user.com.hlthee}
    tag=*alarm*:user.com.hlthee/.UpdateTables
    type=1 whenElapsed=+23h57m34s393ms when=2017-01-19 12:02:00
    window=-1 repeatInterval=86400000 count=0
    operation=PendingIntent{14ea4c17: PendingIntentRecord{3bbb9804 user.com.hlthee broadcastIntent}}

 +11ms running, 0 wakeups, 1 alarms: u0a72:user.com.hlthee
      *alarm*:user.com.hlthee/.UpdateTables

  u0a72:user.com.hlthee +12ms running, 3 wakeups:
    +11ms 0 wakes 1 alarms: *alarm*:user.com.hlthee/.UpdateTables
    +1ms 3 wakes 3 alarms: *walarm*:user.com.hlthee/services.notificationService
Ankur Khandelwal
  • 1,042
  • 3
  • 19
  • 40
  • Do you see anything set when do `adb shell dumpsys alarm` in terminal? – Nick Friskel Jan 18 '17 at 07:44
  • I have updated the question with the adb shell dumpsys alarm output. One thing I would like to take in your notice, updateTables class is also called when an alarm occur. SO please don't confuse. @nickfriskel – Ankur Khandelwal Jan 18 '17 at 07:49
  • Is your `notificationService` in a subfolder named `services`? If so, you need to correct the `name` attribute on the `` element. – Mike M. Jan 18 '17 at 08:01
  • thanks man. @MikeM. what a silly mistake. you save me. – Ankur Khandelwal Jan 18 '17 at 08:07
  • hey @MikeM. Can you tell me one more thing how do I get to know whether my alarm is set or not. I have referred this http://stackoverflow.com/questions/28742884/how-to-read-adb-shell-dumpsys-alarm-output link. according to this, 3 wakes 3 alarms: means I have 3 alarm and devices wake up 3 times. But in that case my notificationService service was not register and then also I am getting this. – Ankur Khandelwal Jan 21 '17 at 07:43
  • I've not verified this, but I would assume that the system doesn't check that your `` is actually valid when you set the alarm. It will still wake up to try to fire the `PendingIntent`, and at that time, it will just fail, because the `` entry doesn't point to a valid class. – Mike M. Jan 21 '17 at 08:12
  • Hey @MikeM. I am again working with the alarm but this time when alarm fire up instead of opening dialog it open the app. – Ankur Khandelwal Jan 21 '17 at 08:40
  • I don't know what you mean by "open the app", and there is no `Dialog` in your posted code. – Mike M. Jan 21 '17 at 08:57
  • you can find each details here http://stackoverflow.com/questions/41777583/when-alarm-rang-app-open-instead-of-dialog @MikeM. – Ankur Khandelwal Jan 21 '17 at 09:13

0 Answers0