Example usage for android.app AlarmManager setRepeating

List of usage examples for android.app AlarmManager setRepeating

Introduction

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

Prototype

public void setRepeating(@AlarmType int type, long triggerAtMillis, long intervalMillis,
        PendingIntent operation) 

Source Link

Document

Schedule a repeating alarm.

Usage

From source file:org.zywx.wbpalmstar.platform.push.mqttpush.PushGetData2.java

private void startKeepAlives() {
    Intent i = new Intent();
    i.setClass(mCtx, PushService.class);
    i.setAction(CLIENT_ID + ".KEEP_ALIVE");
    PendingIntent pi = PendingIntent.getService(mCtx, 0, i, 0);
    AlarmManager alarmMgr = (AlarmManager) mCtx.getSystemService(Service.ALARM_SERVICE);
    alarmMgr.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + KEEP_ALIVE_INTERVAL,
            KEEP_ALIVE_INTERVAL, pi);//from  w  ww  .  j ava2s  . c  o m
}

From source file:es.uva.tel.gte.cardiomanager.main.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.slide_main);

    // Comprobamos la alarma que nos indica si se ha cerrado o no la aplicacin
    DBAdapter dbAdapter = new DBAdapter(getApplicationContext());
    dbAdapter.open();/*from  w ww  .  j ava  2  s. co  m*/

    boolean alarmUp = isMyServiceRunning(AppService.class);

    if (alarmUp) {
        // No se ha cerrado la aplicacin
        Log.println(Log.ASSERT, "Main Activity", "La alarma estaba activa");
    } else {
        Log.println(Log.ASSERT, "Main Activity", "Activamos alarma");
        // Se ha cerrado la aplicacion
        // Volvemos a poner la alarma
        Intent intent = new Intent(getApplicationContext(), CheckAlarmsService.class);
        PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 123456789, intent,
                PendingIntent.FLAG_UPDATE_CURRENT);
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(System.currentTimeMillis());
        calendar.add(Calendar.YEAR, 1); // Alarma a 1 ao, tiempo suficiente 
        Log.println(Log.ASSERT, "Alarm Created", "Alarm Created");
        AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
        alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), 1000 * 60,
                pendingIntent);
        // Comprobamos ahora cuantos medicamentos no se han tomado
        startService(intent);

    }

    // Instantiate a ViewPager and a PagerAdapter.
    mPager = (ViewPager) findViewById(R.id.pager);
    mPagerAdapter = new ScreenSlidePagerAdapter(getSupportFragmentManager());
    mPager.setAdapter(mPagerAdapter);

    fManager = getSupportFragmentManager();

    Cursor cursor = dbAdapter.fetchAllRows(DBAdapter.TABLE_NAME_POLITICS_ACCEPTED);
    if (cursor.moveToFirst()) {
        if (cursor.getInt(1) == 1 && cursor.getInt(2) == 1) {
            // Accepted
        } else {
            // Mostrar dilogo
            PoliticDialog newFragment = new PoliticDialog();
            newFragment.show(fManager, "Tag");
        }
    } else {
        // Mostrar dilogo
        PoliticDialog newFragment = new PoliticDialog();
        newFragment.show(fManager, "Tag");
    }
    dbAdapter.close();

}

From source file:com.mech.tech.meet.activities.scenario.MainActivity.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override//from  w ww  .  j a v  a 2  s  .c om
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    int currentapiVersion = android.os.Build.VERSION.SDK_INT;
    if (currentapiVersion >= Build.VERSION_CODES.LOLLIPOP) {
        Window window = getWindow();
        window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
        window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        window.setStatusBarColor(getResources().getColor(R.color.material_wala_deep_blue));
    }

    Calendar cal = Calendar.getInstance();
    cal.add(Calendar.SECOND, 10);

    Intent intent = new Intent(this, MyNotificationService.class);
    PendingIntent pintent = PendingIntent.getService(this, 0, intent, 0);
    AlarmManager alarm = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    alarm.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), 36000 * 1000 * 2, pintent);

    startService(new Intent(getBaseContext(), MyNotificationService.class));

    mNavigationDrawerFragment = (NavigationDrawerFragment) getSupportFragmentManager()
            .findFragmentById(R.id.navigation_drawer);
    mTitle = getTitle();

    // Set up the drawer.
    mNavigationDrawerFragment.setUp(R.id.navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout));
}

From source file:org.dodgybits.shuffle.android.server.sync.SyncAlarmService.java

@Override
protected void onHandleIntent(Intent intent) {
    long lastSyncDate = Preferences.getLastSyncLocalDate(this);
    long nextSyncDate = Math.max(System.currentTimeMillis() + 5000L, lastSyncDate + SYNC_PERIOD);

    if (Log.isLoggable(TAG, Log.INFO)) {
        Log.i(TAG, "Next sync at " + new Date(nextSyncDate));
    }/*from  ww w.ja  va2 s .c o m*/

    AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    Intent syncIntent = new Intent(this, SyncAlarmReceiver.class);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, syncIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    alarmManager.setRepeating(AlarmManager.RTC, nextSyncDate, SYNC_PERIOD, pendingIntent);

    // Release the wake lock provided by the WakefulBroadcastReceiver
    WakefulBroadcastReceiver.completeWakefulIntent(intent);
}

