Example usage for android.app AlarmManager ELAPSED_REALTIME_WAKEUP

List of usage examples for android.app AlarmManager ELAPSED_REALTIME_WAKEUP

Introduction

In this page you can find the example usage for android.app AlarmManager ELAPSED_REALTIME_WAKEUP.

Prototype

int ELAPSED_REALTIME_WAKEUP

To view the source code for android.app AlarmManager ELAPSED_REALTIME_WAKEUP.

Click Source Link

Document

Alarm time in android.os.SystemClock#elapsedRealtime SystemClock.elapsedRealtime() (time since boot, including sleep), which will wake up the device when it goes off.

Usage

From source file:com.lgallardo.youtorrentcontroller.RefreshListener.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {

    if (requestCode == SETTINGS_CODE) {

        alarmMgr = (AlarmManager) getApplication().getSystemService(Context.ALARM_SERVICE);
        Intent intent = new Intent(getApplication(), NotifierService.class);
        alarmIntent = PendingIntent.getBroadcast(getApplication(), 0, intent, 0);

        alarmMgr.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 5000,
                notification_period, alarmIntent);

    }//from   w w  w .j a va  2s  .co  m

    if (requestCode == OPTION_CODE) {

        String json = "";

        // Get Options
        getOptions();

        /***************************************
         * Save qBittorrent's options remotely *
         ****************************************/

        // Maximum global number of simultaneous connections
        json += "\"max_connec\":" + global_max_num_connections;

        // Maximum number of simultaneous connections per torrent
        json += ",\"max_connec_per_torrent\":" + max_num_conn_per_torrent;

        // Maximum number of upload slots per torrent
        json += ",\"max_uploads_per_torrent\":" + max_num_upslots_per_torrent;

        // Global upload speed limit in KiB/s; -1 means no limit is applied
        json += ",\"up_limit\":" + global_upload;

        // Global download speed limit in KiB/s; -1 means no limit is
        // applied
        json += ",\"dl_limit\":" + global_download;

        // alternative global upload speed limit in KiB/s
        json += ",\"alt_up_limit\":" + alt_upload;

        // alternative global upload speed limit in KiB/s
        json += ",\"alt_dl_limit\":" + alt_download;

        // Is torrent queuing enabled ?
        json += ",\"queueing_enabled\":" + torrent_queueing;

        // Maximum number of active simultaneous downloads
        json += ",\"max_active_downloads\":" + max_act_downloads;

        // Maximum number of active simultaneous uploads
        json += ",\"max_active_uploads\":" + max_act_uploads;

        // Maximum number of active simultaneous downloads and uploads
        json += ",\"max_active_torrents\":" + max_act_torrents;

        // Schedule alternative rate limits
        json += ",\"scheduler_enabled\":" + schedule_alternative_rate_limits;

        // Scheduler starting hour
        json += ",\"schedule_from_hour\":" + alt_from_hour;

        // Scheduler starting min
        json += ",\"schedule_from_min\":" + alt_from_min;

        // Scheduler ending hour
        json += ",\"schedule_to_hour\":" + alt_to_hour;

        // Scheduler ending min
        json += ",\"schedule_to_min\":" + alt_to_min;

        // Scheduler scheduler days
        json += ",\"scheduler_days\":" + scheduler_days;

        // Put everything in an json object
        json = "{" + json + "}";

        // Set preferences using this json object
        setQBittorrentPrefefrences(json);

        // Now it can be refreshed
        canrefresh = true;

    }

    if (requestCode == HELP_CODE) {
        // Now it can be refreshed
        canrefresh = true;
        swipeRefresh();

    }

    if (requestCode == SETTINGS_CODE && resultCode == RESULT_OK) {

        // Change current server (from settings or drawer menu)
        changeCurrentServer();
    }

}

From source file:com.goftagram.telegram.messenger.NotificationsController.java

private void scheduleNotificationRepeat() {
    try {//  w w  w .ja  v a  2s.  com
        PendingIntent pintent = PendingIntent.getService(ApplicationLoader.applicationContext, 0,
                new Intent(ApplicationLoader.applicationContext, NotificationRepeat.class), 0);
        SharedPreferences preferences = ApplicationLoader.applicationContext
                .getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
        int minutes = preferences.getInt("repeat_messages", 60);
        if (minutes > 0 && personal_count > 0) {
            alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP,
                    SystemClock.elapsedRealtime() + minutes * 60 * 1000, pintent);
        } else {
            alarmManager.cancel(pintent);
        }
    } catch (Exception e) {
        FileLog.e("tmessages", e);
    }
}

From source file:com.xorcode.andtweet.AndTweetService.java

/**
 * Starts the repeating Alarm that sends the fetch Intent.
 *///from  ww  w .  j  a  v a 2  s.  c om
private boolean scheduleRepeatingAlarm() {
    final AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    final PendingIntent pIntent = getRepeatingIntent();
    final int frequencyMs = getFetchFrequencyS();
    final long firstTime = SystemClock.elapsedRealtime() + frequencyMs;
    am.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, firstTime, frequencyMs, pIntent);
    MyLog.d(TAG, "Started repeating alarm in a " + frequencyMs + "ms rhythm.");
    return true;
}

