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:com.notalenthack.blaster.CommandActivity.java

private void startStatusUpdate() {
    // Setup expiration if we never get a message from the service
    AlarmManager am = (AlarmManager) this.getSystemService(Context.ALARM_SERVICE);
    Intent intent = new Intent();
    intent.setAction(Constants.ACTION_REFRESH_STATUS);
    PendingIntent pi = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    // Set repeating updating of status, will need to cancel if activity is gone
    Calendar cal = Calendar.getInstance();
    am.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), Constants.UPATE_STATUS_PERIOD * 1000, pi);
}

From source file:org.wso2.iot.agent.services.operation.OperationManagerWorkProfile.java

@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
@Override/*from  w w  w  .j av a  2 s.  c o  m*/
public void restrictAccessToApplications(Operation operation) throws AndroidAgentException {
    AppRestriction appRestriction = CommonUtils.getAppRestrictionTypeAndList(operation, getResultBuilder(),
            getContextResources());
    if (Constants.AppRestriction.BLACK_LIST.equals(appRestriction.getRestrictionType())) {
        Intent restrictionIntent = new Intent(getContext(), AppLockService.class);
        restrictionIntent.setAction(Constants.APP_LOCK_SERVICE);

        restrictionIntent.putStringArrayListExtra(Constants.AppRestriction.APP_LIST,
                (ArrayList) appRestriction.getRestrictedList());

        PendingIntent pendingIntent = PendingIntent.getService(getContext(), 0, restrictionIntent,
                PendingIntent.FLAG_UPDATE_CURRENT);

        AlarmManager alarmManager = (AlarmManager) getContext().getSystemService(Context.ALARM_SERVICE);
        Calendar calendar = Calendar.getInstance();
        calendar.setTimeInMillis(System.currentTimeMillis());
        calendar.add(Calendar.SECOND, 1); // First time
        long frequency = 1 * 1000; // In ms
        alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), frequency,
                pendingIntent);

        getContext().startService(restrictionIntent);

    } else if (Constants.AppRestriction.WHITE_LIST.equals(appRestriction.getRestrictionType())) {
        ArrayList appList = (ArrayList) appRestriction.getRestrictedList();
        JSONArray whiteListApps = new JSONArray();
        for (Object appObj : appList) {
            JSONObject app = new JSONObject();
            try {
                app.put(Constants.AppRestriction.PACKAGE_NAME, appObj.toString());
                app.put(Constants.AppRestriction.RESTRICTION_TYPE, Constants.AppRestriction.WHITE_LIST);
                whiteListApps.put(app);
            } catch (JSONException e) {
                operation.setStatus(getContextResources().getString(R.string.operation_value_error));
                operation.setOperationResponse("Error in parsing app white-list payload.");
                getResultBuilder().build(operation);
                throw new AndroidAgentException("Invalid JSON format for app white-list bundle.", e);
            }
        }
        Preference.putString(getContext(), Constants.AppRestriction.WHITE_LIST_APPS, whiteListApps.toString());
        validateInstalledApps();
    }
    operation.setStatus(getContextResources().getString(R.string.operation_value_completed));
    getResultBuilder().build(operation);
}

From source file:com.z3r0byte.magistify.Services.BackgroundService.java

public void setAlarm(Context context) {
    cancelAlarm(context);//from   w  w w  .jav a 2 s. c o m
    AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    Intent intent = new Intent(context, BackgroundService.class);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, 0);
    alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(), 1000 * 60, pendingIntent);
}

From source file:org.wso2.iot.agent.services.operation.OperationManagerBYOD.java

