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.meetingcpp.sched.service.SessionAlarmService.java

private void scheduleAlarm(final long sessionStart, final long sessionEnd, final long alarmOffset) {

    NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    nm.cancel(NOTIFICATION_ID);/*from  ww w. j  av a  2s.co  m*/
    final long currentTime = UIUtils.getCurrentTime(this);
    // If the session is already started, do not schedule system notification.
    if (currentTime > sessionStart) {
        LOGD(TAG, "Not scheduling alarm because target time is in the past: " + sessionStart);
        return;
    }

    // By default, sets alarm to go off at 10 minutes before session start time.  If alarm
    // offset is provided, alarm is set to go off by that much time from now.
    long alarmTime;
    if (alarmOffset == UNDEFINED_ALARM_OFFSET) {
        alarmTime = sessionStart - MILLI_TEN_MINUTES;
    } else {
        alarmTime = currentTime + alarmOffset;
    }

    LOGD(TAG, "Scheduling alarm for " + alarmTime + " = " + (new Date(alarmTime)).toString());

    final Intent notifIntent = new Intent(ACTION_NOTIFY_SESSION, null, this, SessionAlarmService.class);
    // Setting data to ensure intent's uniqueness for different session start times.
    notifIntent.setData(
            new Uri.Builder().authority("com.meetingcpp.sched").path(String.valueOf(sessionStart)).build());
    notifIntent.putExtra(SessionAlarmService.EXTRA_SESSION_START, sessionStart);
    LOGD(TAG, "-> Intent extra: session start " + sessionStart);
    notifIntent.putExtra(SessionAlarmService.EXTRA_SESSION_END, sessionEnd);
    LOGD(TAG, "-> Intent extra: session end " + sessionEnd);
    notifIntent.putExtra(SessionAlarmService.EXTRA_SESSION_ALARM_OFFSET, alarmOffset);
    LOGD(TAG, "-> Intent extra: session alarm offset " + alarmOffset);
    PendingIntent pi = PendingIntent.getService(this, 0, notifIntent, PendingIntent.FLAG_CANCEL_CURRENT);
    final AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    // Schedule an alarm to be fired to notify user of added sessions are about to begin.
    LOGD(TAG, "-> Scheduling RTC_WAKEUP alarm at " + alarmTime);
    am.set(AlarmManager.RTC_WAKEUP, alarmTime, pi);
}

From source file:com.swetha.easypark.GetIndividualParkingSpotDetails.java

private void scheduleNotification(Notification notification) {

    Intent notificationIntent = new Intent(this, NotificationPublisher.class);
    notificationIntent.putExtra(NotificationPublisher.NOTIFICATION_ID, Integer.parseInt(theParkingSpotId));
    notificationIntent.putExtra(NotificationPublisher.NOTIFICATION, notification);
    PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, notificationIntent,
            PendingIntent.FLAG_UPDATE_CURRENT);

    long currentTimeInLong = DateTimeHelpers
            .convertToLongFromTime(DateTimeHelpers.dtf.format(new Date()).toString());
    long delay = toTime - (currentTimeInLong + Constants.tenMinutesInMilliseconds);
    long futureInMills = SystemClock.elapsedRealtime() + delay;

    Log.i("GetIndividualParkingSpotDetails", " Spot has been blocked till long " + toTime);
    Log.i("GetIndividualParkingSpotDetails",
            " Spot has been blocked till  DateTime" + DateTimeHelpers.convertToTimeFromLong(toTime));

    Log.i("GetIndividualParkingSpotDetails", " CurrentTime in  long " + currentTimeInLong);
    Log.i("GetIndividualParkingSpotDetails",
            " Spot has been blocked till  DateTime" + DateTimeHelpers.convertToTimeFromLong(currentTimeInLong));

    Log.i("GetIndividualParkingSpotDetails", "value of delay" + delay);
    Log.i("GetIndividualParkingSpotDetails",
            "value of mills in time" + DateTimeHelpers.convertToTimeFromLong(futureInMills));

    Log.i("GetIndividualParkingSpotDetails", "Notification is kept at this mills" + futureInMills);
    AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    alarmManager.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, futureInMills, pendingIntent);

}

From source file:com.granita.tasks.notification.NotificationActionUtils.java

/**
 * Registers a timeout for the undo notification such that when it expires, the undo bar will disappear, and the action will be performed.
 *///from  w  ww . ja  v a2s .  c o m
public static void registerUndoTimeout(final Context context, final NotificationAction notificationAction) {

    if (sUndoTimeoutMillis == -1) {
        sUndoTimeoutMillis = TIMEOUT_MILLIS;
    }

    final AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
    final long triggerAtMills = SystemClock.elapsedRealtime() + sUndoTimeoutMillis;
    final PendingIntent pendingIntent = createUndoTimeoutPendingIntent(context, notificationAction);
    alarmManager.set(AlarmManager.ELAPSED_REALTIME, triggerAtMills, pendingIntent);
}

