Example usage for android.content Context ALARM_SERVICE

List of usage examples for android.content Context ALARM_SERVICE

Introduction

In this page you can find the example usage for android.content Context ALARM_SERVICE.

Prototype

String ALARM_SERVICE

To view the source code for android.content Context ALARM_SERVICE.

Click Source Link

Document

Use with #getSystemService(String) to retrieve a android.app.AlarmManager for receiving intents at a time of your choosing.

Usage

From source file:knayi.delevadriver.AvaliableJobDetailActivity.java

private void cancelAlarmManager() {
    Log.d("TAG", "cancelAlarmManager");

    Context context = getBaseContext();
    //Intent gpsTrackerIntent = new Intent(context, GpsTrackerAlarmReceiver.class);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, gpsTrackerIntent, 0);
    AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    alarmManager.cancel(pendingIntent);//from w ww .  j a  v a 2s  .  co  m
}

From source file:knayi.delevadriver.AvaliableJobDetailActivity.java

private void startAlarmManager() {
    Log.d("TAG", "startAlarmManager");

    Context context = getBaseContext();
    alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    gpsTrackerIntent = new Intent(context, GpsTrackerAlarmReceiver.class);
    pendingIntent = PendingIntent.getBroadcast(context, 0, gpsTrackerIntent, 0);

    alarmManager.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime(),
            intervalInMinutes * 10000, // 60000 = 1 minute
            pendingIntent);/*from ww w .j  a  va  2  s . co m*/

    //startService(new Intent(AvaliableJobDetailActivity.this, GPSLocationService.class));

}

From source file:eu.faircode.netguard.ServiceSinkhole.java

@Override
public void onCreate() {
    Log.i(TAG, "Create version=" + Util.getSelfVersionName(this) + "/" + Util.getSelfVersionCode(this));

    SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);

    // Native init
    jni_init();//from w w  w .  ja  v a 2s.c o  m
    boolean pcap = prefs.getBoolean("pcap", false);
    setPcap(pcap, this);

    prefs.registerOnSharedPreferenceChangeListener(this);

    Util.setTheme(this);
    super.onCreate();

    HandlerThread commandThread = new HandlerThread(getString(R.string.app_name) + " command",
            Process.THREAD_PRIORITY_FOREGROUND);
    HandlerThread logThread = new HandlerThread(getString(R.string.app_name) + " log",
            Process.THREAD_PRIORITY_BACKGROUND);
    HandlerThread statsThread = new HandlerThread(getString(R.string.app_name) + " stats",
            Process.THREAD_PRIORITY_BACKGROUND);
    commandThread.start();
    logThread.start();
    statsThread.start();

    commandLooper = commandThread.getLooper();
    logLooper = logThread.getLooper();
    statsLooper = statsThread.getLooper();

    commandHandler = new CommandHandler(commandLooper);
    logHandler = new LogHandler(logLooper);
    statsHandler = new StatsHandler(statsLooper);

    // Listen for power save mode
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP && !Util.isPlayStoreInstall(this)) {
        PowerManager pm = (PowerManager) getSystemService(POWER_SERVICE);
        powersaving = pm.isPowerSaveMode();
        IntentFilter ifPower = new IntentFilter();
        ifPower.addAction(PowerManager.ACTION_POWER_SAVE_MODE_CHANGED);
        registerReceiver(powerSaveReceiver, ifPower);
        registeredPowerSave = true;
    }

    // Listen for user switches
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        IntentFilter ifUser = new IntentFilter();
        ifUser.addAction(Intent.ACTION_USER_BACKGROUND);
        ifUser.addAction(Intent.ACTION_USER_FOREGROUND);
        registerReceiver(userReceiver, ifUser);
        registeredUser = true;
    }

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        // Listen for idle mode state changes
        IntentFilter ifIdle = new IntentFilter();
        ifIdle.addAction(PowerManager.ACTION_DEVICE_IDLE_MODE_CHANGED);
        registerReceiver(idleStateReceiver, ifIdle);
        registeredIdleState = true;
    }

    // Listen for connectivity updates
    IntentFilter ifConnectivity = new IntentFilter();
    ifConnectivity.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
    registerReceiver(connectivityChangedReceiver, ifConnectivity);
    registeredConnectivityChanged = true;

    // Listen for added applications
    IntentFilter ifPackage = new IntentFilter();
    ifPackage.addAction(Intent.ACTION_PACKAGE_ADDED);
    ifPackage.addAction(Intent.ACTION_PACKAGE_REMOVED);
    ifPackage.addDataScheme("package");
    registerReceiver(packageChangedReceiver, ifPackage);
    registeredPackageChanged = true;

    // Setup house holding
    Intent alarmIntent = new Intent(this, ServiceSinkhole.class);
    alarmIntent.setAction(ACTION_HOUSE_HOLDING);
    PendingIntent pi = PendingIntent.getService(this, 0, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT);

    AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    am.setInexactRepeating(AlarmManager.RTC, SystemClock.elapsedRealtime() + 60 * 1000,
            AlarmManager.INTERVAL_HALF_DAY, pi);
}

