List of usage examples for android.app AlarmManager RTC
int RTC
To view the source code for android.app AlarmManager RTC.
Click Source Link
From source file:com.strathclyde.highlightingkeyboard.SoftKeyboardService.java
/** * Main initialization of the input method component. * Set up the word separators list//from w ww .j a v a 2s. c o m * Initialize the core service * Initialize the colours to be used in highlighting * Initialize the list of autocorrected words * Load the suspect-replacement probability distribution map */ @Override public void onCreate() { super.onCreate(); //get User ID try { Class<?> c = Class.forName("android.os.SystemProperties"); Method get = c.getMethod("get", String.class); userid = (String) get.invoke(c, "ro.serialno"); Log.i("OnCreate", "User id= " + userid); } catch (Exception ignored) { Log.i("OnCreate", "Could not obtain userid"); userid = "xxx"; } Editor e = PreferenceManager.getDefaultSharedPreferences(this).edit(); e.putString("prefUsername", userid); e.commit(); //used for managing injected errors errorMap = new HashMap<Integer, Character>(); mWordSeparators = getResources().getString(R.string.word_separators); mSpecialSeparators = getResources().getString(R.string.special_separators); CoreEngineInitialize.initializeCoreService(getApplicationContext()); initializeCore(); assignColours(); autocorrected_words = new HashMap<String, String>(); try { suspectReplacementDistribution = new JSONObject(loadJSONFromAsset()); } catch (JSONException ex) { // TODO Auto-generated catch block ex.printStackTrace(); } //setup the upload task alarm manager /* * Twice daily, broadcast an event * This will be trapped by our receiver */ Intent alarmIntent = new Intent(this, UploadDataReceiver.class); alarmIntent.putExtra("origin", "alarm"); alarmIntent.putExtra("insert", true); PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, alarmIntent, PendingIntent.FLAG_UPDATE_CURRENT); AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); alarmManager.setInexactRepeating(AlarmManager.RTC, Calendar.getInstance().getTimeInMillis(), AlarmManager.INTERVAL_HALF_DAY, pendingIntent); //Log.i("OnCreate", "Alarm set "); }
From source file:ca.marcmeszaros.papyrus.browser.BooksBrowser.java
/** * Executes the query to loan out the book *//*from w w w. j a va 2 s. c o m*/ private void loanBook(int mYear, int mMonth, int mDay) { // set the due date Calendar c = Calendar.getInstance(); c.set(mYear, mMonth, mDay); // gets the uri path to the user selected Uri user = loanData.getData(); // gets the user id String id = user.getLastPathSegment(); // prepare the query ContentValues values = new ContentValues(); values.put(PapyrusContentProvider.Loans.FIELD_BOOK_ID, selectedBookID); values.put(PapyrusContentProvider.Loans.FIELD_CONTACT_ID, id); values.put(PapyrusContentProvider.Loans.FIELD_LEND_DATE, System.currentTimeMillis()); values.put(PapyrusContentProvider.Loans.FIELD_DUE_DATE, c.getTimeInMillis()); // insert the entry in the database, and get the new loan id Uri newLoan = resolver.insert(PapyrusContentProvider.Loans.CONTENT_URI, values); int loanID = (int) ContentUris.parseId(newLoan); // Book book = new Book(isbn10, title, author); Loan loan = new Loan(loanID, values.getAsInteger(PapyrusContentProvider.Loans.FIELD_BOOK_ID), values.getAsInteger(PapyrusContentProvider.Loans.FIELD_CONTACT_ID), values.getAsLong(PapyrusContentProvider.Loans.FIELD_LEND_DATE), values.getAsLong(PapyrusContentProvider.Loans.FIELD_DUE_DATE)); // get an alarm manager AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE); // create the intent for the alarm Intent intent = new Intent(this, AlarmReceiver.class); // put the loan object into the alarm receiver intent.putExtra("loan", loan); // create the pendingIntent to run when the alarm goes off and be handled by a receiver PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, 0); // set the repeating alarm am.set(AlarmManager.RTC, c.getTimeInMillis(), pendingIntent); Toast.makeText(this, getString(R.string.BooksBrowser_toast_loanSuccessful), Toast.LENGTH_LONG).show(); }
From source file:com.nextgis.mobile.services.TrackerService.java
protected void ScheduleNextUpdate(Context context, String action, long nMinTimeBetweenSend, boolean bEnergyEconomy, boolean bStart) { if (context == null) return;/*from w w w. j av a 2 s .com*/ Log.d(TAG, "Schedule Next Update for tracker " + bStart); if (bStart == false) return; Intent intent = new Intent(action); PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); // The update frequency should often be user configurable. This is not. long currentTimeMillis = System.currentTimeMillis(); long nextUpdateTimeMillis = currentTimeMillis + nMinTimeBetweenSend; Time nextUpdateTime = new Time(); nextUpdateTime.set(nextUpdateTimeMillis); AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); if (bEnergyEconomy) alarmManager.set(AlarmManager.RTC, nextUpdateTimeMillis, pendingIntent); else alarmManager.set(AlarmManager.RTC_WAKEUP, nextUpdateTimeMillis, pendingIntent); }
From source file:com.nextgis.mobile.TrackerService.java
protected void ScheduleNextUpdate(Context context, String action, long nMinTimeBetweenSend, boolean bEnergyEconomy, boolean bStart) { if (context == null) return;/*from ww w .j a v a2 s. com*/ Log.d(MainActivity.TAG, "Schedule Next Update for tracker " + bStart); if (bStart == false) return; Intent intent = new Intent(action); PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); // The update frequency should often be user configurable. This is not. long currentTimeMillis = System.currentTimeMillis(); long nextUpdateTimeMillis = currentTimeMillis + nMinTimeBetweenSend; Time nextUpdateTime = new Time(); nextUpdateTime.set(nextUpdateTimeMillis); AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); if (bEnergyEconomy) alarmManager.set(AlarmManager.RTC, nextUpdateTimeMillis, pendingIntent); else alarmManager.set(AlarmManager.RTC_WAKEUP, nextUpdateTimeMillis, pendingIntent); }
From source file:im.neon.activity.CommonActivityUtils.java
/** * Restart the application after 100ms//from w ww .java 2 s . c o m * * @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 w w w . ja v a 2 s.c o 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:com.nextgis.firereporter.GetFiresService.java
protected void ScheduleNextUpdate(Context context, int nCommand, long nMinTimeBetweenSend, boolean bEnergyEconomy) { if (context == null) return;//w w w . j a v a2 s . c o m Intent intent = new Intent(MainActivity.INTENT_NAME); intent.putExtra(RECEIVER, mUserNasaReceiver); intent.putExtra(RECEIVER_SCANEX, mScanexReceiver); intent.putExtra(COMMAND, nCommand); intent.putExtra(SOURCE, mnFilter); PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); // The update frequency should often be user configurable. This is not. long currentTimeMillis = System.currentTimeMillis(); long nextUpdateTimeMillis = currentTimeMillis + nMinTimeBetweenSend; Time nextUpdateTime = new Time(); nextUpdateTime.set(nextUpdateTimeMillis); AlarmManager alarmManager = (AlarmManager) getSystemService(Context.ALARM_SERVICE); if (bEnergyEconomy) alarmManager.set(AlarmManager.RTC, nextUpdateTimeMillis, pendingIntent); else alarmManager.set(AlarmManager.RTC_WAKEUP, nextUpdateTimeMillis, pendingIntent); }
From source file:com.metinkale.prayerapp.vakit.WidgetService.java
@Override public int onStartCommand(Intent intent, int flags, int startId) { WidgetProvider.updateWidgets(this); updateOngoing();//from w ww . ja v a2s . c o m AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE); PendingIntent service = PendingIntent.getService(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT); App.setExact(am, AlarmManager.RTC, DateTime.now().withMillisOfSecond(0).withSecondOfMinute(0).plusMinutes(1).getMillis(), service); stopSelf(); return super.onStartCommand(intent, flags, startId); }
From source file:com.cssweb.android.base.BaseActivity.java
@Override protected void onPause() { // Log.i("==========", "======onPause==="); super.onPause(); ActivityUtil.ALARM_RECORED = -1;/*from w w w . j a va 2 s. c o m*/ // ActivityUtil.clearAlarmRecord(BaseActivity.this); alarmManager.setRepeating(AlarmManager.RTC, 0, 60 * 1000, pendingIntent); }
From source file:com.jefftharris.passwdsafe.NotificationMgr.java
/** Load the expiration entries from the database */ private void loadEntries(SQLiteDatabase db) throws SQLException { long expiration; if (itsExpiryFilter != null) { expiration = itsExpiryFilter.getExpiryFromNow(null); } else {// w w w.ja v a2s. com expiration = Long.MIN_VALUE; } LongReference nextExpiration = new LongReference(Long.MAX_VALUE); itsNotifUris.clear(); HashSet<Long> uris = new HashSet<>(); ArrayList<Long> removeUriIds = new ArrayList<>(); Cursor uriCursor = db.query(DB_TABLE_URIS, new String[] { DB_COL_URIS_ID, DB_COL_URIS_URI }, null, null, null, null, null); try { while (uriCursor.moveToNext()) { long id = uriCursor.getLong(0); Uri uri = Uri.parse(uriCursor.getString(1)); boolean exists = loadUri(id, uri, uris, expiration, nextExpiration, db); if (!exists) { removeUriIds.add(id); } } } finally { uriCursor.close(); } Iterator<HashMap.Entry<Long, UriNotifInfo>> iter = itsUriNotifs.entrySet().iterator(); while (iter.hasNext()) { HashMap.Entry<Long, UriNotifInfo> entry = iter.next(); if (!uris.contains(entry.getKey())) { itsNotifyMgr.cancel(entry.getValue().getNotifId()); iter.remove(); } } for (Long removeId : removeUriIds) { removeUri(removeId, db); } PasswdSafeUtil.dbginfo(TAG, "nextExpiration: %tc", nextExpiration.itsValue); if ((nextExpiration.itsValue != Long.MAX_VALUE) && (itsExpiryFilter != null)) { if (itsTimerIntent == null) { Intent intent = new Intent(PasswdSafeApp.EXPIRATION_TIMEOUT_INTENT); itsTimerIntent = PendingIntent.getBroadcast(itsCtx, 0, intent, PendingIntent.FLAG_CANCEL_CURRENT); } long nextTimer = System.currentTimeMillis() + (nextExpiration.itsValue - expiration); PasswdSafeUtil.dbginfo(TAG, "nextTimer: %tc", nextTimer); itsAlarmMgr.set(AlarmManager.RTC, nextTimer, itsTimerIntent); } else if (itsTimerIntent != null) { PasswdSafeUtil.dbginfo(TAG, "cancel expiration timer"); itsAlarmMgr.cancel(itsTimerIntent); } }