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: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();/* ww w .  ja v  a  2 s  .  c om*/
    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: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;
        }/*  w w w .  java2s  . co  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  www  . ja va2  s.  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();
}