From source file:com.ncode.android.apps.schedo.service.SessionAlarmService.java

private void scheduleAlarm(final long sessionStart, final long sessionEnd, final long alarmOffset) {

    NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    nm.cancel(NOTIFICATION_ID);/*from   w  ww  . j  a  v  a 2 s  .c  o m*/
    final long currentTime = UIUtils.getCurrentTime(this);
    // If the session is already started, do not schedule system notification.
    if (currentTime > sessionStart) {
        LOGD(TAG, "Not scheduling alarm because target time is in the past: " + sessionStart);
        return;
    }

    // By default, sets alarm to go off at 10 minutes before session start time.  If alarm
    // offset is provided, alarm is set to go off by that much time from now.
    long alarmTime;
    if (alarmOffset == UNDEFINED_ALARM_OFFSET) {
        alarmTime = sessionStart - MILLI_TEN_MINUTES;
    } else {
        alarmTime = currentTime + alarmOffset;
    }

    LOGD(TAG, "Scheduling alarm for " + alarmTime + " = " + (new Date(alarmTime)).toString());

    final Intent notifIntent = new Intent(ACTION_NOTIFY_SESSION, null, this, SessionAlarmService.class);
    // Setting data to ensure intent's uniqueness for different session start times.
    notifIntent.setData(new Uri.Builder().authority("com.ncode.android.apps.schedo")
            .path(String.valueOf(sessionStart)).build());
    notifIntent.putExtra(SessionAlarmService.EXTRA_SESSION_START, sessionStart);
    LOGD(TAG, "-> Intent extra: session start " + sessionStart);
    notifIntent.putExtra(SessionAlarmService.EXTRA_SESSION_END, sessionEnd);
    LOGD(TAG, "-> Intent extra: session end " + sessionEnd);
    notifIntent.putExtra(SessionAlarmService.EXTRA_SESSION_ALARM_OFFSET, alarmOffset);
    LOGD(TAG, "-> Intent extra: session alarm offset " + alarmOffset);
    PendingIntent pi = PendingIntent.getService(this, 0, notifIntent, PendingIntent.FLAG_CANCEL_CURRENT);
    final AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    // Schedule an alarm to be fired to notify user of added sessions are about to begin.
    LOGD(TAG, "-> Scheduling RTC_WAKEUP alarm at " + alarmTime);
    am.set(AlarmManager.RTC_WAKEUP, alarmTime, pi);
}

From source file:org.simlar.SimlarService.java

private void stopKeepAwake() {
    unregisterReceiver(mKeepAwakeReceiver);
    ((AlarmManager) getSystemService(Context.ALARM_SERVICE)).cancel(mkeepAwakePendingIntent);
}

From source file:com.google.samples.apps.sergio.service.SessionAlarmService.java

private void scheduleAlarm(final long sessionStart, final long sessionEnd, final long alarmOffset) {

    NotificationManager nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    nm.cancel(NOTIFICATION_ID);//from www. ja va2s . co  m
    final long currentTime = UIUtils.getCurrentTime(this);
    // If the session is already started, do not schedule system notification.
    if (currentTime > sessionStart) {
        LOGD(TAG, "Not scheduling alarm because target time is in the past: " + sessionStart);
        return;
    }

    // By default, sets alarm to go off at 10 minutes before session start time.  If alarm
    // offset is provided, alarm is set to go off by that much time from now.
    long alarmTime;
    if (alarmOffset == UNDEFINED_ALARM_OFFSET) {
        alarmTime = sessionStart - MILLI_TEN_MINUTES;
    } else {
        alarmTime = currentTime + alarmOffset;
    }

    LOGD(TAG, "Scheduling alarm for " + alarmTime + " = " + (new Date(alarmTime)).toString());

    final Intent notifIntent = new Intent(ACTION_NOTIFY_SESSION, null, this, SessionAlarmService.class);
    // Setting data to ensure intent's uniqueness for different session start times.
    notifIntent.setData(new Uri.Builder().authority("com.google.samples.apps.sergio")
            .path(String.valueOf(sessionStart)).build());
    notifIntent.putExtra(SessionAlarmService.EXTRA_SESSION_START, sessionStart);
    LOGD(TAG, "-> Intent extra: session start " + sessionStart);
    notifIntent.putExtra(SessionAlarmService.EXTRA_SESSION_END, sessionEnd);
    LOGD(TAG, "-> Intent extra: session end " + sessionEnd);
    notifIntent.putExtra(SessionAlarmService.EXTRA_SESSION_ALARM_OFFSET, alarmOffset);
    LOGD(TAG, "-> Intent extra: session alarm offset " + alarmOffset);
    PendingIntent pi = PendingIntent.getService(this, 0, notifIntent, PendingIntent.FLAG_CANCEL_CURRENT);
    final AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
    // Schedule an alarm to be fired to notify user of added sessions are about to begin.
    LOGD(TAG, "-> Scheduling RTC_WAKEUP alarm at " + alarmTime);
    am.set(AlarmManager.RTC_WAKEUP, alarmTime, pi);
}

