Example usage for android.app AlarmManager RTC

List of usage examples for android.app AlarmManager RTC

Introduction

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

Prototype

int RTC

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

Click Source Link

Document

Alarm time in System#currentTimeMillis System.currentTimeMillis() (wall clock time in UTC).

Usage

From source file:com.aware.Aware.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
        DEBUG = Aware.getSetting(awareContext, Aware_Preferences.DEBUG_FLAG).equals("true");
        TAG = Aware.getSetting(awareContext, Aware_Preferences.DEBUG_TAG).length() > 0
                ? Aware.getSetting(awareContext, Aware_Preferences.DEBUG_TAG)
                : TAG;/*from w  w  w  .ja v  a 2s  . c o m*/

        if (Aware.DEBUG)
            Log.d(TAG, "AWARE framework is active...");
        startAllServices();

        //Only the client keeps the plugins running and checks for updates
        if (getPackageName().equals("com.aware")) {

            Cursor enabled_plugins = getContentResolver().query(Aware_Plugins.CONTENT_URI, null,
                    Aware_Plugins.PLUGIN_STATUS + "=" + Aware_Plugin.STATUS_PLUGIN_ON, null, null);
            if (enabled_plugins != null && enabled_plugins.moveToFirst()) {
                do {
                    startPlugin(getApplicationContext(), enabled_plugins
                            .getString(enabled_plugins.getColumnIndex(Aware_Plugins.PLUGIN_PACKAGE_NAME)));
                } while (enabled_plugins.moveToNext());
            }
            if (enabled_plugins != null && !enabled_plugins.isClosed())
                enabled_plugins.close();

            if (Aware.getSetting(getApplicationContext(), Aware_Preferences.AWARE_AUTO_UPDATE).equals("true")) {
                if (aware_preferences.getLong(PREF_LAST_UPDATE, 0) == 0
                        || (aware_preferences.getLong(PREF_LAST_UPDATE, 0) > 0 && System.currentTimeMillis()
                                - aware_preferences.getLong(PREF_LAST_UPDATE, 0) > 6 * 60 * 60 * 1000)) { //check every 6h
                    new Update_Check().execute();
                    SharedPreferences.Editor editor = aware_preferences.edit();
                    editor.putLong(PREF_LAST_UPDATE, System.currentTimeMillis());
                    editor.commit();
                }
            }
        }

        if (Aware.getSetting(getApplicationContext(), Aware_Preferences.STATUS_WEBSERVICE).equals("true")) {
            int frequency_webservice = Integer.parseInt(
                    Aware.getSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_WEBSERVICE));
            if (frequency_webservice == 0) {
                if (DEBUG) {
                    Log.d(TAG, "Data sync is disabled.");
                }
                alarmManager.cancel(webserviceUploadIntent);
            } else if (frequency_webservice > 0) {
                //Fixed: set alarm only once if not set yet.
                if (aware_preferences.getLong(PREF_LAST_SYNC, 0) == 0
                        || (aware_preferences.getLong(PREF_LAST_SYNC, 0) > 0 && System.currentTimeMillis()
                                - aware_preferences.getLong(PREF_LAST_SYNC, 0) > frequency_webservice * 60
                                        * 1000)) {
                    if (DEBUG) {
                        Log.d(TAG, "Data sync every " + frequency_webservice + " minute(s)");
                    }
                    SharedPreferences.Editor editor = aware_preferences.edit();
                    editor.putLong(PREF_LAST_SYNC, System.currentTimeMillis());
                    editor.commit();
                    alarmManager.setInexactRepeating(AlarmManager.RTC,
                            aware_preferences.getLong(PREF_LAST_SYNC, 0), frequency_webservice * 60 * 1000,
                            webserviceUploadIntent);
                }
            }

            //Check if study is open or still exists
            new Study_Check().execute();
        }

        if (!Aware.getSetting(getApplicationContext(), Aware_Preferences.FREQUENCY_CLEAN_OLD_DATA)
                .equals("0")) {
            Intent dataCleaning = new Intent(ACTION_AWARE_SPACE_MAINTENANCE);
            awareContext.sendBroadcast(dataCleaning);
        }
    } else { //Turn off all enabled plugins
        Cursor enabled_plugins = getContentResolver().query(Aware_Plugins.CONTENT_URI, null,
                Aware_Plugins.PLUGIN_STATUS + "=" + Aware_Plugin.STATUS_PLUGIN_ON, null, null);
        if (enabled_plugins != null && enabled_plugins.moveToFirst()) {
            do {
                stopPlugin(getApplicationContext(), enabled_plugins
                        .getString(enabled_plugins.getColumnIndex(Aware_Plugins.PLUGIN_PACKAGE_NAME)));
            } while (enabled_plugins.moveToNext());
            enabled_plugins.close();
        }
        if (enabled_plugins != null && !enabled_plugins.isClosed())
            enabled_plugins.close();
        if (Aware.DEBUG)
            Log.w(TAG, "AWARE plugins disabled...");
    }
    return START_STICKY;
}