From source file:com.mozilla.SUTAgentAndroid.service.DoCommand.java

public String SetTimeZone(String sTimeZone) {
    String sRet = "Unable to set timezone to " + sTimeZone;
    TimeZone tz = null;//from   w  w w.j a  v  a2  s. c o  m
    AlarmManager amgr = null;

    if ((sTimeZone.length() > 0) && (sTimeZone.startsWith("GMT"))) {
        amgr = (AlarmManager) contextWrapper.getSystemService(Context.ALARM_SERVICE);
        if (amgr != null)
            amgr.setTimeZone(sTimeZone);
    } else {
        String[] zoneNames = TimeZone.getAvailableIDs();
        int nNumMatches = zoneNames.length;
        int lcv = 0;

        for (lcv = 0; lcv < nNumMatches; lcv++) {
            if (zoneNames[lcv].equalsIgnoreCase(sTimeZone))
                break;
        }

        if (lcv < nNumMatches) {
            amgr = (AlarmManager) contextWrapper.getSystemService(Context.ALARM_SERVICE);
            if (amgr != null)
                amgr.setTimeZone(zoneNames[lcv]);
        }
    }

    if (amgr != null) {
        tz = TimeZone.getDefault();
        Date now = new Date();
        sRet = tz.getDisplayName(tz.inDaylightTime(now), TimeZone.LONG);
    }

    return (sRet);
}

From source file:org.kontalk.service.msgcenter.MessageCenterService.java

void setWakeupAlarm() {
    long delay = Preferences.getWakeupTimeMillis(this, MIN_WAKEUP_TIME);

    // start message center pending intent
    PendingIntent pi = PendingIntent.getService(getApplicationContext(), 0, getStartIntent(this),
            PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_ONE_SHOT);

    // we don't use the shared alarm manager instance here
    // since this can happen after the service has begun to stop
    AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    am.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + delay, pi);
}

From source file:de.anderdonau.spacetrader.Main.java

public void btnChangeTheme(View view) {
    SharedPreferences sp = getSharedPreferences("spacetrader", MODE_PRIVATE);
    SharedPreferences.Editor ed = sp.edit();
    String theme = sp.getString("Theme", "Light");
    if (view.getId() == R.id.btnDarkTheme) {
        if ("Dark".equals(theme)) {
            Toast.makeText(this, "This theme is already selected.", Toast.LENGTH_SHORT).show();
            return;
        }//from   w  w  w. ja v  a  2 s.  c  o m
        ed.putString("Theme", "Dark");
    } else {
        if ("Light".equals(theme)) {
            Toast.makeText(this, "This theme is already selected.", Toast.LENGTH_SHORT).show();
            return;
        }
        ed.putString("Theme", "Light");
    }
    ed.commit();
    Popup popup = new Popup(this, "Change Theme",
            "Space Trader must be restarted to change the theme. Do you want to do that now?", "",
            "Restart now", "Restart later", new Popup.buttonCallback() {
                @Override
                public void execute(Popup popup, View view) {
                    saveGame();
                    Intent mStartActivity = new Intent(getApplicationContext(), Main.class);
                    int mPendingIntentId = Math.abs(gameState.rand.nextInt());
                    //noinspection ConstantConditions
                    PendingIntent mPendingIntent = PendingIntent.getActivity(getApplicationContext(),
                            mPendingIntentId, mStartActivity, PendingIntent.FLAG_CANCEL_CURRENT);
                    AlarmManager mgr = (AlarmManager) getApplicationContext()
                            .getSystemService(Context.ALARM_SERVICE);
                    mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 100, mPendingIntent);
                    System.exit(0);
                }
            }, cbShowNextPopup);
    addPopup(popup);
    showNextPopup();
}

From source file:com.guardtrax.ui.screens.HomeScreen.java

