set Alarm via AlarmManager - Android Android OS

Android examples for Android OS:Alarm Set Up

Description

set Alarm via AlarmManager

Demo Code


import android.app.AlarmManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.SystemClock;
import android.util.Log;
import java.util.concurrent.TimeUnit;

public class Main{
    private static AlarmManager mAlarmManager;
    private static PendingIntent mPendingIntent;
    private static void setAlarm(long time) {
        Log.i("Alarm", String.format("Setting alarm for: %d",
                TimeUnit.MILLISECONDS.toMinutes(time)));
        Intent intent = new Intent("com.byteshaft.gsmDetails");
        mPendingIntent = PendingIntent.getBroadcast(
                AppGlobals.getContext(), 0, intent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        mAlarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP,
                SystemClock.elapsedRealtime() + time, mPendingIntent);
    }//from w  ww . j av a 2s  . c o m
}

Related Tutorials