NotificationManager getNotifier() { return (NotificationManager) getApplicationContext().getSystemService(NOTIFICATION_SERVICE); }
protected synchronized void acquireLocks() { if (wakeLock == null) { PowerManager pMgr = (PowerManager) getSystemService(POWER_SERVICE); wakeLock = pMgr.newWakeLock(wakeLockType(), "com.zegoggles.smssync:"+TAG); } wakeLock.acquire(10*60*1000L /*10 minutes*/); if (isConnectedViaWifi()) { // we have Wifi, lock it WifiManager wMgr = getWifiManager(); if (wifiLock == null) { wifiLock = wMgr.createWifiLock(getWifiLockType(), TAG); } wifiLock.acquire(); } }
@Override public int onStartCommand(final Intent intent, int flags, int startId) { handleIntent(intent); return START_NOT_STICKY; }
@SuppressWarnings("deprecation") private boolean isConnectedViaWifi_pre_SDK21() { WifiManager wifiManager = getWifiManager(); return (wifiManager != null && wifiManager.isWifiEnabled() && getConnectivityManager().getNetworkInfo(TYPE_WIFI) != null && getConnectivityManager().getNetworkInfo(TYPE_WIFI).isConnected()); }
protected BackupImapStore getBackupImapStore() throws MessagingException { final String uri = getAuthPreferences().getStoreUri(); if (!BackupImapStore.isValidUri(uri)) { throw new MessagingException("No valid IMAP URI: "+uri); } return new BackupImapStore(getApplicationContext(), uri, getAuthPreferences().isTrustAllCertificates()); }
protected void appLog(int id, Object... args) { final String msg = getString(id, args); if (appLog != null) { appLog.append(msg); } else if (LOCAL_LOGV) { Log.d(App.TAG, "AppLog: "+msg); } }
public boolean isWorking() { return getState().isRunning(); }
@TargetApi(Build.VERSION_CODES.LOLLIPOP) @SuppressWarnings("deprecation") private boolean isConnectedViaWifi_SDK21() { for (Network network : getConnectivityManager().getAllNetworks()) { final NetworkInfo networkInfo = getConnectivityManager().getNetworkInfo(network); if (networkInfo != null && networkInfo.getType() == TYPE_WIFI && networkInfo.isConnectedOrConnecting()) { return true; } } return false; } }
protected void appLogDebug(String message, Object... args) { if (getPreferences().isAppLogDebug() && appLog != null) { appLog.append(String.format(ENGLISH, message, args)); } else if (LOCAL_LOGV) { Log.v(App.TAG, "AppLog: "+String.format(ENGLISH, message, args)); } }
@SuppressWarnings("deprecation") @NonNull NotificationCompat.Builder createNotification(int resId) { return new NotificationCompat.Builder(this) .setSmallIcon(R.drawable.ic_notification) .setTicker(getString(resId)) .setWhen(System.currentTimeMillis()) .setOngoing(true); }
protected WifiManager getWifiManager() { return (WifiManager) getApplicationContext().getSystemService(Context.WIFI_SERVICE); }
protected ConnectivityManager getConnectivityManager() { return (ConnectivityManager) getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE); }
PendingIntent getPendingIntent(@Nullable Bundle extras) { final Intent intent = new Intent(getApplicationContext(), MainActivity.class); if (extras != null) { intent.putExtras(extras); } return PendingIntent.getActivity(getApplicationContext(), 0, intent, FLAG_UPDATE_CURRENT); }
protected Preferences getPreferences() { return new Preferences(getApplicationContext()); }