From source file:cw.kop.autobackground.LiveWallpaperService.java

private void startAlarms() {
    if (AppSettings.useTimer() && AppSettings.getTimerDuration() > 0
            && PendingIntent.getBroadcast(getApplicationContext(), 0,
                    new Intent(LiveWallpaperService.DOWNLOAD_WALLPAPER),
                    PendingIntent.FLAG_NO_CREATE) != null) {

        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(System.currentTimeMillis());
        calendar.set(Calendar.HOUR_OF_DAY, AppSettings.getTimerHour());
        calendar.set(Calendar.MINUTE, AppSettings.getTimerMinute());

        alarmManager.cancel(pendingDownloadIntent);

        if (calendar.getTimeInMillis() > System.currentTimeMillis()) {
            alarmManager.setInexactRepeating(AlarmManager.RTC, calendar.getTimeInMillis(),
                    AppSettings.getTimerDuration(), pendingDownloadIntent);
        } else {//from w w  w .  j a va2 s  .  c om
            alarmManager.setInexactRepeating(AlarmManager.RTC,
                    calendar.getTimeInMillis() + AlarmManager.INTERVAL_DAY, AppSettings.getTimerDuration(),
                    pendingDownloadIntent);
        }
    }
    if (AppSettings.useInterval() && AppSettings.getIntervalDuration() > 0
            && PendingIntent.getBroadcast(getApplicationContext(), 0,
                    new Intent(LiveWallpaperService.UPDATE_WALLPAPER), PendingIntent.FLAG_NO_CREATE) != null) {
        alarmManager.setInexactRepeating(AlarmManager.RTC,
                System.currentTimeMillis() + AppSettings.getIntervalDuration(),
                AppSettings.getIntervalDuration(), pendingIntervalIntent);
    }
}

From source file:org.adblockplus.android.AdblockPlus.java

/**
 * Sets Alarm to call updater after specified number of minutes or after one
 * day if/*from   w ww.  j a  v  a 2 s . c  om*/
 * minutes are set to 0.
 * 
 * @param minutes
 *          number of minutes to wait
 */
public void scheduleUpdater(int minutes) {
    Calendar updateTime = Calendar.getInstance();

    if (minutes == 0) {
        // Start update checks at 10:00 GMT...
        updateTime.setTimeZone(TimeZone.getTimeZone("GMT"));
        updateTime.set(Calendar.HOUR_OF_DAY, 10);
        updateTime.set(Calendar.MINUTE, 0);
        // ...next day
        updateTime.add(Calendar.HOUR_OF_DAY, 24);
        // Spread out the mass downloading? for 6 hours
        updateTime.add(Calendar.MINUTE, (int) (Math.random() * 60 * 6));
    } else {
        updateTime.add(Calendar.MINUTE, minutes);
    }

    Intent updater = new Intent(this, AlarmReceiver.class);
    PendingIntent recurringUpdate = PendingIntent.getBroadcast(this, 0, updater,
            PendingIntent.FLAG_CANCEL_CURRENT);
    // Set non-waking alarm
    AlarmManager alarms = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    alarms.set(AlarmManager.RTC, updateTime.getTimeInMillis(), recurringUpdate);
}

