Example usage for android.app AlarmManager RTC_WAKEUP

List of usage examples for android.app AlarmManager RTC_WAKEUP

Introduction

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

Prototype

int RTC_WAKEUP

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

Click Source Link

Document

Alarm time in System#currentTimeMillis System.currentTimeMillis() (wall clock time in UTC), which will wake up the device when it goes off.

Usage

From source file:com.jay.pea.mhealthapp2.utilityClasses.AlarmReceiver.java

public void SetAlarm(Context context) {
    AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    Intent intent = new Intent(context, AlarmReceiver.class);
    intent.putExtra(ONE_TIME, Boolean.FALSE);
    PendingIntent pi = PendingIntent.getBroadcast(context, 0, intent, 0);
    //After after 30 seconds
    am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), 1000 * 5, pi);
}

From source file:com.windroilla.invoker.gcm.MyGcmListenerService.java

/**
 * Called when message is received.//from w  ww. j av a 2  s .  c  om
 *
 * @param from SenderID of the sender.
 * @param data Data bundle containing message data as key/value pairs.
 *             For Set of keys use data.keySet().
 */
// [START receive_message]
@Override
public void onMessageReceived(String from, Bundle data) {
    String message = data.getString("message");
    Log.d(TAG, "From: " + from);
    Log.d(TAG, "Message: " + message);

    if (from.startsWith("/topics/")) {
        // message received from some topic.
    } else {
        Log.i("Device ID ", deviceID);
        // normal downstream message.
        apiService.getBlockTimes(new RequestBlockTimes(deviceID)).subscribeOn(Schedulers.newThread())
                .observeOn(Schedulers.newThread()).subscribe(new Action1<BlockTimeList>() {
                    @Override
                    public void call(BlockTimeList blockTimeList) {
                        Log.d(TAG, blockTimeList.access_time);
                        Vector<ContentValues> cVVector = new Vector<ContentValues>(
                                blockTimeList.getBlockTimes().size());
                        AlarmManager mgrAlarm = (AlarmManager) getApplicationContext()
                                .getSystemService(ALARM_SERVICE);
                        ArrayList<PendingIntent> intentArray = new ArrayList<PendingIntent>();
                        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                        formatter.setLenient(false);

                        for (int i = 0; i < blockTimeList.getBlockTimes().size(); i++) {
                            BlockTime blockTime = blockTimeList.getBlockTimes().get(i);
                            Log.d(TAG,
                                    blockTime.getCourse_id() + " " + blockTime.getId() + " "
                                            + blockTime.getStarttime() + " " + blockTime.getEndtime() + " "
                                            + blockTime.getCreated_time());
                            ContentValues blockTimeValues = new ContentValues();
                            blockTimeValues.put(BlocktimeContract.BlocktimeEntry.COLUMN_START_TIME,
                                    blockTime.getStarttime());
                            blockTimeValues.put(BlocktimeContract.BlocktimeEntry.COLUMN_END_TIME,
                                    blockTime.getEndtime());
                            blockTimeValues.put(BlocktimeContract.BlocktimeEntry.COLUMN_CREATED_TIME,
                                    blockTime.getCreated_time());
                            Intent startIntent = new Intent(getBaseContext(), AlarmReceiver.class);
                            startIntent.setAction("com.windroilla.invoker.blockservice.start");
                            Intent endIntent = new Intent(getBaseContext(), AlarmReceiver.class);
                            endIntent.setAction("com.windroilla.invoker.blockservice.stop");
                            PendingIntent pendingStartIntent = PendingIntent.getBroadcast(
                                    getApplicationContext(), blockTime.getId(), startIntent,
                                    PendingIntent.FLAG_UPDATE_CURRENT);
                            PendingIntent pendingEndIntent = PendingIntent.getBroadcast(getApplicationContext(),
                                    -blockTime.getId(), endIntent, PendingIntent.FLAG_UPDATE_CURRENT);
                            try {
                                mgrAlarm.set(AlarmManager.RTC_WAKEUP,
                                        formatter.parse(blockTime.getStarttime()).getTime(),
                                        pendingStartIntent);
                                Log.d(TAG,
                                        formatter.parse(blockTime.getStarttime()).getTime() + " "
                                                + System.currentTimeMillis() + " "
                                                + (formatter.parse(blockTime.getStarttime()).getTime()
                                                        - System.currentTimeMillis()));
                                Log.d(TAG,
                                        formatter.parse(blockTime.getEndtime()).getTime() + " "
                                                + System.currentTimeMillis() + " "
                                                + (formatter.parse(blockTime.getEndtime()).getTime()
                                                        - System.currentTimeMillis()));
                                mgrAlarm.set(AlarmManager.RTC_WAKEUP,
                                        formatter.parse(blockTime.getEndtime()).getTime(), pendingEndIntent);
                            } catch (ParseException e) {
                                Log.e(TAG, e.toString());
                            }
                            intentArray.add(pendingStartIntent);
                            intentArray.add(pendingEndIntent);
                            cVVector.add(blockTimeValues);
                        }
                        Log.d(TAG, intentArray.size() + " PendingIntents have been progressed");
                        int inserted = 0;
                        // add to database
                        if (cVVector.size() > 0) {
                            ContentValues[] cvArray = new ContentValues[cVVector.size()];
                            cVVector.toArray(cvArray);
                            getBaseContext().getContentResolver()
                                    .bulkInsert(BlocktimeContract.BlocktimeEntry.CONTENT_URI, cvArray);
                        }

                    }
                }, new Action1<Throwable>() {
                    @Override
                    public void call(Throwable throwable) {
                        Log.e(TAG, "BlockTimes Sync failed! " + throwable);
                    }
                });

    }

    // [START_EXCLUDE]
    /**
     * Production applications would usually process the message here.
     * Eg: - Syncing with server.
     *     - Store message in local database.
     *     - Update UI.
     */

    /**
     * In some cases it may be useful to show a notification indicating to the user
     * that a message was received.
     */
    sendNotification(message);
    // [END_EXCLUDE]
}

