Linked Questions

Popular Questions

I want to fire notification for my adhan, So I used Alarmmanager and JobIntentService but I am not getting notification.

Here is receiver.

    <receiver android:name="receiver.BootReceiver"
            android:exported="false" />

and following is service class extending JobIntentService.

    public class JobService extends JobIntentService {

    public static final int JOB_ID = 100;
    public static final int NOTIF_ID = 56;
    long timestamp;
    private NotificationManager mNotificationManager;
//    private final IBinder mBinder = new NotificationService.LocalBinder();

//    MediaPlayer mMediaPlayer = null;

    String MpStop;
    SharedPreferences mPreferences;
    float selectedLat, selectedLng;
    String name, userSect;
    boolean mAzanNotification;

    public static void enqueueWork(Context context, Intent work) {

        enqueueWork(context, JobService.class, JOB_ID, work);
    protected void onHandleWork(@NonNull Intent intent) {
        mPreferences = Application.getAppContext().getSharedPreferences(Utils.PREF_NAME, Context.MODE_PRIVATE);

        mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);;

In notifyTasker isTimerTask(), where I check if currentTime equals my prayer Time. If it is true then I fire Notification.

NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, "CH_ID")
                    .setAutoCancel(true) //                    .setSound(uri)

            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {

                // Creating an Audio Attribute
               /* AudioAttributes audioAttributes = new AudioAttributes.Builder()

                // Creating Channel
                NotificationChannel notificationChannel = new NotificationChannel("CH_ID", "Testing_Audio", NotificationManager.IMPORTANCE_HIGH); //                notificationChannel.setSound(uri,audioAttributes);
            Notification notification =;
            notification.flags |=
                    Notification.FLAG_ONGOING_EVENT |
            notification.ledOnMS = 300;
            notification.ledOffMS = 3000;

            notification.flags |= Notification.FLAG_AUTO_CANCEL;

And following is my alarmManager which I activate from activity.

 Intent intent = new Intent(getMain(), BootReceiver.class);
        // Create a PendingIntent to be triggered when the alarm goes off
        alarmPendingIntent = PendingIntent.getBroadcast(getMain(), BootReceiver.REQUEST_CODE,
                intent, 0);
        // Setup periodic alarm every 5 seconds
        long firstMillis = System.currentTimeMillis(); // first run of alarm is immediate
        int intervalMillis = 60000; // as of API 19, alarm manager will be forced up to 60000 to save battery
        AlarmManager am = (AlarmManager) getActivity().getSystemService(ALARM_SERVICE);
        // See
        int minutes = 1;
        // by my own convention, minutes <= 0 means notifications are disabled
//        if (minutes > 0) {
                    SystemClock.elapsedRealtime() + minutes * 60 * 1000, minutes * 60 * 1000, alarmPendingIntent);

I tried to fire notification with above code for android oreo but it is not working. Is there any possibility to fire notification at specific time using job schedular. As notification will be fired at specific azan time.

Related Questions