@Override
public void restrictAccessToApplications(Operation operation) throws AndroidAgentException {
    AppRestriction appRestriction = CommonUtils.getAppRestrictionTypeAndList(operation, getResultBuilder(),
            getContextResources());/*from w w w .  ja v a 2s  . c o m*/
    String ownershipType = Preference.getString(getContext(), Constants.DEVICE_TYPE);

    if (Constants.AppRestriction.WHITE_LIST.equals(appRestriction.getRestrictionType())) {
        //Persisting white-listed app list.
        JSONArray whiteListApps = new JSONArray();
        ArrayList appList = (ArrayList) appRestriction.getRestrictedList();
        for (Object appObj : appList) {
            JSONObject app = new JSONObject();
            try {
                app.put(Constants.AppRestriction.PACKAGE_NAME, appObj.toString());
                app.put(Constants.AppRestriction.RESTRICTION_TYPE, Constants.AppRestriction.WHITE_LIST);
                whiteListApps.put(app);
            } catch (JSONException e) {
                operation.setStatus(getContextResources().getString(R.string.operation_value_error));
                operation.setOperationResponse("Error in parsing app white-list payload.");
                getResultBuilder().build(operation);
                throw new AndroidAgentException("Invalid JSON format for app white-list bundle.", e);
            }
        }
        if (Constants.OWNERSHIP_COPE.equals(ownershipType)) {
            //Removing existing non-white-listed apps.
            List<String> installedAppPackages = CommonUtils.getInstalledAppPackages(getContext());
            List<String> toBeHideApps = new ArrayList<>(installedAppPackages);
            toBeHideApps.removeAll(appList);
            for (String packageName : toBeHideApps) {
                CommonUtils.callSystemApp(getContext(), operation.getCode(), "false", packageName);
            }
        }
        Preference.putString(getContext(), Constants.AppRestriction.WHITE_LIST_APPS, whiteListApps.toString());

    } else if (Constants.AppRestriction.BLACK_LIST.equals(appRestriction.getRestrictionType())) {
        if (Constants.OWNERSHIP_BYOD.equals(ownershipType)) {
            Intent restrictionIntent = new Intent(getContext(), AppLockService.class);
            restrictionIntent.setAction(Constants.APP_LOCK_SERVICE);

            restrictionIntent.putStringArrayListExtra(Constants.AppRestriction.APP_LIST,
                    (ArrayList) appRestriction.getRestrictedList());

            PendingIntent pendingIntent = PendingIntent.getService(getContext(), 0, restrictionIntent,
                    PendingIntent.FLAG_UPDATE_CURRENT);

            AlarmManager alarmManager = (AlarmManager) getContext().getSystemService(Context.ALARM_SERVICE);
            Calendar calendar = Calendar.getInstance();
            calendar.setTimeInMillis(System.currentTimeMillis());
            calendar.add(Calendar.SECOND, 1); // First time
            long frequency = 1 * 1000; // In ms
            alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), frequency,
                    pendingIntent);

            getContext().startService(restrictionIntent);
        } else if (Constants.OWNERSHIP_COPE.equals(ownershipType)) {
            for (String packageName : appRestriction.getRestrictedList()) {
                CommonUtils.callSystemApp(getContext(), operation.getCode(), "false", packageName);
            }
        }
    }
    operation.setStatus(getContextResources().getString(R.string.operation_value_completed));
    getResultBuilder().build(operation);
}

From source file:com.concentricsky.android.khanacademy.app.HomeActivity.java

private void setupRepeatingLibraryUpdateAlarm() {
    Log.d(LOG_TAG, "setupRepeatingLibraryUpdateAlarm");
    AlarmManager am = (AlarmManager) getSystemService(Activity.ALARM_SERVICE);

    Intent intent = new Intent(getApplicationContext(), KADataService.class);
    intent.setAction(ACTION_LIBRARY_UPDATE);
    PendingIntent existing = PendingIntent.getService(getApplicationContext(),
            REQUEST_CODE_RECURRING_LIBRARY_UPDATE, intent, PendingIntent.FLAG_NO_CREATE);
    boolean alreadyScheduled = existing != null;

    if (!alreadyScheduled) {
        // Initial delay.
        Calendar cal = Calendar.getInstance();
        cal.add(Calendar.SECOND, UPDATE_DELAY_FROM_FIRST_RUN);

        // Schedule the alarm.
        PendingIntent pendingIntent = PendingIntent.getService(getApplicationContext(),
                REQUEST_CODE_RECURRING_LIBRARY_UPDATE, intent, PendingIntent.FLAG_CANCEL_CURRENT);
        Log.d(LOG_TAG, "(re)setting alarm");
        am.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), AlarmManager.INTERVAL_DAY,
                pendingIntent);/*from   ww w.j  a v  a2  s.  co  m*/
    }
}

