Example usage for android.app Service getSystemService

List of usage examples for android.app Service getSystemService

Introduction

In this page you can find the example usage for android.app Service getSystemService.

Prototype

@Override
    public Object getSystemService(String name) 

Source Link

Usage

From source file:uk.ac.horizon.ubihelper.service.channel.WifiScannerChannel.java

/**
 * @param handler/* w w  w.  jav  a 2 s  .  c o m*/
 * @param name
 */
public WifiScannerChannel(Service service, Handler handler, String name) {
    super(handler, name);
    wifi = (WifiManager) service.getSystemService(Service.WIFI_SERVICE);
    this.service = service;
    if (wifi == null)
        Log.w(TAG, "No WifiManager");
    IntentFilter filter = new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION);
    filter.addAction(WifiManager.WIFI_STATE_CHANGED_ACTION);
    this.service.registerReceiver(receiver, filter);
}

From source file:uk.ac.horizon.ubihelper.service.channel.CellStrengthChannel.java

/**
 * @param name//from ww w . j  a v a2 s . com
 */
public CellStrengthChannel(Service service, String name) {
    super(name);
    this.service = service;
    telephony = (TelephonyManager) service.getSystemService(Service.TELEPHONY_SERVICE);
}

From source file:uk.ac.horizon.ubihelper.service.channel.CellLocationChannel.java

/**
 * @param handler//from   w ww .j a v  a2s  .c om
 * @param name
 */
public CellLocationChannel(Handler handler, Service service, String name, boolean includeNeighbours) {
    super(handler, name);
    this.includeNeighbours = includeNeighbours;
    telephony = (TelephonyManager) service.getSystemService(Service.TELEPHONY_SERVICE);
}

From source file:org.ado.minesync.gui.notification.MineSyncNotification.java

public MineSyncNotification(final Service service) {
    this.service = service;
    notificationManager = (NotificationManager) service.getSystemService(Context.NOTIFICATION_SERVICE);
    notNull(notificationManager, "notificationManager shouldn't be null");
}

From source file:com.dmbstream.android.util.Util.java

private static void stopForeground(Service service, boolean removeNotification) {
    // Service.stopForeground() was introduced in Android 2.0.
    // Use reflection to maintain compatibility with 1.5.
    try {//from  w  ww  .java  2  s .  c  o  m
        Method method = Service.class.getMethod("stopForeground", boolean.class);
        method.invoke(service, removeNotification);
        Log.i(TAG, "Successfully invoked Service.stopForeground()");
    } catch (Throwable x) {
        NotificationManager notificationManager = (NotificationManager) service
                .getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.cancel(Constants.NOTIFICATION_ID_PLAYING);
        Log.i(TAG, "Service.stopForeground() not available. Using work-around.");
    }
}

From source file:com.dmbstream.android.util.Util.java

private static void startForeground(Service service, int notificationId, Notification notification) {
    // Service.startForeground() was introduced in Android 2.0.
    // Use reflection to maintain compatibility with 1.5.
    try {//from   w  ww.  j  av a 2s  . c  o m
        Method method = Service.class.getMethod("startForeground", int.class, Notification.class);
        method.invoke(service, notificationId, notification);
        Log.i(TAG, "Successfully invoked Service.startForeground()");
    } catch (Throwable x) {
        NotificationManager notificationManager = (NotificationManager) service
                .getSystemService(Context.NOTIFICATION_SERVICE);
        notificationManager.notify(Constants.NOTIFICATION_ID_PLAYING, notification);
        Log.i(TAG, "Service.startForeground() not available. Using work-around.");
    }
}

From source file:net.czlee.debatekeeper.AlertManager.java

/**
 * Constructor.//www  . ja  v  a 2 s.co  m
 * @param debatingTimerService The instance of {@link DebatingTimerService} to which this
 * AlertManager relates
 */
public AlertManager(Service debatingTimerService) {

    mService = debatingTimerService;

    // System services
    mNotificationManager = (NotificationManager) debatingTimerService
            .getSystemService(Context.NOTIFICATION_SERVICE);
    mVibrator = (Vibrator) debatingTimerService.getSystemService(Context.VIBRATOR_SERVICE);
    mPowerManager = (PowerManager) mService.getSystemService(Context.POWER_SERVICE);

    // Create a PendingIntent for the notification we raise while the timer is running.
    Intent intent = new Intent(debatingTimerService, DebatingActivity.class);
    // This flag prevents the activity from having multiple instances on the back stack,
    // so that when the user presses the notification while already in Debatekeeper, pressing
    // back won't make the user go through several instances of Debatekeeper on the back stack.
    intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);

    mIntentForOngoingNotification = PendingIntent.getActivity(debatingTimerService, 0, intent, 0);

    // Set up defaults
    Resources res = mService.getResources();
    mSilentMode = res.getBoolean(R.bool.prefDefault_silentMode);
    mVibrateMode = res.getBoolean(R.bool.prefDefault_vibrateMode);

    createWakeLock();
}