From source file:it.gulch.linuxday.android.services.AlarmIntentService.java

private void addBookmark(Intent intent) {
    long delay = getDelay();
    long eventId = intent.getLongExtra(ExtraConstants.EXTRA_EVENT_ID, -1L);
    long startTime = intent.getLongExtra(ExtraConstants.EXTRA_EVENT_START_TIME, -1L);

    // Only schedule future events. If they start before the delay, the alarm will go off immediately
    if ((startTime == -1L) || (startTime < System.currentTimeMillis())) {
        return;/*w w w.  jav  a 2s. com*/
    }

    alarmManager.set(AlarmManager.RTC_WAKEUP, startTime - delay, getAlarmPendingIntent(eventId));
}

From source file:com.example.ireviewr.MainActivity.java

@Override
protected void onResume() {
    // TODO Auto-generated method stub
    super.onResume();

    //da postavi naziv korisnika
    setUpUserName();//  w ww . j a v a  2s  .  c  o  m

    //Za slucaj da referenca nije postavljena da se izbegne problem sa androidom!
    if (manager == null) {
        setUpReceiver();
    }

    if (allowSync) {
        int interval = ReviewerTools.calculateTimeTillNextSync(Integer.parseInt(synctime));
        manager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), interval, pendingIntent);
        //Toast.makeText(this, "Alarm Set", Toast.LENGTH_SHORT).show();
    }

    IntentFilter filter = new IntentFilter();
    filter.addAction(NEW_COMMENTS);
    filter.addAction(SYNC_DATA);

    registerReceiver(sync, filter);
}

From source file:ca.etsmtl.applets.etsmobile.NewsListActivity.java