From source file:com.first.akashshrivastava.showernow.ShowerActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main_shower_activity);

    /*Launching BootReceiver to test
    Intent playIntent = new Intent(getApplicationContext(), BootReceiver.class);
    startActivity(playIntent);/*  ww  w. j  av a2  s  .c  om*/
    */

    //Mobile ads initialization....The long number is the AdID, can be found on AdMob -  ca-app-pub-8782530512283806/2988799979
    MobileAds.initialize(getApplicationContext(), "ca-app-pub-8782530512283806/2988799979");
    AdView mAdView = (AdView) findViewById(R.id.adView);
    AdRequest adRequest = new AdRequest.Builder().build();
    mAdView.loadAd(adRequest);

    //Facebook SDK initialization...
    FacebookSdk.sdkInitialize(getApplicationContext());
    AppEventsLogger.activateApp(this);

    shareDialog = new ShareDialog(this);

    mDatabaseReference = FirebaseDatabase.getInstance().getReference();
    mFirebaseAuth = FirebaseAuth.getInstance();

    final ImageView genderImage = (ImageView) findViewById(R.id.imageGender);

    guyText = (TextView) findViewById(R.id.guyText);

    topText = (TextView) findViewById(R.id.textView2);

    SharedPreferences prefs = getSharedPreferences("myPrefs", Context.MODE_PRIVATE);

    extraAge = prefs.getInt("age", 0);
    extraFluffiness = prefs.getString("fluffiness", "");
    extraGender = prefs.getString("gender", "");
    extraOldTime = prefs.getLong("time", 0);
    extraSteps = prefs.getFloat("stepsBoot", 0);

    switch (extraGender) {
    case "male":
        genderImage.setImageResource(R.drawable.male_white_outline);
        break;
    case "female":
        genderImage.setImageResource(R.drawable.female_white_outline);
        break;
    case "other":
        genderImage.setImageResource(R.drawable.other_white_outline);
        break;
    }

    genderImage.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) { //set alarm
            //Swith ccase
            switch (event.getAction()) {

            case MotionEvent.ACTION_UP:
                // PRESSED ..PRESSED

                if (genderImage.getDrawable().getConstantState() == getResources()
                        .getDrawable(R.drawable.female_white_outline_pressed).getConstantState()) {
                    genderImage.setImageResource(R.drawable.female_white_outline);
                } else if (genderImage.getDrawable().getConstantState() == getResources()
                        .getDrawable(R.drawable.male_white_outline_pressed).getConstantState()) {
                    genderImage.setImageResource(R.drawable.male_white_outline);
                } else if (genderImage.getDrawable().getConstantState() == getResources()
                        .getDrawable(R.drawable.other_white_outline_pressed).getConstantState()) {
                    genderImage.setImageResource(R.drawable.other_white_outline);
                }

                //Resets the wave after shower..this is not getting called for some reason....
                waveProgressbar.setCurrent(0, "");
                guyText.setText("0 %");
                waveProgressbar.setVisibility(View.INVISIBLE);

                topText.setText("You have showered! \n When the wave hits 100% its time for your next shower ");

                if (fluffiness != null && gotSteps) {
                    Calendar cal = Calendar.getInstance();
                    Intent activate = new Intent(ShowerActivity.this, AlarmReceiver.class);
                    activate.putExtra("age", age);
                    activate.putExtra("fluffiness", fluffiness);
                    activate.putExtra("gender", gender);
                    activate.putExtra("steps", steps);
                    activate.putExtra("time", System.currentTimeMillis());

                    AlarmManager alarms;
                    PendingIntent alarmIntent = PendingIntent.getBroadcast(ShowerActivity.this, 0, activate,
                            FLAG_CANCEL_CURRENT);
                    alarms = (AlarmManager) getSystemService(ALARM_SERVICE);
                    alarms.cancel(alarmIntent);

                    alarms.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis() + 5000, 1000 * 60,
                            alarmIntent);//sets the alarm

                    mDatabaseReference.child("User").child(mFirebaseAuth.getCurrentUser().getUid())
                            .child("Steps").setValue(steps);//sets old steps
                    oldSteps = steps;
                    mDatabaseReference.child("User").child(mFirebaseAuth.getCurrentUser().getUid())
                            .child("Time").setValue(System.currentTimeMillis());
                    oldTime = System.currentTimeMillis();
                    newUser = false;

                    SharedPreferences sharedPref = getSharedPreferences("myPrefs", Context.MODE_PRIVATE);
                    SharedPreferences.Editor editor = sharedPref.edit();
                    editor.putInt("age", age);
                    editor.putString("fluffiness", fluffiness);
                    editor.putString("gender", gender);
                    editor.putFloat("steps", steps);
                    editor.putLong("time", System.currentTimeMillis());
                    editor.putFloat("stepsBoot", 0);
                    editor.putBoolean("bootStart", true);
                    editor.apply();

                } else if (!gotSteps) {
                    Toast.makeText(getApplicationContext(), "Waiting for steps", Toast.LENGTH_SHORT).show();
                }
                return true; // if you want to handle the touch event

            case MotionEvent.ACTION_DOWN:
                // RELEASED..RELEASED..

                if (genderImage.getDrawable().getConstantState() == getResources()
                        .getDrawable(R.drawable.female_white_outline).getConstantState()) {
                    genderImage.setImageResource(R.drawable.female_white_outline_pressed);

                } else if (genderImage.getDrawable().getConstantState() == getResources()
                        .getDrawable(R.drawable.male_white_outline).getConstantState()) {
                    genderImage.setImageResource(R.drawable.male_white_outline_pressed);

                } else if (genderImage.getDrawable().getConstantState() == getResources()
                        .getDrawable(R.drawable.other_white_outline).getConstantState()) {
                    genderImage.setImageResource(R.drawable.other_white_outline_pressed);

                }

                return true; // if you want to handle the touch event
            }
            //Switch case end bracket

            return false;
        }

    });

    createWave();
    setMenuColor();
    setupStepcount();
    setWaveHeight();

    FloatingActionButton editDetails = (FloatingActionButton) findViewById(R.id.menu_item4); //edit user information. Goes to main activity
    editDetails.setOnClickListener(new View.OnClickListener() {

        public void onClick(View v) {

            /*
            Fragment fragment = new Fragment();
            FragmentTransaction transaction = manager.beginTransaction();
            transaction.add(ShowerActivity.java);
            transaction.addToBackStack(ShowerActivity.java);
            transaction.commit();
                    
            */
            //Fragment B at pos 2 should open when edit details is pressed..
            Intent i = new Intent(ShowerActivity.this, MainActivity.class);
            i.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
            startActivity(i);
        }
    });

    FloatingActionButton fabmenuDeleteAccount = (FloatingActionButton) findViewById(R.id.delete_Account);
    fabmenuDeleteAccount.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            dialog();
        }
    });

    FloatingActionButton fabMenuItem1 = (FloatingActionButton) findViewById(R.id.menu_item);
    fabMenuItem1.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            /*ComponentName receiver = new ComponentName(ShowerActivity.this, AlarmReceiver.class); // alarms.cancel(alarmIntent);??
            PackageManager pm = ShowerActivity.this.getPackageManager();
            pm.setComponentEnabledSetting(receiver,
                PackageManager.COMPONENT_ENABLED_STATE_DISABLED,
                PackageManager.DONT_KILL_APP);
                    
            stopService(new Intent(StepCountService.STEP_COUNT_SERVICE));*/

            //mFirebaseAuth.getCurrentUser().getUid() =null;

            SharedPreferences sharedPref = getSharedPreferences("myPrefs", Context.MODE_PRIVATE);
            SharedPreferences.Editor editor = sharedPref.edit();
            editor.putInt("age", 0);
            editor.putString("fluffiness", "");
            editor.putString("gender", "");
            editor.putFloat("steps", 0);
            editor.putLong("time", 0);
            editor.putFloat("stepsBoot", 0);
            editor.putBoolean("bootStart", false);
            editor.apply();

            Intent activate = new Intent(ShowerActivity.this, AlarmReceiver.class);
            PendingIntent alarmIntent = PendingIntent.getBroadcast(ShowerActivity.this, 0, activate,
                    FLAG_CANCEL_CURRENT);

            AlarmManager alarms = (AlarmManager) getSystemService(ALARM_SERVICE);
            alarms.cancel(alarmIntent);

            stopService(new Intent(ShowerActivity.this, StepCountService.class));

            mFirebaseAuth.getInstance().signOut();
            Intent i = new Intent(ShowerActivity.this, LoginActivity.class);
            startActivity(i);
        }
    });

    final FloatingActionButton shareButton = (FloatingActionButton) findViewById(R.id.shareButton);
    shareButton.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {

            Intent shareIntent = new Intent(Intent.ACTION_SEND);
            shareIntent.setType("text/plain");
            String shareBody = "Check out this showering app at: https://play.google.com/store/apps/details?id=com.first.akashshrivastava.showernow \n";
            String shareSubString = "An app that tells you when you should shower and apparently keeps you clean";
            shareIntent.putExtra(Intent.EXTRA_SUBJECT, shareSubString);
            shareIntent.putExtra(Intent.EXTRA_TEXT, shareBody);
            startActivity(Intent.createChooser(shareIntent, " Share using the following"));

        }
    });

    mDatabaseReference.addListenerForSingleValueEvent(new ValueEventListener() {
        @Override
        public void onDataChange(DataSnapshot snap) {

            try {
                if ((!(mFirebaseAuth.getCurrentUser().getUid().isEmpty()))
                        && snap.child("User").child(mFirebaseAuth.getCurrentUser().getUid()).child("gender")
                                .getValue().toString().equalsIgnoreCase("female")) {
                    genderImage.setImageResource(R.drawable.female_white_outline);
                } else if (snap.child("User").child(mFirebaseAuth.getCurrentUser().getUid()).child("gender")
                        .getValue().toString().equalsIgnoreCase("male")) {
                    genderImage.setImageResource(R.drawable.male_white_outline);
                } else if (snap.child("User").child(mFirebaseAuth.getCurrentUser().getUid()).child("gender")
                        .getValue().toString().equalsIgnoreCase("other")) {
                    genderImage.setImageResource(R.drawable.other_white_outline);
                }

            } catch (Exception e) {
                e.printStackTrace();
            }
            age = Integer.parseInt(snap.child("User").child(mFirebaseAuth.getCurrentUser().getUid())
                    .child("Age").getValue().toString());//gotta get int

            fluffiness = snap.child("User").child(mFirebaseAuth.getCurrentUser().getUid()).child("gender")
                    .getValue().toString();
            gender = snap.child("User").child(mFirebaseAuth.getCurrentUser().getUid()).child("gender")
                    .getValue().toString();

            if (snap.child("User").child(mFirebaseAuth.getCurrentUser().getUid()).child("Time").exists()) {
                oldTime = snap.child("User").child(mFirebaseAuth.getCurrentUser().getUid()).child("Time")
                        .getValue(Long.class);
                oldSteps = snap.child("User").child(mFirebaseAuth.getCurrentUser().getUid()).child("Steps")
                        .getValue(float.class);

            } else {
                newUser = true;
            }
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {

        }
    });
}