From source file:im.neon.activity.CommonActivityUtils.java

/**
 * Restart the application after 100ms/*from w w w . j  a  va 2  s .  c om*/
 *
 * @param activity activity
 */
public static void restartApp(Activity activity) {
    // clear the preferences
    SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(activity);
    SharedPreferences.Editor editor = preferences.edit();

    // use the preference to avoid infinite relaunch on some devices
    // the culprit activity is restarted when System.exit is called.
    // so called it once to fix it
    if (!preferences.getBoolean(RESTART_IN_PROGRESS_KEY, false)) {
        CommonActivityUtils.displayToast(activity.getApplicationContext(),
                "Restart the application (low memory)");

        Log.e(LOG_TAG, "Kill the application");
        editor.putBoolean(RESTART_IN_PROGRESS_KEY, true);
        editor.commit();

        PendingIntent mPendingIntent = PendingIntent.getActivity(activity, 314159,
                new Intent(activity, LoginActivity.class), PendingIntent.FLAG_CANCEL_CURRENT);

        // so restart the application after 100ms
        AlarmManager mgr = (AlarmManager) activity.getSystemService(Context.ALARM_SERVICE);
        mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 50, mPendingIntent);

        System.exit(0);
    } else {
        Log.e(LOG_TAG, "The application is restarting, please wait !!");
        activity.finish();
    }
}

