• 5
name

A PHP Error was encountered

Severity: Notice

Message: Undefined index: userid

Filename: views/question.php

Line Number: 191

Backtrace:

File: /home/prodcxja/public_html/questions/application/views/question.php
Line: 191
Function: _error_handler

File: /home/prodcxja/public_html/questions/application/controllers/Questions.php
Line: 433
Function: view

File: /home/prodcxja/public_html/questions/index.php
Line: 315
Function: require_once

name Punditsdkoslkdosdkoskdo

AlarmManager not working in Android 8.1.0

My requirement is set Notification for specific time like user birthday or holiday

I am using AlarmManager for scheduling notification using broadcast receiver

Code is working fine in 6.0 (even when app is killed,swiped from recent list) but not working on Android 8.1.0 (Mf : Oppo)

Readed This and This and many answers but not find any helpfull any idea how to solve this issue

Here is my code

    AlarmManager am = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE);

    //creating a new intent specifying the broadcast receiver\

    Intent i = new Intent(this, HolidayBroadcast.class);
    i.putExtra("eventName",islamicHoliday.getEventName());
    i.putExtra("dateH", testTmp.getCalendar().getTimeInMillis());
    i.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
    //creating a pending intent using the intent
    PendingIntent pi = PendingIntent.getBroadcast(this, new Random().nextInt(), i, PendingIntent.FLAG_UPDATE_CURRENT);


    //setting alarm
    if(Build.VERSION.SDK_INT>= Build.VERSION_CODES.M) {
        am.setExactAndAllowWhileIdle(AlarmManager.RTC_WAKEUP,getTimeInMillis(), pi);
    }
    else
    {
        am.setExact(AlarmManager.RTC_WAKEUP, getTimeInMillis(), pi);
    }

You can use workmanager as mentioned in link.It supports all api version and easy to use because it uses backward compatibility to API level 14

https://developer.android.com/topic/libraries/architecture/workmanager

https://medium.com/androiddevelopers/introducing-workmanager-2083bcfc4712

  • 1
Reply Report