Like @shaish, first create a link to Context so you can work with Android :.
Context context = cordova.getActivity().getApplicationContext();
Use the context to create an Intent, create a PendingIntent, and receive system maintenance.
Intent intent = new Intent(context, AlarmReciever.class); ... PendingIntent sender = PendingIntent.getBroadcast(context, 192837, intent, PendingIntent.FLAG_UPDATE_CURRENT); ... AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
Another problem is the AlarmReceiver class. It should extend BroadcastReceiver:
public class AlarmReceiver extends BroadcastReceiver { private static final String LOG_TAG = AlarmReceiver.class.getSimpleName(); @Override public void onReceive(Context context, Intent intent) { Log.d(LOG_TAG, "onReceive()"); } }
And you need to put it in AndroidManifest.xml:
<application> ... <receiver android:name="de.ma.AlarmReceiver"/> </application>
Alternative to BroadcastReceiver, if AlarmReceiver is an Activity, you can simply use:
PendingIntent sender = PendingIntent.getActivity(context, 192837, intent, PendingIntent.FLAG_UPDATE_CURRENT);
which launches your activity directly.
source share