From source file:com.lgallardo.qbittorrentclient.RefreshListener.java

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {

    if (requestCode == SETTINGS_CODE) {

        //            Log.d("Debug", "Notification alarm set");

        alarmMgr = (AlarmManager) getApplication().getSystemService(Context.ALARM_SERVICE);
        Intent intent = new Intent(getApplication(), NotifierService.class);
        alarmIntent = PendingIntent.getBroadcast(getApplication(), 0, intent, 0);

        alarmMgr.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.elapsedRealtime() + 5000,
                notification_period, alarmIntent);
    }//from   w  w w  .  j  a va  2 s .c o m

    if (requestCode == OPTION_CODE) {

        String json = "";

        // Get Options
        getOptions();

        /***************************************
         * Save qBittorrent's options remotely *
         ****************************************/

        // Maximum global number of simultaneous connections
        json += "\"max_connec\":" + global_max_num_connections;

        // Maximum number of simultaneous connections per torrent
        json += ",\"max_connec_per_torrent\":" + max_num_conn_per_torrent;

        // Global maximum number of upload slots:
        json += ",\"max_uploads\":" + max_uploads;

        // Maximum number of upload slots per torrent
        json += ",\"max_uploads_per_torrent\":" + max_num_upslots_per_torrent;

        // Global upload speed limit in KiB/s; -1 means no limit is applied
        json += ",\"up_limit\":" + global_upload;

        // Global download speed limit in KiB/s; -1 means no limit is
        // applied
        json += ",\"dl_limit\":" + global_download;

        // alternative global upload speed limit in KiB/s
        json += ",\"alt_up_limit\":" + alt_upload;

        // alternative global upload speed limit in KiB/s
        json += ",\"alt_dl_limit\":" + alt_download;

        // Is torrent queuing enabled ?
        json += ",\"queueing_enabled\":" + torrent_queueing;

        // Maximum number of active simultaneous downloads
        json += ",\"max_active_downloads\":" + max_act_downloads;

        // Maximum number of active simultaneous uploads
        json += ",\"max_active_uploads\":" + max_act_uploads;

        // Maximum number of active simultaneous downloads and uploads
        json += ",\"max_active_torrents\":" + max_act_torrents;

        // Schedule alternative rate limits
        json += ",\"scheduler_enabled\":" + schedule_alternative_rate_limits;

        // Scheduler starting hour
        json += ",\"schedule_from_hour\":" + alt_from_hour;

        // Scheduler starting min
        json += ",\"schedule_from_min\":" + alt_from_min;

        // Scheduler ending hour
        json += ",\"schedule_to_hour\":" + alt_to_hour;

        // Scheduler ending min
        json += ",\"schedule_to_min\":" + alt_to_min;

        // Scheduler scheduler days
        json += ",\"scheduler_days\":" + scheduler_days;

        //            Log.d("Debug", "max_ratio_enabled:" + max_ratio_enabled);

        // Share Ratio Limiting
        json += ",\"max_ratio_enabled\":" + max_ratio_enabled;

        if (max_ratio_enabled == false) {
            json += ",\"max_ratio\":-1";
        } else {
            json += ",\"max_ratio\":" + Float.parseFloat(max_ratio);
        }

        //            String max_ratio_string = "4) max_ratio: " + Float.parseFloat(max_ratio);
        //            Log.d("Debug", "3) max_ratio: " + Float.parseFloat(max_ratio));
        //            Log.d("Debug", max_ratio_string );

        json += ",\"max_ratio_act\":" + max_ratio_act;

        // Put everything in an json object
        json = "{" + json + "}";

        // Set preferences using this json object
        setQBittorrentPrefefrences(json);

        // Now it can be refreshed
        canrefresh = true;

    }

    if (requestCode == HELP_CODE && resultCode == RESULT_OK) {
        // Now it can be refreshed
        canrefresh = true;

        refreshSwipeLayout();
        refreshCurrent();
    }

    if (requestCode == SETTINGS_CODE && resultCode == RESULT_OK) {

        // Change current server (from settings or drawer menu)
        changeCurrentServer();

    }

    if (requestCode == ADDFILE_CODE && resultCode == RESULT_OK) {

        String file_path_value = "";

        // MaterialDesignPicker
        if (requestCode == ADDFILE_CODE && resultCode == RESULT_OK) {
            file_path_value = data.getStringExtra(FilePickerActivity.RESULT_FILE_PATH);
        }

        Log.d("Debug", "Torrent path: " + file_path_value);

        // Do something with the file path
        addTorrentFile(file_path_value);
    }

}

From source file:knayi.delevadriver.JobDetailActivity.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);/*  w ww  .  j  ava  2  s .c  om*/

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

}

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);//w w w .  j ava  2  s . c o m

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

}

From source file:com.ferdi2005.secondgram.NotificationsController.java

private void scheduleNotificationRepeat() {
    try {//from   w  ww .  j a  v a  2 s.c  o m
        PendingIntent pintent = PendingIntent.getService(ApplicationLoader.applicationContext, 0,
                new Intent(ApplicationLoader.applicationContext, NotificationRepeat.class), 0);
        SharedPreferences preferences = ApplicationLoader.applicationContext
                .getSharedPreferences("Notifications", Activity.MODE_PRIVATE);
        int minutes = preferences.getInt("repeat_messages", 60);
        if (minutes > 0 && personal_count > 0) {
            alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP,
                    SystemClock.elapsedRealtime() + minutes * 60 * 1000, pintent);
        } else {
            alarmManager.cancel(pintent);
        }
    } catch (Exception e) {
        FileLog.e(e);
    }
}

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:org.kontalk.service.msgcenter.MessageCenterService.java

private void setIdleAlarm() {
    // even if this is called from IdleThread, we don't need to synchronize
    // because at that point mConnection is null so we never get called
    long delay = Preferences.getIdleTimeMillis(this, 0);
    if (delay > 0) {
        ensureIdleAlarm();/* w  w w  .  j av  a 2 s  .  c  o m*/
        mAlarmManager.setInexactRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP,
                SystemClock.elapsedRealtime() + delay, delay, mIdleIntent);
    }
}