From source file:com.xperia64.rompatcher.MainActivity.java

@SuppressLint("NewApi")
@Override/* w w  w  . j  a va  2s.c o  m*/
public void onRequestPermissionsResult(int requestCode, String permissions[], int[] grantResults) {
    super.onRequestPermissionsResult(requestCode, permissions, grantResults);
    switch (requestCode) {
    case PERMISSION_REQUEST: {
        // If request is cancelled, the result arrays are empty.
        boolean good = true;
        if (permissions.length != NUM_PERMISSIONS || grantResults.length != NUM_PERMISSIONS) {
            good = false;
        }

        for (int i = 0; i < grantResults.length && good; i++) {
            if (grantResults[i] != PackageManager.PERMISSION_GRANTED) {
                good = false;
            }
        }
        if (!good) {

            // permission denied, boo! Disable the app.
            new AlertDialog.Builder(MainActivity.this).setTitle("Error")
                    .setMessage("ROM Patcher cannot proceed without these permissions")
                    .setPositiveButton("OK", new OnClickListener() {

                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            MainActivity.this.finish();
                        }

                    }).setCancelable(false).show();
        } else {
            if (!Environment.getExternalStorageDirectory().canRead()) {
                // Buggy emulator? Try restarting the app
                AlarmManager alm = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE);
                alm.set(AlarmManager.RTC, System.currentTimeMillis() + 1000, PendingIntent.getActivity(this,
                        237462, new Intent(this, MainActivity.class), Intent.FLAG_ACTIVITY_NEW_TASK));
                System.exit(0);
            }
        }
        return;
    }

    // other 'case' lines to check for other
    // permissions this app might request
    }
}

From source file:cw.kop.autobackground.sources.SourceListFragment.java

/**
 * Starts (or stops) download and sets download icon appropriately
 */// w w w  .  ja  va2s . c  o m
private void startDownload() {
    listAdapter.saveData();
    if (FileHandler.isDownloading) {

        DialogFactory.ActionDialogListener listener = new DialogFactory.ActionDialogListener() {

            @Override
            public void onClickRight(View v) {
                FileHandler.cancel(appContext);
                resetActionBarDownload();
                dismissDialog();
            }
        };

        DialogFactory.showActionDialog(appContext, "", "Cancel download?", listener, -1, R.string.cancel_button,
                R.string.ok_button);
    } else if (FileHandler.download(appContext)) {
        Drawable drawable = getResources().getDrawable(R.drawable.ic_cancel_white_24dp);
        drawable.setColorFilter(AppSettings.getColorFilterInt(appContext), PorterDuff.Mode.MULTIPLY);
        toolbarMenu.getItem(1).setIcon(drawable);

        if (AppSettings.resetOnManualDownload() && AppSettings.useTimer()
                && AppSettings.getTimerDuration() > 0) {
            Intent intent = new Intent();
            intent.setAction(LiveWallpaperService.DOWNLOAD_WALLPAPER);
            intent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
            PendingIntent pendingIntent = PendingIntent.getBroadcast(appContext, 0, intent, 0);
            AlarmManager alarmManager = (AlarmManager) appContext.getSystemService(Context.ALARM_SERVICE);
            alarmManager.cancel(pendingIntent);
            alarmManager.setInexactRepeating(AlarmManager.RTC,
                    System.currentTimeMillis() + AppSettings.getTimerDuration(), AppSettings.getTimerDuration(),
                    pendingIntent);
        }
    }
}

