I am using AlarmManager to call a function at a certain time. It is working successfully in Genymotion Emulator but not in a real device like Redmi, Honor, etc. Here is the Code.
Intent intent = new Intent(CreateContact.this, DeleteContactReceiver.class);
intent.putExtra("name", name.getText().toString());
intent.putExtra("phone", phoneNumber.getText().toString());
PendingIntent pendingIntent = PendingIntent.getBroadcast(
getApplicationContext(), (int) System.currentTimeMillis(), intent, 0);
AlarmManager alarmManager = (AlarmManager) getSystemService(ALARM_SERVICE);
alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()
+ (selected * 60000), pendingIntent);
The min SDK version is 21.
EDIT: I tried to use setAndAllowWhileIdle but it still won't work.
Any Suggestions?