From source file:com.adithya321.sharesanalysis.activities.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    sharedPreferences = getSharedPreferences("prefs", 0);
    if (sharedPreferences.getBoolean("first", true)) {
        startActivity(new Intent(this, IntroActivity.class));
        return;//from  ww w  .ja v  a 2 s  .  co  m
    }

    setContentView(R.layout.activity_main);

    toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);

    AccountHeader accountHeader = new AccountHeaderBuilder().withHeaderBackground(R.drawable.header)
            .withCompactStyle(true).withActivity(this)
            .addProfiles(new ProfileDrawerItem().withName(sharedPreferences.getString("name", "Name"))
                    .withEmail("Target : " + sharedPreferences.getFloat("target", 20) + "%")
                    .withIcon(getResources().getDrawable(R.mipmap.ic_launcher)))
            .withOnAccountHeaderListener(new AccountHeader.OnAccountHeaderListener() {
                @Override
                public boolean onProfileChanged(View view, IProfile profile, boolean currentProfile) {
                    return false;
                }
            }).build();

    final DatabaseHandler databaseHandler = new DatabaseHandler(getApplicationContext());

    drawer = new DrawerBuilder().withActivity(this).withToolbar(toolbar).withAccountHeader(accountHeader)
            .withActionBarDrawerToggleAnimated(true)
            .addDrawerItems(
                    new PrimaryDrawerItem().withIdentifier(0).withName("Dashboard")
                            .withIcon(R.drawable.ic_timeline_gray),
                    new PrimaryDrawerItem().withIdentifier(1).withName("Fund Flow")
                            .withIcon(R.drawable.ic_compare_arrows_gray),
                    new DividerDrawerItem(),
                    new PrimaryDrawerItem().withIdentifier(2).withName("Share Purchase")
                            .withIcon(R.drawable.ic_add_red)
                            .withTextColor(getResources().getColor(R.color.red_500)),
                    new PrimaryDrawerItem().withIdentifier(3).withName("Share Sales")
                            .withIcon(R.drawable.ic_remove_green)
                            .withTextColor(getResources().getColor(R.color.colorPrimary)),
                    new PrimaryDrawerItem().withIdentifier(4).withName("Share Holdings")
                            .withIcon(R.drawable.ic_account_balance_blue)
                            .withTextColor(getResources().getColor(R.color.colorAccent)),
                    new DividerDrawerItem(),
                    new PrimaryDrawerItem().withIdentifier(5).withName("Charts")
                            .withIcon(R.drawable.ic_insert_chart_gray),
                    new PrimaryDrawerItem()
                            .withIdentifier(6).withName("Summary").withIcon(R.drawable.ic_description_gray),
                    new DividerDrawerItem(),
                    new PrimaryDrawerItem().withIdentifier(7).withName("Feedback")
                            .withIcon(R.drawable.ic_feedback_gray),
                    new PrimaryDrawerItem()
                            .withIdentifier(8).withName("Help").withIcon(R.drawable.ic_help_gray),
                    new DividerDrawerItem(),
                    new PrimaryDrawerItem().withIdentifier(10).withName("Backup")
                            .withIcon(R.drawable.ic_backup_gray),
                    new PrimaryDrawerItem()
                            .withIdentifier(11).withName("Restore").withIcon(R.drawable.ic_restore_gray),
                    new DividerDrawerItem(),
                    new PrimaryDrawerItem().withIdentifier(21).withName("Settings")
                            .withIcon(R.drawable.ic_settings_gray),
                    new PrimaryDrawerItem().withIdentifier(22).withName("About")
                            .withIcon(R.drawable.ic_info_gray))
            .withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
                @Override
                public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
                    boolean flag;
                    List<Share> shareList = databaseHandler.getShares();
                    if (drawerItem != null) {
                        flag = true;
                        switch ((int) drawerItem.getIdentifier()) {
                        case 0:
                            if (shareList.size() < 1)
                                drawer.setSelection(2, true);
                            else
                                switchFragment("Dashboard", "Dashboard");
                            break;
                        case 1:
                            switchFragment("Fund Flow", "FundFlow");
                            break;

                        case 2:
                            switchFragment("Share Purchase", "SharePurchaseMain");
                            break;
                        case 3:
                            if (shareList.size() < 1)
                                drawer.setSelection(2, true);
                            else
                                switchFragment("Share Sales", "SharePurchaseMain");
                            break;
                        case 4:
                            if (shareList.size() < 1)
                                drawer.setSelection(2, true);
                            else
                                switchFragment("Share Holdings", "ShareHoldings");
                            break;

                        case 5:
                            if (shareList.size() < 1)
                                drawer.setSelection(2, true);
                            else
                                switchFragment("Charts", "Charts");
                            break;
                        case 6:
                            if (shareList.size() < 1)
                                drawer.setSelection(2, true);
                            else
                                switchFragment("Summary", "Summary");
                            break;

                        case 7:
                            ConversationActivity.show(MainActivity.this);
                            break;
                        case 8:
                            startActivity(new Intent(MainActivity.this, IntroActivity.class));
                            break;

                        case 10:
                            RealmBackupRestore backup = new RealmBackupRestore(MainActivity.this);
                            backup.backup();
                            break;
                        case 11:
                            RealmBackupRestore restore = new RealmBackupRestore(MainActivity.this);
                            restore.restore();
                            Intent mStartActivity = new Intent(MainActivity.this, MainActivity.class);
                            int mPendingIntentId = 123456;
                            PendingIntent mPendingIntent = PendingIntent.getActivity(MainActivity.this,
                                    mPendingIntentId, mStartActivity, PendingIntent.FLAG_CANCEL_CURRENT);
                            AlarmManager mgr = (AlarmManager) MainActivity.this
                                    .getSystemService(Context.ALARM_SERVICE);
                            mgr.set(AlarmManager.RTC, System.currentTimeMillis() + 100, mPendingIntent);
                            System.exit(0);
                            break;

                        case 21:
                            startActivity(new Intent(MainActivity.this, ProfileActivity.class));
                            break;
                        case 22:
                            new LibsBuilder().withActivityStyle(Libs.ActivityStyle.LIGHT_DARK_TOOLBAR)
                                    .withActivityTitle(getString(R.string.app_name)).withAboutIconShown(true)
                                    .withAboutVersionShown(true).withVersionShown(true).withLicenseShown(true)
                                    .withLicenseDialog(true).withListener(libsListener)
                                    .start(MainActivity.this);
                            break;

                        default:
                            switchFragment("Dashboard", "Dashboard");
                            break;
                        }
                    } else {
                        flag = false;
                    }
                    return flag;
                }
            }).build();

    if (savedInstanceState == null)
        drawer.setSelection(0, true);
    else
        drawer.setSelection(savedInstanceState.getLong("drawerSelection"), true);

    CustomActivityOnCrash.install(this);
}

From source file:vrisini.cordova.plugin.schedule.Schedule.java

/**
 * The alarm manager for the application.
 *//* ww  w .  j a  va 2  s .  c  o  m*/
protected static AlarmManager getAlarmManager() {
    return (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
}

From source file:com.cityfreqs.littlesirecho.MainActivity.java

private void setAlarmNotification() {
    Context context = getBaseContext();
    Intent notifyIntent = new Intent();
    notifyIntent.setAction(ALARM_ACTION);

    if (alarmIntent != null) {
        // already set
        return;/* ww  w. java  2s  . com*/
    } else {
        alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
        alarmIntent = PendingIntent.getBroadcast(context, 0, notifyIntent, 0);
        alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + userSelectedWaitTime,
                userSelectedWaitTime, alarmIntent);
    }
}