private void registerPongListener() { pingID = null; if (pongListener != null) extXMPPConnection.removePacketListener(pongListener); pongListener = new PacketListener() { @Override public void processPacket(Packet packet) { if (packet == null) return; gotServerPong(packet.getPacketID()); } }; extXMPPConnection.addPacketListener(pongListener, new PacketTypeFilter(IQ.class)); pingAlarmPendIntent = PendingIntent.getBroadcast( service.getApplicationContext(), 0, intentPingAlarm, PendingIntent.FLAG_UPDATE_CURRENT); timeoutAlarmPendIntent = PendingIntent.getBroadcast( service.getApplicationContext(), 0, intentTimeoutAlarm, PendingIntent.FLAG_UPDATE_CURRENT); alarmManager.setInexactRepeating( AlarmManager.RTC_WAKEUP, System.currentTimeMillis() + AlarmManager.INTERVAL_FIFTEEN_MINUTES, AlarmManager.INTERVAL_FIFTEEN_MINUTES, pingAlarmPendIntent); }
private void initServiceDiscovery() { ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(extXMPPConnection); try { if (capsCacheDir == null) { capsCacheDir = new File(service.getCacheDir(), "entity-caps-cache"); capsCacheDir.mkdirs(); EntityCapsManager.setPersistentCache(new SimpleDirectoryPersistentCache(capsCacheDir)); } } catch (java.io.IOException e) { Log.e(TAG, "Could not init : " + e.getLocalizedMessage()); } PingManager.getInstanceFor(extXMPPConnection).setPingMinimumInterval(10 * 1000); String app_name = service.getString(R.string.app_name); String build_revision = service.getString(R.string.build_revision); Version.Manager.getInstanceFor(extXMPPConnection) .setVersion(new Version(app_name, build_revision, Constant.ANDROID)); DeliveryReceiptManager dm = DeliveryReceiptManager.getInstanceFor(extXMPPConnection); dm.enableAutoReceipts(); dm.addReceiptReceivedListener( new ReceiptReceivedListener() { // DOES NOT WORK IN CARBONS public void onReceiptReceived(String fromJid, String toJid, String receiptId) { changeMessageDeliveryStatus(receiptId, ChatConstants.DS_ACKED); } }); }
private void initServiceDiscovery() { // register connection features ServiceDiscoveryManager sdm = ServiceDiscoveryManager.getInstanceFor(mXMPPConnection); // init Entity Caps manager with storage in app's cache dir try { if (capsCacheDir == null) { capsCacheDir = new File(mService.getCacheDir(), "entity-caps-cache"); capsCacheDir.mkdirs(); EntityCapsManager.setPersistentCache(new SimpleDirectoryPersistentCache(capsCacheDir)); } } catch (java.io.IOException e) { Log.e(TAG, "Could not init Entity Caps cache: " + e.getLocalizedMessage()); } // reference PingManager, set ping flood protection to 10s PingManager.getInstanceFor(mXMPPConnection).setPingMinimumInterval(10 * 1000); // set Version for replies String app_name = mService.getString(org.yaxim.androidclient.R.string.app_name); String build_revision = mService.getString(org.yaxim.androidclient.R.string.build_revision); Version.Manager.getInstanceFor(mXMPPConnection) .setVersion(new Version(app_name, build_revision, "Android")); // reference DeliveryReceiptManager, add listener DeliveryReceiptManager dm = DeliveryReceiptManager.getInstanceFor(mXMPPConnection); dm.enableAutoReceipts(); dm.addReceiptReceivedListener( new ReceiptReceivedListener() { // DOES NOT WORK IN CARBONS public void onReceiptReceived(String fromJid, String toJid, String receiptId) { Log.d(TAG, "got delivery receipt for " + receiptId); changeMessageDeliveryStatus(receiptId, ChatConstants.DS_ACKED); } }); }
private static ArrayList<String> extractTextFromNotification(Service service, RemoteViews view) { LayoutInflater inflater = (LayoutInflater) service.getSystemService(Context.LAYOUT_INFLATER_SERVICE); ArrayList<String> result = new ArrayList<String>(); if (view == null) { Log.d(TAG, "View is empty"); return null; } try { int layoutid = view.getLayoutId(); ViewGroup localView = (ViewGroup) inflater.inflate(layoutid, null); view.reapply(service.getApplicationContext(), localView); ArrayList<View> outViews = new ArrayList<View>(); extractViewType(outViews, TextView.class, localView); for (View ttv: outViews) { TextView tv = (TextView) ttv; String txt = tv.getText().toString(); if (!TextUtils.isEmpty(txt) && tv.getId() != TIMESTAMPID) { result.add(txt); } } } catch (Exception e) { Log.d(TAG, "FAILED to load notification " + e.toString()); Log.wtf(TAG, e); return null; //notification might have dissapeared by now } Log.d(TAG, "Return result" + result); return result; }
/** * Marks the service as a foreground service. This uses reflection to figure out whether the new * APIs for marking a service as a foreground service are available. If not, it falls back to the * old {@link #setForeground(boolean)} call. * * @param service the service to put in foreground mode * @param notificationId id of the notification to show * @param notification the notification to show */ public static void setForeground( Service service, Integer notificationId, Notification notification) { final Class<?>[] startForegroundSignature = new Class[] {int.class, Notification.class}; Method startForeground = null; try { startForeground = service.getClass().getMethod("startForeground", startForegroundSignature); try { startForeground.invoke(service, new Object[] {notificationId, notification}); } catch (IllegalArgumentException e) { // Should not happen! Log.e("Could not set TriggerService to foreground mode.", e); } catch (IllegalAccessException e) { // Should not happen! Log.e("Could not set TriggerService to foreground mode.", e); } catch (InvocationTargetException e) { // Should not happen! Log.e("Could not set TriggerService to foreground mode.", e); } } catch (NoSuchMethodException e) { // Fall back on old API. service.setForeground(true); NotificationManager manager = (NotificationManager) service.getSystemService(Context.NOTIFICATION_SERVICE); manager.notify(notificationId, notification); } }
public void onEvent(PlayerState playerState) { mPlayerState = playerState; updateNotification(); if (playerState.streamingState == PlayerState.StreamingState.STOPPED) { mService.stopForeground(false); } else { mService.startForeground(BalataNotifier.NOTIFY_ID, createNotification()); } }
@Override public void onCreate() { // TODO Auto-generated method stub super.onCreate(); mNM = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); try { mStartForeground = getClass().getMethod("startForeground", mStartForegroundSignature); mStopForeground = getClass().getMethod("stopForeground", mStopForegroundSignature); } catch (NoSuchMethodException e) { // Running on an older platform. mStartForeground = mStopForeground = null; } startForegroundCompat(NOTIFICATION_ID, getNotification()); try { analyzer = new SimpleAudioAnalyser(); // start listening for data points added, and add sound to them dataManager = SleepDataManager.getInstance(); dataManager.addObserver(analyzer, SleepDataManager.DATA_POINT_ADDED); timer = new Timer(); timer.scheduleAtFixedRate(new DelayTask(), 500, 1000); analyzer.measureStart(); } catch (Exception e) { stopSelf(); } running = true; if (D) Log.e(TAG, "Created!"); }
@Override public void onCreate() { super.onCreate(); singleton = this; wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE); connManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE); try { mStartForeground = getClass().getMethod("startForeground", new Class[] {int.class, Notification.class}); } catch (NoSuchMethodException e) { mStartForeground = null; } state = STATE_STOPPED; filteringEnabled = false; app = (BarnacleApp) getApplication(); app.serviceStarted(this); PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE); wakeLock = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK, "BarnacleService"); wakeLock.acquire(); IntentFilter filter = new IntentFilter(); filter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION); filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); registerReceiver(connectivityReceiver, filter); }
@Override public void onCreate() { super.onCreate(); Intent intent = new Intent("screate"); sendBroadcast(intent); Msg.t(this, "service create"); }
@Override public void onCreate() { super.onCreate(); roster = ConnectionHelper.getRoster(); contactList = ConnectionHelper.getContactList(); roster.addRosterListener( new RosterListener() { @Override public void presenceChanged(Presence arg0) { updateUser(arg0); } @Override public void entriesUpdated(Collection<String> arg0) { // TODO Auto-generated method stub } @Override public void entriesDeleted(Collection<String> arg0) { // TODO Auto-generated method stub } @Override public void entriesAdded(Collection<String> arg0) { // TODO Auto-generated method stub } }); }
@Override public void onDestroy() { super.onDestroy(); mHandler = null; mIsStarted = false; // Log.d(TAG, "onDestroy"); }
@Override public void onDestroy() { super.onDestroy(); cancelUpdate = true; manager.cancel(id); Log.v("updateservice", "service ondestroy"); }
@Override public void onDestroy() { super.onDestroy(); // Service被终止的同时也停止定时器继续运行 timer.cancel(); timer = null; }
@Override public void onCreate() { Log.i(TAG, "Service created."); super.onCreate(); mManager = new AntPlusManager(); mManager.start(this); }
@Override public void onCreate() { super.onCreate(); mLocationFinder = PlatformSpecificImplementationFactory.getLastLocationFinder(this, this); Location location = mLocationFinder.getLastBestLocation(MAX_DISTANCE_LIMIT, MAX_TIME_LIMIT); if (location != null) { onLocationChanged(location); } String provider = Settings.Secure.getString(getContentResolver(), Settings.Secure.LOCATION_PROVIDERS_ALLOWED); if (!"".equals(provider)) { LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE); final boolean gpsEnabled = locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER); final boolean networkEnabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER); mNoProviderEnabled = !gpsEnabled && !networkEnabled; } // TODO provide own interface for notifying // that no providers are available if (mNoProviderEnabled) { for (LocationListener listener : mListeners) { listener.onProviderDisabled(null); } } }
@Override public void onCreate() { super.onCreate(); try { cacheManager = createCacheManager(getApplication()); } catch (CacheCreationException e) { Ln.e(e); stopSelf(); return; } if (cacheManager == null) { Ln.e(new CacheCreationException("createCacheManager() can't create a null cacheManager")); stopSelf(); return; } progressReporter = createRequestRequestListenerNotifier(); spiceServiceListenerNotifier = createSpiceServiceListenerNotifier(); final ExecutorService executorService = getExecutorService(); final NetworkStateChecker networkStateChecker = getNetworkStateChecker(); requestProcessor = createRequestProcessor(executorService, networkStateChecker); requestProcessor.setFailOnCacheError(DEFAULT_FAIL_ON_CACHE_ERROR); notification = createDefaultNotification(); Ln.d("SpiceService instance created."); }
@Override public void onCreate() { super.onCreate(); if (BuildConfig.DEBUG) Logger.log("SensorListener onCreate"); reRegisterSensor(); updateNotificationState(); }
@Override public void onDestroy() { LoginScreen.appendLog(TAG, "[SERVICE] onDestroy"); // Unregister our receiver. unregisterReceiver(mReceiver); unregisterDetector(); mStateEditor = mState.edit(); mStateEditor.putInt("steps", mSteps); mStateEditor.putInt("pace", mPace); mStateEditor.putFloat("distance", mDistance); mStateEditor.putFloat("speed", mSpeed); mStateEditor.putFloat("calories", mCalories); mStateEditor.commit(); wakeLock.release(); super.onDestroy(); // Stop detecting mSensorManager.unregisterListener(mStepDetector); // Tell the user we stopped. // Toast.makeText(this, "stopped pedometer service", Toast.LENGTH_SHORT).show(); }
@Override public void onStart(Intent intent, int startId) { // TODO Auto-generated method stub super.onStart(intent, startId); urlString = intent.getStringExtra("url"); if (urlString != null) showDownloadNotification(); }
public void onDestroy() { super.onDestroy(); if (mGcmRegistrationListener != null) { mAppController.removeListener(mGcmRegistrationListener); } mGcm.close(); }
public void handleMessage(Message msg) { if (msg.what == 1) { LogUtils.i("go thread..."); } super.handleMessage(msg); }
@Override public void onDestroy() { // handler.removeCallbacks(sendUpdatesToUI); super.onDestroy(); Log.v("STOP_SERVICE", "DONE"); locationManager.removeUpdates(listener); }
@Override public void onDestroy() { disconnectMAVConnection(); dismissNotification(); releaseWakelock(); super.onDestroy(); }
@Override public void onCreate() { super.onCreate(); Log.d(TAG, "Audio service started"); /** This service just listens on port 8080 and spits out an audio file */ }
@Override public void onDestroy() { super.onDestroy(); Intent intent = new Intent("sdestroy"); sendBroadcast(intent); Msg.t(this, "service destroy"); }
@Override public void onCreate() { super.onCreate(); SharedPreferences sharedPreferences = getSharedPreferences(JADWAL, 0); jSubuh = sharedPreferences.getInt("jSubuh", 4); mSubuh = sharedPreferences.getInt("mSubuh", 10); jZuhur = sharedPreferences.getInt("jZuhur", 1); mZuhur = sharedPreferences.getInt("mZuhur", 1); jAshar = sharedPreferences.getInt("jAshar", 1); mAshar = sharedPreferences.getInt("mAshar", 1); jMaghrib = sharedPreferences.getInt("jMaghrib", 1); mMaghrib = sharedPreferences.getInt("mMaghrib", 1); jIsya = sharedPreferences.getInt("jIsya", 1); mIsya = sharedPreferences.getInt("mIsya", 1); // jAshar=0; // mAshar=40; // jMaghrib=0; // mMaghrib=38; // jIsya=0; // mIsya=36; mNM = (NotificationManager) getSystemService(NOTIFICATION_SERVICE); // init the service here _startService(); }
public int onStartCommand(Intent intent, int flags, int startId) { super.onStartCommand(intent, flags, startId); new Thread(svrThreads, new ServiceWorker(), "PecorinerLocationDetect").start(); // Toast.makeText(this, "start calling", Toast.LENGTH_SHORT).show(); return START_STICKY; }
@Override public void onCreate() { super.onCreate(); builder = new NotificationCompat.Builder(getBaseContext()); notificationManager = (NotificationManager) getBaseContext().getSystemService(NOTIFICATION_SERVICE); }
@Override public void onCreate() { audioManager = (AudioManager) getSystemService(AUDIO_SERVICE); NotificationCenter.getInstance().addObserver(this, NotificationCenter.audioProgressDidChanged); NotificationCenter.getInstance().addObserver(this, NotificationCenter.audioPlayStateChanged); super.onCreate(); }
public void onCreate() { super.onCreate(); Log.d(LOG_TAG, "MyService onCreate"); filteredPlaylist = new ArrayList<>(); mediaPlayer = new MediaPlayer(); }