From source file:com.umundus.service.NCallServiceOld.java

public void onCreate() {
    Log.d(TAG, "[*]Service-onCreate");
    super.onCreate();

    IntentFilter filter = new IntentFilter(ACTION_START_PATTERN_SEND_DATA);
    filter.addAction(ACTION_END_PATTERN_SEND_DATA);
    registerReceiver(mBroadcastReceiver, filter);

    int myID = 1234;
    Intent intent = new Intent(this, NCallServiceOld.class);
    //PendingIntent pendIntent = PendingIntent.getActivity(this, 0, bindIntent, 0);
    PendingIntent pi = PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_NO_CREATE);
    Notification notice = new Notification.Builder(this).setContentTitle("(Rang)")
            .setContentText("(Rang)? .").setSmallIcon(R.drawable.ic_launcher)
            .setLargeIcon(BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher)).setOngoing(true)
            .setContentIntent(pi).build();
    notice.flags |= Notification.FLAG_NO_CLEAR;
    notice.flags |= Notification.FLAG_ONGOING_EVENT;
    startForeground(myID, notice);//from ww w . ja  v a  2  s. co m

    AlarmManager al = (AlarmManager) this.getSystemService(this.ALARM_SERVICE);
    al.setRepeating(AlarmManager.RTC, System.currentTimeMillis(), 1000 * 15, pi);
}

From source file:com.google.android.apps.muzei.api.MuzeiArtSource.java

private void setUpdateAlarm(long nextTimeMillis) {
    if (!isEnabled()) {
        Log.w(TAG, "Source has no subscribers, not actually scheduling next update" + ", id=" + mName);
        return;/*from w ww  . j av  a 2  s  .co  m*/
    }

    if (nextTimeMillis < System.currentTimeMillis()) {
        Log.w(TAG, "Refusing to schedule next artwork in the past, id=" + mName);
        return;
    }

    AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
    am.set(AlarmManager.RTC, nextTimeMillis, getHandleNextCommandPendingIntent(this));
    Log.i(TAG, "Scheduling next artwork (source " + mName + ") at " + new Date(nextTimeMillis));
}

From source file:co.taqat.call.assistant.AssistantActivity.java

public void restartApplication() {
    mPrefs.firstLaunchSuccessful();/*www . j  av a  2  s . c om*/

    Intent mStartActivity = new Intent(this, LinphoneLauncherActivity.class);
    PendingIntent mPendingIntent = PendingIntent.getActivity(this, (int) System.currentTimeMillis(),
            mStartActivity, PendingIntent.FLAG_CANCEL_CURRENT);
    AlarmManager mgr = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE);
    mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 500, mPendingIntent);

    stopService(new Intent(Intent.ACTION_MAIN).setClass(this, LinphoneService.class));
    android.os.Process.killProcess(android.os.Process.myPid());
}

From source file:net.lp.hivawareness.v4.HIVAwarenessActivity.java

private void finishGame(boolean infected, int whenInfected) {

    String msg;//from   ww  w  .  j a v  a2s  .c  o m
    if (infected && whenInfected == 0) {
        msg = getString(R.string.infected_at_beginning);
    } else if (infected) {
        msg = getString(R.string.infected_when, whenInfected);
    } else {
        msg = getString(R.string.not_infected);
    }

    Intent intent = new Intent(this, AlertReceiver.class);
    intent.putExtra("message", msg);
    PendingIntent operation = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT);

    AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
    am.set(AlarmManager.RTC, System.currentTimeMillis(), operation);

    // clear history
    SharedPreferences prefs = getSharedPreferences(PREFS, MODE_PRIVATE);
    Editor editor = prefs.edit();
    editor.remove(PREFS_HISTORY);
    editor.remove(PREFS_HISTORY_INFECTED);

    editor.apply();
    HIVAwarenessActivity.dataChanged();
}