Пример #1
0
  /**
   * ***************************************************
   *
   * <p>Private methods
   *
   * <p>****************************************************
   */
  private void initialize() {
    Logs.d(TAG, "# Service : initialize ---");

    // Get content manager instance
    mContentManager = ContentManager.getInstance(mContext, this);
    // Get connection info instance
    mConnectionInfo = ConnectionInfo.getInstance(mContext);

    // Set notification broadcast receiver
    mReceiver = new NotificationReceiver();
    IntentFilter filter = new IntentFilter();
    filter.addAction(Constants.NOTIFICATION_LISTENER);
    registerReceiver(mReceiver, filter);

    // Set battery broadcast receiver
    IntentFilter iFilter = new IntentFilter();
    iFilter.addAction(Intent.ACTION_BATTERY_CHANGED);
    registerReceiver(mBatteryInfoReceiver, iFilter);

    // Set SMS listener
    IntentFilter smsFilter = new IntentFilter();
    smsFilter.addAction("android.provider.Telephony.SMS_RECEIVED");
    registerReceiver(mSmsListener, smsFilter);

    // Set telephony listener
    TelephonyStateListener telephonyListener = new TelephonyStateListener();
    TelephonyManager telephony =
        (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE);
    telephony.listen(telephonyListener, PhoneStateListener.LISTEN_SERVICE_STATE);
    telephony.listen(telephonyListener, PhoneStateListener.LISTEN_CALL_STATE);

    // Get local Bluetooth adapter
    mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

    // If the adapter is null, then Bluetooth is not supported
    if (mBluetoothAdapter == null) {
      Toast.makeText(this, "Bluetooth is not available", Toast.LENGTH_LONG).show();
      return;
    }

    if (!mBluetoothAdapter.isEnabled()) {
      // BT is not on, need to turn on manually.
      // Activity will do this.
    } else {
      if (mBtManager == null) {
        setupBT();
      }
    }
  }