private void setAlarm() {
    final Intent toAlarm = new Intent(this, NewsAlarmReceiver.class);
    final PendingIntent toDownload = PendingIntent.getBroadcast(this, 0, toAlarm,
            PendingIntent.FLAG_CANCEL_CURRENT);
    final AlarmManager alarms = (AlarmManager) getSystemService(Context.ALARM_SERVICE);

    final Calendar updateTime = Calendar.getInstance();
    updateTime.setTimeZone(TimeZone.getTimeZone("GMT"));

    updateTime.set(Calendar.HOUR_OF_DAY, 6);
    updateTime.set(Calendar.MINUTE, 00);
    alarms.setInexactRepeating(AlarmManager.RTC_WAKEUP, updateTime.getTimeInMillis(), AlarmManager.INTERVAL_DAY,
            toDownload);//  ww  w  . j  a  v  a  2s . c  o  m

    updateTime.set(Calendar.HOUR_OF_DAY, 12);
    alarms.setInexactRepeating(AlarmManager.RTC_WAKEUP, updateTime.getTimeInMillis(), AlarmManager.INTERVAL_DAY,
            toDownload);

    updateTime.set(Calendar.HOUR_OF_DAY, 18);
    alarms.setInexactRepeating(AlarmManager.RTC_WAKEUP, updateTime.getTimeInMillis(), AlarmManager.INTERVAL_DAY,
            toDownload);
}

From source file:org.leopub.mat.service.MessageService.java

public static void setUpdate(int latency, int period) {
    Context context = MyApplication.getAppContext();
    Logger.i(TAG, "setUpdate latency:" + latency + ", period:" + period);
    Intent i = new Intent(context, MessageService.class);
    PendingIntent pi = PendingIntent.getService(context, 0, i, PendingIntent.FLAG_UPDATE_CURRENT);

    AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);

    if (period > 0) {
        alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + latency * 60 * 1000,
                period * 60 * 1000, pi);
    } else {/*  ww  w  .  ja  v a  2  s .  co  m*/
        alarmManager.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + latency * 60 * 1000, pi);
    }
    Logger.i(TAG, "setUpdate Done");
}

From source file:com.shinymetal.gradereport.AbstractActivity.java

protected void setRecurringAlarm(Context context, boolean force) {

    boolean alarmUp = (PendingIntent.getBroadcast(context, 0, new Intent(context, AlarmReceiver.class),
            PendingIntent.FLAG_NO_CREATE) != null);

    if (alarmUp && !force)
        return;// www  . jav  a 2  s. c om

    Intent downloader = new Intent(context, AlarmReceiver.class);
    downloader.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);

    PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, downloader,
            PendingIntent.FLAG_UPDATE_CURRENT);

    AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);

    Date firstRun = new Date();
    long mSyncInterval = Long.parseLong(PreferenceManager.getDefaultSharedPreferences(this)
            .getString(getString(R.string.pref_sync_key), "15")) * 60000;

    alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, firstRun.getTime() + 10, mSyncInterval, pendingIntent);

    if (BuildConfig.DEBUG)
        Log.d(this.toString(), TS.get() + this.toString() + " Set alarmManager.setRepeating to: "
                + firstRun.toString() + " interval: " + mSyncInterval);
}

From source file:com.njlabs.amrita.aid.landing.Landing.java

