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:com.lewa.crazychapter11.MainActivity.java

public boolean isLewaRom(Context context, Intent alarmIntent) {
    PackageManager pm = context.getPackageManager();
    boolean isLewaRom = true;
    String version = "";
    int versionCode = 0;
    PackageInfo pi = null;/*from  w  ww.  jav a  2 s.co  m*/

    String testsr = null;
    try {
        // com.lewa.permmanager
        // pm.getPackageInfo("com.lewa.deviceactivate",PackageManager.GET_ACTIVITIES);
        pm.getPackageInfo("com.lewa.permmanager", PackageManager.GET_ACTIVITIES);

        pi = pm.getPackageInfo(context.getPackageName(), 0);
        version = pi.versionName;
        versionCode = pi.versionCode;
    } catch (PackageManager.NameNotFoundException e) {
        isLewaRom = false;
    }
    Log.d("algerheMain00", "isLewaRom : " + isLewaRom);
    Log.i("algerheVersion", "versionname=" + version + " \n getPackageName()=" + getPackageName()
            + " \n versioncode=" + versionCode);
    Log.i("algerheStr", "TextUtils.isEmpty(testsr) = " + TextUtils.isEmpty(testsr));
    // Log.i("algerheStr","testsr.length="+testsr.length());

    ///alarm test
    Calendar calendar = Calendar.getInstance();
    calendar.setTimeInMillis(System.currentTimeMillis());
    calendar.set(Calendar.HOUR_OF_DAY, 16);
    calendar.set(Calendar.MINUTE, 0);
    calendar.set(Calendar.SECOND, 0);
    calendar.set(Calendar.MILLISECOND, 0);

    alarmIntent.setAction("com.lewa.alarm.test");
    PendingIntent pipi = PendingIntent.getBroadcast(context, 3359, alarmIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    Log.i("algerheAlarm", "send alarm message in time=" + System.currentTimeMillis());

    // alarmManager.setExact(AlarmManager.RTC_WAKEUP, System.currentTimeMillis()+5000, pipi);

    alarmManager.setExact(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pipi);

    // final Timer timer = new Timer();

    // timer.schedule(new TimerTask() {
    //    @Override
    //    public void run() {
    //       Message msg = new Message();
    //       msg.what = 0x2789;   

    //       handler.sendMessage(msg);

    //       timer.cancel();
    //    }
    // }, 0, 5000);

    return isLewaRom;
}

From source file:com.magnet.mmx.client.MMXClient.java

private static void scheduleWakeupAlarm(Context context, long interval) {
    if (Log.isLoggable(TAG, Log.DEBUG)) {
        Log.d(TAG, "scheduleWakeupAlarm(): called with interval=" + interval);
    }//from   w  w w.  j  ava2s  .  c om
    AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    if (interval > 0) {
        //a time was set
        alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + interval,
                getWakeupIntent(context));
    } else {
        //cancel
        if (Log.isLoggable(TAG, Log.DEBUG)) {
            Log.d(TAG, "scheduleWakeupAlarm(): cancelling alarm");
        }
        alarmManager.cancel(getWakeupIntent(context));
    }
}

From source file:com.nuvolect.deepdive.probe.DecompileApk.java

public JSONObject stopThread(String threadId) {

    THREAD_ID thread = THREAD_ID.valueOf(threadId);
    Thread myThread = null;/*from  w ww. j  a  v  a 2s.com*/

    switch (thread) {

    case unpack_apk:
        myThread = m_unpackApkThread;
        break;
    case dex2jar:
        myThread = m_dex2jarThread;
        break;
    case optimize_dex:
        myThread = m_optimizeDexThread;
        break;
    case cfr:
        myThread = m_cfrThread;
        break;
    case jadx:
        myThread = m_jadxThread;
        break;
    case fern_flower:
        myThread = m_fernThread;
        break;
    default:// do nothing
    }

    //        if( myThread != null){
    //                myThread.currentThread().stop();// deprecated as of API 16 jellybean
    //            myThread.currentThread().interrupt(); // not working, does not stop thread
    //        }

    /**
     * Not the best solution but attempts to selectively stop individual threads do not
     * seem to work. We need need a more robust solution for long running process management.
     */
    Intent mStartActivity = new Intent(m_ctx, com.nuvolect.deepdive.main.MainActivity.class);
    int mPendingIntentId = 123456;
    PendingIntent mPendingIntent = PendingIntent.getActivity(m_ctx, mPendingIntentId, mStartActivity,
            PendingIntent.FLAG_CANCEL_CURRENT);
    AlarmManager mgr = (AlarmManager) m_ctx.getSystemService(Context.ALARM_SERVICE);
    mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 100, mPendingIntent);
    System.exit(0);

    Runtime.getRuntime().exit(0);

    return getStatus();
}

From source file:com.jins_meme.bridge.MainActivity.java

void restart() {
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, getIntent(),
            PendingIntent.FLAG_CANCEL_CURRENT);
    AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    alarmManager.set(AlarmManager.RTC, System.currentTimeMillis() + 500, pendingIntent);

    finishAndRemoveTask();// w ww  .j  av a 2s.  c om
}

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.jav  a  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;

        // 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.android.launcher3.Utilities.java

public static void restart(Context context, int delay) {
    if (delay == 0) {
        delay = 1;/* w ww. j av a2  s  .c  om*/
    }
    Intent restartIntent = context.getPackageManager().getLaunchIntentForPackage(context.getPackageName());
    restartIntent.setFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
    PendingIntent intent = PendingIntent.getActivity(context, 0, restartIntent,
            PendingIntent.FLAG_CANCEL_CURRENT);
    AlarmManager manager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    manager.set(AlarmManager.RTC, java.lang.System.currentTimeMillis() + delay, intent);
    java.lang.System.exit(2);
}

From source file:com.android.exchange.ExchangeService.java

private void clearAlarm(long id) {
    synchronized (mPendingIntents) {
        PendingIntent pi = mPendingIntents.get(id);
        if (pi != null) {
            AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
            alarmManager.cancel(pi);//from w  w w . j a v a 2s  .  c  om
            //log("+Alarm cleared for " + alarmOwner(id));
            mPendingIntents.remove(id);
        }
    }
}

From source file:com.android.exchange.ExchangeService.java

private void setAlarm(long id, long millis) {
    synchronized (mPendingIntents) {
        PendingIntent pi = mPendingIntents.get(id);
        if (pi == null) {
            Intent i = new Intent(this, MailboxAlarmReceiver.class);
            i.putExtra("mailbox", id);
            i.setData(Uri.parse("Box" + id));
            pi = PendingIntent.getBroadcast(this, 0, i, 0);
            mPendingIntents.put(id, pi);

            AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
            alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + millis, pi);
            //log("+Alarm set for " + alarmOwner(id) + ", " + millis/1000 + "s");
        }//from w  w  w.j ava  2  s  . c  om
    }
}

From source file:com.android.exchange.ExchangeService.java

private void clearAlarms() {
    AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    synchronized (mPendingIntents) {
        for (PendingIntent pi : mPendingIntents.values()) {
            alarmManager.cancel(pi);//from w  w  w  .ja  va2 s.  co  m
        }
        mPendingIntents.clear();
    }
}

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

/**
 * Starts the repeating Alarm that sends the fetch Intent.
 *///  w  w 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;
}