How to know that my scheduled alarm has been canceled in AlarmManager using cancelAlarm method in Android?

50
April 15, 2019, at 8:00 PM

Is there any way that I can print Log and check it? like I tried this code:

  if (mPendingIntent == null) {
            showLog("cancelAlarm(): canceled");
        } else {
            showLog("cancelAlarm(): Unable to cancel scheduled alarms");
        }

But, I don't think that mPendingIntent will be null! Note: I'm using same Id, to create & cancel alarms.

public void cancelAlarm(Context context, int ID) {
        AlarmManager mAlarmManager;
        mAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
        mPendingIntent = PendingIntent.getBroadcast(context, ID, new Intent(context, AlarmReceiver.class), 0);
        mAlarmManager.cancel(mPendingIntent);
        // Restart alarm if device is rebooted
        ComponentName receiver = new ComponentName(context, BootReceiver.class);
        PackageManager pm = context.getPackageManager();
        pm.setComponentEnabledSetting(receiver,
                PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
                PackageManager.DONT_KILL_APP);
    }

//For Create

public void createRepeatAlarm(Context context, Calendar calendar, int id, long repeatTime) {
        AlarmManager mAlarmManager;
        mAlarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
        Intent intent = new Intent(context, AlarmReceiver.class);
        intent.putExtra(REMINDER_ID, id);
        mPendingIntent = PendingIntent.getBroadcast(context, id, intent, PendingIntent.FLAG_UPDATE_CURRENT);
        mAlarmManager.setRepeating(AlarmManager.RTC, calendar.getTimeInMillis(), repeatTime, mPendingIntent);
        /*TODO:-> Restart alarm if device is rebooted*/
        ComponentName receiver = new ComponentName(context, BootReceiver.class);
        PackageManager pm = context.getPackageManager();
        pm.setComponentEnabledSetting(receiver,
                PackageManager.COMPONENT_ENABLED_STATE_ENABLED,
                PackageManager.DONT_KILL_APP);
    }

Any help would be appreciate.

READ ALSO
How to get each device's distance from bluetooth?

How to get each device's distance from bluetooth?

I have a module device (Galaxy S2, API 16) and this device is use to be server module

27
Is there a way to automate user interaction with an android app?

Is there a way to automate user interaction with an android app?

I want to develop an app which can simulate user interaction on a web siteFor example the user types in a username and a password and a text

51
Swipe Layout automatically Swipe in first time when user open the Screen

Swipe Layout automatically Swipe in first time when user open the Screen

I'm creating a swipe layout using recyclerview, now I want to do something like gmail appWhen user open first time that screen the swipe layout automatically Swipe for interaction

17
How to fix this error whenever I am trying to run my android project?

How to fix this error whenever I am trying to run my android project?

Whenever I am trying to run my android project I get this error

57