From source file:com.ekasoft.promoexito.MyActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(com.ekasoft.promoexito.R.layout.activity_my);

    Settings.set(this, "promo_order", "false");

    if (!Settings.isKey(this, "install")) {
        Calendar cal = Calendar.getInstance();

        Intent intent = new Intent(this, ServiceWithWebView.class);
        PendingIntent pintent = PendingIntent.getService(this, 0, intent, 0);
        AlarmManager alarm = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
        alarm.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), 24 * 60 * 60 * 1000, pintent);
        Intent intent2 = new Intent(MyActivity.this, InstallPromoActivity.class);
        startActivity(intent2);/* ww  w  .  j a  va2s  .  c  o m*/
        finish();
    }

    ActionBar ab = getSupportActionBar();
    ab.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#ffe800")));
    ab.setIcon(com.ekasoft.promoexito.R.drawable.bar);
    ab.setLogo(com.ekasoft.promoexito.R.drawable.bar);
    ab.setDisplayUseLogoEnabled(true);
    ab.setHomeAsUpIndicator(com.ekasoft.promoexito.R.drawable.bar);
    ab.setDisplayHomeAsUpEnabled(true);
    ab.setTitle("");

    ActiveAndroid.initialize(this);

    mAdView = (AdView) findViewById(com.ekasoft.promoexito.R.id.ad_view);
    AdRequest adRequest = new AdRequest.Builder().addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
            //.addTestDevice("4CBD3F38AF88E4EFA5FC4FB8B02D8D73")
            .build();
    mAdView.loadAd(adRequest);

    listPromo = new FragmentListPromo();
    listCategories = new CategorysFragment();

    getSupportFragmentManager().beginTransaction()
            .add(com.ekasoft.promoexito.R.id.fragment_container, listPromo).commit();
}

From source file:com.cpd.receivers.LibraryRenewAlarmBroadcastReceiver.java

public void setAlarm(Context context) {
    Log.d(TAG, "setAlarm() called with: " + "context = [" + context + "]");
    Calendar calendar = Calendar.getInstance();
    calendar.set(Calendar.HOUR_OF_DAY, 12);
    calendar.set(Calendar.MINUTE, 1);
    calendar.set(Calendar.SECOND, 0);

    AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    Intent intent = new Intent(context, LibraryRenewAlarmBroadcastReceiver.class);

    PendingIntent pi = PendingIntent.getBroadcast(context, 1, intent, 0);

    am.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(),
            AlarmManager.INTERVAL_DAY / DAILY_RETRIES, pi);
}

From source file:com.home.pr.opendoor.MainActivity.java

public void schedulePeriodicUpdate() {
    /*final Handler handler = new Handler();
    handler.postDelayed(new Runnable(){//  w w  w  .j av  a 2s. co m
    @Override
    public void run() {
        handler.postDelayed(this,10000);
        Intent intent = new Intent(getApplicationContext(), AdafruitDoorStatus.class);
        getApplicationContext().startService(intent);
    }
    },10000);*/
    Intent intent = new Intent(this, StatusReceiver.class);
    PendingIntent pIntent = PendingIntent.getBroadcast(this, StatusReceiver.REQUEST_CODE, intent, 0);
    long firstMillis = System.currentTimeMillis();
    AlarmManager alarm = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE);
    alarm.setRepeating(AlarmManager.RTC_WAKEUP, firstMillis, 10000, pIntent);
}

From source file:com.senior.javnav.MainActivity.java

@Override
protected void onStop() {
    //Start the service in a timely interval
    SharedPreferences shared = PreferenceManager.getDefaultSharedPreferences(this);
    if (shared.getBoolean("notif", true) && shared.getBoolean("notifiCancelled", true)) {
        //one second * 60 seconds in a minute * 5
        int fiveMinutes = 1000 * 60 * 5;

        //Start the alarm manager service
        SharedPreferences.Editor edit = shared.edit();
        Intent service = new Intent(getApplicationContext(), BroadcastNews.class);
        PendingIntent pendingService = PendingIntent.getBroadcast(getApplicationContext(), 0, service, 0);
        AlarmManager newsUpdate = (AlarmManager) getSystemService(ALARM_SERVICE);

        //Check for the update every 5 minutes
        newsUpdate.setRepeating(AlarmManager.RTC, System.currentTimeMillis(), fiveMinutes, pendingService);
        edit.putBoolean("notifiCancelled", false).commit();
        Log.i("Main", "Alarm set " + shared.getBoolean("notifiCancelled", true));
    }//from   w  w  w .  j av a  2 s  .  c om

    super.onStop();
}

From source file:com.devnoobs.bmr.Powiadomienia.java

public void setAlarm(int h, int m) {
    Calendar calendar = przygotujCzas(h, m);

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

    Intent i = new Intent(S);
    PendingIntent pi = PendingIntent.getBroadcast(c, 0, i, PendingIntent.FLAG_CANCEL_CURRENT);
    IntentFilter intentFilter = new IntentFilter(S);
    Powiadomienia p = new Powiadomienia();
    c.registerReceiver(p, intentFilter);

    am.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), 1000 * 60 * 10, pi); // Millisec * Sec * Min
    //am.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), AlarmManager.INTERVAL_DAY, pi); //   
    showToast("Powiadomienie wlaczone");
}

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);
}