From source file:com.near.chimerarevo.fragments.SettingsFragment.java

private void setAlarm(int sel, boolean isEnabled) {
    Intent intent = new Intent(getActivity().getApplicationContext(), NewsService.class);
    PendingIntent pintent = PendingIntent.getService(getActivity().getApplicationContext(), 0, intent, 0);
    AlarmManager alarm = (AlarmManager) getActivity().getSystemService(Context.ALARM_SERVICE);

    alarm.cancel(pintent);/*from  ww w.j  a va 2s .  c o m*/

    if (isEnabled) {
        long delay;
        switch (sel) {
        case 0:
            delay = AlarmManager.INTERVAL_FIFTEEN_MINUTES;
            break;
        case 1:
            delay = AlarmManager.INTERVAL_HALF_HOUR;
            break;
        case 2:
            delay = AlarmManager.INTERVAL_HOUR;
            break;
        case 3:
            delay = 2 * AlarmManager.INTERVAL_HOUR;
            break;
        case 4:
            delay = 3 * AlarmManager.INTERVAL_HOUR;
            break;
        case 5:
            delay = 6 * AlarmManager.INTERVAL_HOUR;
            break;
        case 6:
            delay = AlarmManager.INTERVAL_HALF_DAY;
            break;
        case 7:
            delay = AlarmManager.INTERVAL_DAY;
            break;
        default:
            delay = AlarmManager.INTERVAL_HOUR;
            break;
        }

        alarm.setRepeating(AlarmManager.ELAPSED_REALTIME_WAKEUP, SystemClock.uptimeMillis(), delay, pintent);
    }
}