private void showAlert(final String title, final String message, boolean OKOnly) {
    AlertDialog.Builder dialog = new AlertDialog.Builder(HomeScreen.this);
    dialog.setCancelable(false);//from ww  w.ja v  a  2s. c o m
    dialog.setTitle(title);
    dialog.setMessage(message);
    dialog.setPositiveButton("OK", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int place) {
            //if device not registered go straight to scan screen
            if (!Utility.deviceRegistered())
                scan_click(false);

            //if OK entered from updateSync then reboot
            if (restartsyncTimer) {
                Intent restartIntent = getPackageManager().getLaunchIntentForPackage(getPackageName());
                PendingIntent intent = PendingIntent.getActivity(HomeScreen.this, 0, restartIntent,
                        Intent.FLAG_ACTIVITY_CLEAR_TOP);
                AlarmManager manager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
                manager.set(AlarmManager.RTC, System.currentTimeMillis() + 500, intent);
                System.exit(2);
            }

            if (taa == 5) {
                taa = 3; //when returning to onResume from signature screen this will execute specific code inside onResume
                signaturefileName = Utility.createSignatureFileName();
                Intent intent = new Intent();
                intent.setClass(HomeScreen.this, SignatureScreen.class);
                intent.putExtra("file_name", Utility.getsharedPreference(HomeScreen.this, "signaturefileName"));
                startActivity(intent);
            }
        }
    });

    if (!OKOnly) {
        dialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
            @Override
            public void onClick(DialogInterface dialog, int place) {
                if (taa == 5) {
                    taa = 3; //tells onResume to execute end shift code
                    onResume();
                }
            }
        });
    }
    dialog.show();
}

From source file:com.codename1.impl.android.AndroidImplementation.java

public void scheduleLocalNotification(LocalNotification notif, long firstTime, int repeat) {

    final Intent notificationIntent = new Intent(getContext(), LocalNotificationPublisher.class);
    notificationIntent.setAction(getContext().getApplicationInfo().packageName + "." + notif.getId());
    notificationIntent.putExtra(LocalNotificationPublisher.NOTIFICATION, createBundleFromNotification(notif));

    Intent contentIntent = new Intent();
    if (getActivity() != null) {
        contentIntent.setComponent(getActivity().getComponentName());
    }//  w w w . jav  a  2s . c  o m
    contentIntent.putExtra("LocalNotificationID", notif.getId());

    if (BACKGROUND_FETCH_NOTIFICATION_ID.equals(notif.getId()) && getBackgroundFetchListener() != null) {
        Context context = AndroidNativeUtil.getContext();

        Intent intent = new Intent(context, BackgroundFetchHandler.class);
        //there is an bug that causes this to not to workhttps://code.google.com/p/android/issues/detail?id=81812
        //intent.putExtra("backgroundClass", getBackgroundLocationListener().getName());
        //an ugly workaround to the putExtra bug 
        intent.setData(
                Uri.parse("http://codenameone.com/a?" + getBackgroundFetchListener().getClass().getName()));
        PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        notificationIntent.putExtra(LocalNotificationPublisher.BACKGROUND_FETCH_INTENT, pendingIntent);

    } else {
        contentIntent.setData(
                Uri.parse("http://codenameone.com/a?LocalNotificationID=" + Uri.encode(notif.getId())));
    }
    PendingIntent pendingContentIntent = PendingIntent.getActivity(getContext(), 0, contentIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    notificationIntent.putExtra(LocalNotificationPublisher.NOTIFICATION_INTENT, pendingContentIntent);

    PendingIntent pendingIntent = PendingIntent.getBroadcast(getContext(), 0, notificationIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    AlarmManager alarmManager = (AlarmManager) getContext().getSystemService(Context.ALARM_SERVICE);
    if (BACKGROUND_FETCH_NOTIFICATION_ID.equals(notif.getId())) {
        alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, firstTime,
                getPreferredBackgroundFetchInterval() * 1000, pendingIntent);
    } else {
        if (repeat == LocalNotification.REPEAT_NONE) {
            alarmManager.set(AlarmManager.RTC_WAKEUP, firstTime, pendingIntent);

        } else if (repeat == LocalNotification.REPEAT_MINUTE) {

            alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, firstTime, 60 * 1000, pendingIntent);

        } else if (repeat == LocalNotification.REPEAT_HOUR) {

            alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, firstTime,
                    AlarmManager.INTERVAL_HALF_HOUR, pendingIntent);

        } else if (repeat == LocalNotification.REPEAT_DAY) {

            alarmManager.setInexactRepeating(AlarmManager.RTC_WAKEUP, firstTime, AlarmManager.INTERVAL_DAY,
                    pendingIntent);

        } else if (repeat == LocalNotification.REPEAT_WEEK) {

            alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, firstTime, AlarmManager.INTERVAL_DAY * 7,
                    pendingIntent);

        }
    }
}

From source file:com.codename1.impl.android.AndroidImplementation.java

public void cancelLocalNotification(String notificationId) {
    Intent notificationIntent = new Intent(getContext(), LocalNotificationPublisher.class);
    notificationIntent.setAction(getContext().getApplicationInfo().packageName + "." + notificationId);

    PendingIntent pendingIntent = PendingIntent.getBroadcast(getContext(), 0, notificationIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    AlarmManager alarmManager = (AlarmManager) getContext().getSystemService(Context.ALARM_SERVICE);
    alarmManager.cancel(pendingIntent);/*w  w  w.  j ava  2  s . c  om*/
}