@SuppressLint("ShortAlarm")
@Override//from  w  w  w.j  a v  a 2 s .c o m
public void init(Bundle savedInstanceState) {
    setupLayout(R.layout.activity_landing, "Amrita Info Desk");
    toolbar.setBackgroundColor(getResources().getColor(R.color.white));
    setRecentHeaderColor(getResources().getColor(R.color.white));
    checkForUpdates();

    AccountHeader headerResult = new AccountHeaderBuilder().withActivity(this)
            .withHeaderBackground(R.drawable.header)
            .addProfiles(new ProfileDrawerItem().withName("Amrita Info Desk")
                    .withEmail("Version " + BuildConfig.VERSION_NAME).setSelectable(false))
            .withSelectionListEnabledForSingleProfile(false).build();

    headerResult.getHeaderBackgroundView().setColorFilter(Color.rgb(170, 170, 170),
            android.graphics.PorterDuff.Mode.MULTIPLY);
    Drawer result = new DrawerBuilder().withActivity(this).withToolbar(toolbar).withAccountHeader(headerResult)
            .addDrawerItems(
                    new PrimaryDrawerItem().withName("Home").withIcon(R.drawable.ic_action_home)
                            .withCheckable(false),
                    new PrimaryDrawerItem()
                            .withName("News").withIcon(R.drawable.ic_action_speaker_notes).withCheckable(false),
                    new DividerDrawerItem(),
                    new PrimaryDrawerItem().withName("About the app").withIcon(R.drawable.ic_action_info)
                            .withCheckable(false),
                    new PrimaryDrawerItem().withName("Invite").withIcon(R.drawable.ic_action_info)
                            .withCheckable(false),
                    new PrimaryDrawerItem().withName("Settings").withIcon(R.drawable.ic_action_settings)
                            .withCheckable(false))
            .withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
                @Override
                public boolean onItemClick(AdapterView<?> parent, View view, int position, long id,
                        IDrawerItem drawerItem) {
                    switch (position) {
                    case 1:
                        startActivity(new Intent(baseContext, NewsActivity.class));
                        break;
                    case 3:
                        startActivity(new Intent(baseContext, App.class));
                        break;
                    case 4:
                        Intent intent = new AppInviteInvitation.IntentBuilder("Invite users")
                                .setMessage("Spread the word to fellow Amrititans")
                                .setCallToActionText("Invite").build();
                        startActivityForResult(intent, 211);
                        break;
                    case 5:
                        startActivity(new Intent(baseContext, SettingsActivity.class));
                        break;
                    }
                    return false;
                }
            }).withCloseOnClick(true).build();

    setupGrid();

    File aumsCookieFile = new File(getApplicationContext().getFilesDir().getParent() + "/shared_prefs/"
            + PersistentCookieStore.AUMS_COOKIE_PREFS + ".xml");
    if (aumsCookieFile.exists()) {
        aumsCookieFile.delete();
    }

    File gpmsCookieFile = new File(getApplicationContext().getFilesDir().getParent() + "/shared_prefs/"
            + PersistentCookieStore.GPMS_COOKIE_PREFS + ".xml");
    if (gpmsCookieFile.exists()) {
        gpmsCookieFile.delete();
    }

    AlarmManager alarm = (AlarmManager) getSystemService(ALARM_SERVICE);
    alarm.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + (1000 * 60 * 60 * 6),
            PendingIntent.getService(this, 0, new Intent(this, NewsUpdateService.class), 0));

    startService(new Intent(baseContext, NewsUpdateService.class));
}

From source file:com.groundupworks.wings.core.WingsService.java

/**
 * Schedules an alarm to start the {@link WingsService}.
 *
 * @param context the {@link Context}./* ww w . java 2s  .  c  om*/
 * @param delay   how far in the future to schedule the alarm.
 */
static void scheduleWingsService(Context context, long delay) {
    Context appContext = context.getApplicationContext();

    // Create pending intent.
    Intent intent = new Intent(appContext, AlarmReceiver.class);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(appContext, 0, intent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    // Set alarm.
    AlarmManager alarmManager = (AlarmManager) appContext.getSystemService(Context.ALARM_SERVICE);
    alarmManager.set(AlarmManager.RTC_WAKEUP, delay, pendingIntent);
}

From source file:com.aafr.alfonso.sunshine.app.ForecastFragment.java

private void updateWeather() {
    Intent alarmIntent = new Intent(getActivity(), SunshineService.AlarmReceiver.class);
    alarmIntent.putExtra(SunshineService.LOCATION_QUERY_EXTRA, Utility.getPreferredLocation(getActivity()));

    //Wrap in a pending intent which only fires once.
    PendingIntent pi = PendingIntent.getBroadcast(getActivity(), 0, alarmIntent, PendingIntent.FLAG_ONE_SHOT);//getBroadcast(context, 0, i, 0);

    AlarmManager am = (AlarmManager) getActivity().getSystemService(Context.ALARM_SERVICE);

    //Set the AlarmManager to wake up the system.
    am.set(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + 5000, pi);
}