From source file:uk.ac.horizon.ubihelper.service.PeerManager.java

public PeerManager(Service service) {
    this.service = service;
    // Note: meant to open database on another thread?!
    database = new PeersOpenHelper(service).getWritableDatabase();

    protocol = new MyProtocolManager();
    peerConnectionListener = new OnPeerConnectionListener(protocol);
    remoteChannelTimer = new Timer();

    wifi = (WifiManager) service.getSystemService(Service.WIFI_SERVICE);

    try {/*from w w  w . j  ava  2s .  c  om*/
        messageDigest = MessageDigest.getInstance("MD5");
    } catch (Exception e) {
        Log.e(TAG, "Could not get MessageDigest: " + e);
    }
    try {
        serverSocketChannel = ServerSocketChannel.open();
        ServerSocket ss = serverSocketChannel.socket();
        ss.bind(new InetSocketAddress(InetAddress.getByName("0.0.0.0"), 0));
        serverPort = ss.getLocalPort();
        serverSocketChannel.configureBlocking(false);
    } catch (IOException e) {
        Log.w(TAG, "Error opening ServerSocketChannel: " + e.getMessage());
    }
    try {
        selector = new PeerConnectionScheduler(serverSocketChannel);
        selector.setListener(selectorListener);
        selector.start();
    } catch (IOException e) {
        Log.w(TAG, "Error starting Selector: " + e.getMessage());
    }
}

From source file:org.broeuschmeul.android.gps.usb.provider.driver.USBGpsManager.java

/**
 * @param callingService/*from   ww  w  .ja  v a2 s  .c  o  m*/
 * @param vendorId
 * @param productId
 * @param maxRetries
 */
public USBGpsManager(Service callingService, int vendorId, int productId, int maxRetries) {
    this.gpsVendorId = vendorId;
    this.gpsProductId = productId;
    this.callingService = callingService;
    this.maxConnectionRetries = maxRetries + 1;
    this.nbRetriesRemaining = maxConnectionRetries;
    this.appContext = callingService.getApplicationContext();
    this.parser = new NmeaParser(10f, this.appContext);

    locationManager = (LocationManager) callingService.getSystemService(Context.LOCATION_SERVICE);

    sharedPreferences = PreferenceManager.getDefaultSharedPreferences(callingService);

    deviceSpeed = sharedPreferences.getString(USBGpsProviderService.PREF_GPS_DEVICE_SPEED,
            callingService.getString(R.string.defaultGpsDeviceSpeed));

    shouldSetTime = sharedPreferences.getBoolean(USBGpsProviderService.PREF_SET_TIME, false);
    timeSetAlready = true;

    defaultDeviceSpeed = callingService.getString(R.string.defaultGpsDeviceSpeed);
    setDeviceSpeed = !deviceSpeed.equals(callingService.getString(R.string.autoGpsDeviceSpeed));
    sirfGps = sharedPreferences.getBoolean(USBGpsProviderService.PREF_SIRF_GPS, false);
    notificationManager = (NotificationManager) callingService.getSystemService(Context.NOTIFICATION_SERVICE);
    parser.setLocationManager(locationManager);

    Intent stopIntent = new Intent(USBGpsProviderService.ACTION_STOP_GPS_PROVIDER);

    PendingIntent stopPendingIntent = PendingIntent.getService(appContext, 0, stopIntent,
            PendingIntent.FLAG_CANCEL_CURRENT);

    connectionProblemNotificationBuilder = new NotificationCompat.Builder(appContext)
            .setContentIntent(stopPendingIntent).setSmallIcon(R.drawable.ic_stat_notify);

    Intent restartIntent = new Intent(USBGpsProviderService.ACTION_START_GPS_PROVIDER);
    PendingIntent restartPendingIntent = PendingIntent.getService(appContext, 0, restartIntent,
            PendingIntent.FLAG_CANCEL_CURRENT);

    serviceStoppedNotificationBuilder = new NotificationCompat.Builder(appContext)
            .setContentIntent(restartPendingIntent).setSmallIcon(R.drawable.ic_stat_notify)
            .setContentTitle(
                    appContext.getString(R.string.service_closed_because_connection_problem_notification_title))
            .setContentText(
                    appContext.getString(R.string.service_closed_because_connection_problem_notification));

    usbManager = (UsbManager) callingService.getSystemService(Service.USB_SERVICE);

}