From source file:org.apps8os.motivator.ui.MainActivity.java

/**
 * Set the notifications for the first time. After this, the notifications are controlled from the settings activity.
 *///from  w ww .j a v  a2 s.  c o m
public void setNotifications() {
    // Set up notifying user to answer to the mood question
    // The time to notify the user
    Calendar notificationTime = Calendar.getInstance();
    notificationTime.set(Calendar.MINUTE, 0);
    notificationTime.set(Calendar.SECOND, 0);
    // An alarm manager for scheduling notifications
    AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    // Set the notification to repeat over the given time at notificationTime
    Intent notificationIntent = new Intent(this, NotificationService.class);
    notificationIntent.putExtra(NotificationService.NOTIFICATION_TYPE, NotificationService.NOTIFICATION_MOOD);
    PendingIntent pendingNotificationIntent = PendingIntent.getService(this, 0, notificationIntent,
            PendingIntent.FLAG_CANCEL_CURRENT);
    alarmManager.cancel(pendingNotificationIntent);
    if (notificationTime.get(Calendar.HOUR_OF_DAY) >= 10) {
        notificationTime.add(Calendar.DATE, 1);
    }
    notificationTime.set(Calendar.HOUR_OF_DAY, 10);
    alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, notificationTime.getTimeInMillis(),
            AlarmManager.INTERVAL_DAY, pendingNotificationIntent);

    /** Commented out for now, setting different times for the notifications.
    if (mTimeToNotify == getString(R.string.in_the_morning_value)) {
       if (notificationTime.get(Calendar.HOUR_OF_DAY) >= 10) {
    notificationTime.add(Calendar.DATE, 1);
       }
       notificationTime.set(Calendar.HOUR_OF_DAY, 10);
       alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, notificationTime.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingNotificationIntent);
    } else if (mTimeToNotify == getString(R.string.morning_and_evening_value)) {
       if (notificationTime.get(Calendar.HOUR_OF_DAY) >= 10 && notificationTime.get(Calendar.HOUR_OF_DAY) < 22) {
    notificationTime.set(Calendar.HOUR_OF_DAY, 22);
       } else if (notificationTime.get(Calendar.HOUR_OF_DAY) < 10) {
    notificationTime.set(Calendar.HOUR_OF_DAY, 10);
       } else {
    notificationTime.add(Calendar.DATE, 1);
    notificationTime.set(Calendar.HOUR_OF_DAY, 10);
       }
       alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, notificationTime.getTimeInMillis(), AlarmManager.INTERVAL_HALF_DAY, pendingNotificationIntent);
    } else if (mTimeToNotify == getString(R.string.every_hour_value)) {
       notificationTime.add(Calendar.HOUR_OF_DAY, 1);
       alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, notificationTime.getTimeInMillis(), AlarmManager.INTERVAL_HOUR, pendingNotificationIntent);
    }
    **/
}

From source file:de.domjos.schooltools.activities.MainActivity.java

private void initServices() {
    try {//from  w w w  .j a  v  a  2  s.  c  om
        if (MainActivity.globals.getUserSettings().isNotificationsShown()) {
            // init Memory Service
            Intent intent = new Intent(this.getApplicationContext(), MemoryService.class);
            PendingIntent pendingIntent1 = PendingIntent.getService(this.getApplicationContext(), 0, intent, 0);

            // init frequently
            AlarmManager alarmManager1 = (AlarmManager) this.getApplicationContext()
                    .getSystemService(Context.ALARM_SERVICE);
            long frequency = 8 * 60 * 60 * 1000;
            assert alarmManager1 != null;
            alarmManager1.setRepeating(AlarmManager.RTC_WAKEUP, Calendar.getInstance().getTimeInMillis(),
                    frequency, pendingIntent1);
        }
    } catch (Exception ex) {
        Helper.printException(this.getApplicationContext(), ex);
    }
}

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);//  ww w.jav  a 2  s. co  m

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