Example usage for android.net ConnectivityManager CONNECTIVITY_ACTION

List of usage examples for android.net ConnectivityManager CONNECTIVITY_ACTION

Introduction

In this page you can find the example usage for android.net ConnectivityManager CONNECTIVITY_ACTION.

Prototype

String CONNECTIVITY_ACTION

To view the source code for android.net ConnectivityManager CONNECTIVITY_ACTION.

Click Source Link

Document

A change in network connectivity has occurred.

Usage

From source file:com.nbplus.vbroadlauncher.RealtimeBroadcastActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    overridePendingTransition(R.anim.fade_in, R.anim.fade_out);
    acquireCpuWakeLock();//from  w  w w .j a va  2s  . co m

    KeyguardManager km = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
    km.inKeyguardRestrictedInputMode();
    if (km.inKeyguardRestrictedInputMode()) {
        Log.i(TAG, " ??");
        isKeyguardRestrictedInputMode = true;
    } else {
        Log.i(TAG, "   ??");
    }

    mLastNetworkStatus = NetworkUtils.isConnected(this);
    Intent intent = getIntent();
    if (intent == null || !PushConstants.ACTION_PUSH_MESSAGE_RECEIVED.equals(intent.getAction())) {
        Log.d(TAG, "empty or none broadcast intent value ...");
        finishActivity();
        return;
    }

    mBroadcastData = intent.getParcelableExtra(Constants.EXTRA_BROADCAST_PAYLOAD_DATA);
    if (mBroadcastData == null) {
        Log.d(TAG, ">> payload data is null");
        finishActivity();
        return;
    }

    mBroadcastPayloadIdx = intent.getLongExtra(Constants.EXTRA_BROADCAST_PAYLOAD_INDEX, -1);
    Log.d(TAG, ">> onCreate() mBroadcastPayloadIdx= " + mBroadcastPayloadIdx);

    // ? ms  ? ?? ? ?   ?  ????
    // broadcast ? .
    //  ?? ?? ??.
    Intent i = new Intent(this, RealtimeBroadcastActivity.class);
    i.setAction(intent.getAction());
    i.putExtra(Constants.EXTRA_BROADCAST_PAYLOAD_DATA, mBroadcastData);
    i.putExtra(Constants.EXTRA_BROADCAST_PAYLOAD_INDEX, mBroadcastPayloadIdx);
    LocalBroadcastManager.getInstance(this).sendBroadcast(i);

    IntentFilter filter = new IntentFilter();
    filter.addAction(PushConstants.ACTION_PUSH_MESSAGE_RECEIVED);
    filter.addAction(Constants.ACTION_BROWSER_ACTIVITY_CLOSE);
    LocalBroadcastManager.getInstance(this).registerReceiver(mBroadcastReceiver, filter);

    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
    registerReceiver(mBroadcastReceiver, intentFilter);

    hideSystemUI();
    /*
    final Window win = getWindow();
    win.setFlags(
        WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
                | WindowManager.LayoutParams.FLAG_FULLSCREEN
                | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
                | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD,
        WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
                | WindowManager.LayoutParams.FLAG_FULLSCREEN
                | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
                | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
            
    win.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
                | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON
                | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
                | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
                | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON);
    */

    if (Constants.PUSH_PAYLOAD_TYPE_TEXT_BROADCAST.equals(mBroadcastData.getServiceType())) {
        setContentView(R.layout.fragment_text_broadcast);
    } else {
        setContentView(R.layout.fragment_audio_broadcast);
    }
    getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
            | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);

    if (Constants.PUSH_PAYLOAD_TYPE_TEXT_BROADCAST.equals(mBroadcastData.getServiceType())) {
        mcheckText2SpeechLister = this;
        // ?
        mTextView = (TextView) findViewById(R.id.broadcast_text);
        mTextView.setText(mBroadcastData.getMessage());
        mTextView.setVerticalScrollBarEnabled(true);
        mTextView.setHorizontalScrollBarEnabled(false);
        mTextView.setMovementMethod(new ScrollingMovementMethod());

        mHandler.sendEmptyMessageDelayed(HANDLER_MESSAGE_SETUP_CURRENT_PLAYING, 800);
        Log.d(TAG, "text broadcast = " + mBroadcastData.getMessage());

        mText2SpeechHandler = new TextToSpeechHandler(this, this);
        checkText2SpeechAvailable();
        mIsTTS = true;
    } else {
        // , ??
        mWebView = (WebView) findViewById(R.id.webview);
        mWebViewClient = new RealtimeBroadcastWebViewClient(this, mWebView, this);
        mWebViewClient.setBackgroundTransparent();

        String url = mBroadcastData.getMessage();
        if (url.indexOf("?") > 0) {
            if (!url.contains("UUID=")) {
                url += ("&UUID=" + LauncherSettings.getInstance(this).getDeviceID());
            }
            if (!url.contains("APPID=")) {
                url += ("&APPID=" + getApplicationContext().getPackageName());
            }
        } else {
            if (!url.contains("UUID=")) {
                url += ("?UUID=" + LauncherSettings.getInstance(this).getDeviceID());
            }
            if (!url.contains("APPID=")) {
                if (!url.contains("UUID=")) {
                    url += ("?APPID=" + getApplicationContext().getPackageName());
                } else {
                    url += ("&APPID=" + getApplicationContext().getPackageName());
                }
            }
        }

        mWebViewClient.loadUrl(url);
        mIsTTS = false;
    }
    AudioManager audio = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    mStreamMusicVolume = audio.getStreamVolume(AudioManager.STREAM_MUSIC);
    audio.setStreamVolume(AudioManager.STREAM_MUSIC, audio.getStreamMaxVolume(AudioManager.STREAM_MUSIC),
            AudioManager.FLAG_PLAY_SOUND);

    if (Constants.OPEN_BETA_PHONE && LauncherSettings.getInstance(this).isSmartPhone()) {
        StateListener phoneStateListener = new StateListener();
        TelephonyManager telephonyManager = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
        telephonyManager.listen(phoneStateListener, PhoneStateListener.LISTEN_CALL_STATE);
    }
}

From source file:org.alfresco.mobile.android.application.activity.MainActivity.java

@Override
protected void onStart() {
    registerPublicReceiver(new NetworkReceiver(), new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));

    super.onStart();
    AccountOAuthHelper.requestRefreshToken(getCurrentSession(), this);
    FavoritesSyncManager.getInstance(this).cronSync(currentAccount);
}

From source file:indrora.atomic.irc.IRCService.java

/**
 * On create//from   w  ww  .j a va 2s . c o m
 */
@Override
public void onCreate() {
    super.onCreate();
    _netTransitionHandler = new NetworkTransitionHandler(this);
    settings = new Settings(getBaseContext());
    notificationManager = (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;
    }

    // Load servers from Database
    Database db = new Database(this);
    Atomic.getInstance().setServers(db.getServers());
    db.close();

    // Broadcast changed server list
    sendBroadcast(new Intent(Broadcast.SERVER_UPDATE));

    // Set up our connectivity handler
    registerReceiver(_netTransitionHandler, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));

}

From source file:com.futureplatforms.kirin.extensions.networking.NetworkingBackend.java

private void listenForChangeInNetworkStatus() {
    Log.i(C.TAG, "NetworkingBackend.listenForChangeInNetworkStatus: ");
    mReceiver = new BroadcastReceiver() {

        @Override//from w  ww .  j  a  v  a  2s  . c om
        public void onReceive(Context context, Intent intent) {
            if (intent.getBooleanExtra(ConnectivityManager.EXTRA_NO_CONNECTIVITY, false)) {
                String reason = intent.getStringExtra(ConnectivityManager.EXTRA_REASON);
                if (reason == null || reason.trim().length() == 0) {
                    reason = mContext.getString(R.string.networking_connection_lost);
                }
                cancelAllDownloads(reason);
            }
        }

    };
    mContext.registerReceiver(mReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));

}

From source file:com.autoupdateapk.AutoUpdateApk.java

private void setupVariables(Context ctx) {
    context = ctx;/*  w  ww .ja v a 2 s.  c o m*/

    packageName = context.getPackageName();
    preferences = context.getSharedPreferences(packageName + "_" + TAG, Context.MODE_PRIVATE);
    device_id = crc32(Secure.getString(context.getContentResolver(), Secure.ANDROID_ID));
    last_update = preferences.getLong("last_update", 0);
    NOTIFICATION_ID += crc32(packageName);
    // schedule.add(new ScheduleEntry(0,24));

    ApplicationInfo appinfo = context.getApplicationInfo();
    if (appinfo.icon != 0) {
        appIcon = appinfo.icon;
    } else {
        Log_w(TAG, "unable to find application icon");
    }

    //appName = context.getString(appinfo.labelRes); NON!
    appName = (String) context.getPackageManager().getApplicationLabel(appinfo);
    if (appName != null) {
        Log_w(TAG, "application name = " + appName);
    } else {
        Log_w(TAG, "unable to find application label");
    }
    if (new File(appinfo.sourceDir).lastModified() > preferences.getLong(MD5_TIME, 0)) {
        preferences.edit().putString(MD5_KEY, MD5Hex(appinfo.sourceDir)).commit();
        preferences.edit().putLong(MD5_TIME, System.currentTimeMillis()).commit();

        String update_file = preferences.getString(UPDATE_FILE, "");
        if (update_file.length() > 0) {
            if (new File(context.getFilesDir().getAbsolutePath() + "/" + update_file).delete()) {
                preferences.edit().remove(UPDATE_FILE).remove(SILENT_FAILED).commit();
            }
        }
    }

    // hack
    preferences.edit().remove(SILENT_FAILED).commit();

    raise_notification();

    if (haveInternetPermissions()) {
        context.registerReceiver(connectivity_receiver,
                new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
    }
}

From source file:com.scooter1556.sms.android.service.MediaService.java

@RequiresApi(api = Build.VERSION_CODES.O)
@Override/*ww  w .j a v  a2 s .  co  m*/
public void onCreate() {
    super.onCreate();

    Log.d(TAG, "onCreate()");

    restService = RESTService.getInstance();

    // Retrieve preferences if they exist
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);

    // Load default settings
    PreferenceManager.setDefaultValues(this, R.xml.preferences, false);

    // Initialise database
    ConnectionDatabase db = new ConnectionDatabase(this);

    // Check connection
    long id = sharedPreferences.getLong("Connection", -1);

    if (id >= 0) {
        Connection connection = db.getConnection(id);
        restService.setConnection(connection);
        isConnected = true;
    } else {
        isConnected = false;
    }

    queueManager = new QueueManager(getApplicationContext(), new QueueManager.MetadataUpdateListener() {
        @Override
        public void onMetadataChanged(MediaMetadataCompat metadata) {
            Log.d(TAG, "onMetadataChanged()");

            mediaSession.setMetadata(metadata);
        }

        @Override
        public void onMetadataRetrieveError() {
            Log.d(TAG, "onMetadataRetrieveError()");

            playbackManager.updatePlaybackState(getString(R.string.error_no_metadata));
        }

        @Override
        public void onCurrentQueueIndexUpdated(int queueIndex) {
            Log.d(TAG, "onCurrentQueueIndexUpdated(" + queueIndex + ")");

            playbackManager.handlePlayRequest();
        }

        @Override
        public void onQueueUpdated(List<MediaSessionCompat.QueueItem> newQueue) {
            Log.d(TAG, "onQueueUpdated()");

            mediaSession.setQueue(newQueue);
            mediaSession.setQueueTitle("Now Playing");
        }
    });

    // Initialise playback manager
    playbackManager = PlaybackManager.getInstance();
    playbackManager.initialise(getApplicationContext(), this, queueManager);

    // Start a new Media Session
    mediaSession = new MediaSessionCompat(this, MediaService.class.getSimpleName());
    mediaSession.setCallback(playbackManager.getMediaSessionCallback());
    mediaSession.setFlags(
            MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS | MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS
                    | MediaSessionCompat.FLAG_HANDLES_QUEUE_COMMANDS);

    Context context = getApplicationContext();
    Intent intent = new Intent(context, NowPlayingActivity.class);
    PendingIntent pendingIntent = PendingIntent.getActivity(context, 99, intent,
            PendingIntent.FLAG_UPDATE_CURRENT);
    mediaSession.setSessionActivity(pendingIntent);

    mediaSessionExtras = new Bundle();
    AutoUtils.setSlotReservationFlags(mediaSessionExtras, true, true, true);
    mediaSession.setExtras(mediaSessionExtras);

    setSessionToken(mediaSession.getSessionToken());

    try {
        mediaNotificationManager = new MediaNotificationManager(this);
    } catch (RemoteException e) {
        throw new IllegalStateException("Could not create a MediaNotificationManager", e);
    }

    if (!TVUtils.isTvUiMode(this)) {
        castSessionManager = CastContext.getSharedInstance(this).getSessionManager();
        castSessionManagerListener = new CastSessionManagerListener();
        castSessionManager.addSessionManagerListener(castSessionManagerListener, CastSession.class);
    }

    mediaRouter = MediaRouter.getInstance(getApplicationContext());

    registerCarConnectionReceiver();

    // Register connectivity receiver
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
    this.registerReceiver(connectivityChangeReceiver, intentFilter);
}

From source file:eu.faircode.netguard.SinkholeService.java

@Override
public void onCreate() {
    super.onCreate();
    Log.i(TAG, "Create");

    HandlerThread thread = new HandlerThread(getString(R.string.app_name));
    thread.start();//from  ww  w . j  a  v a  2 s  .  c  o m

    mServiceLooper = thread.getLooper();
    mServiceHandler = new ServiceHandler(mServiceLooper);

    // Listen for interactive state changes
    IntentFilter ifInteractive = new IntentFilter();
    ifInteractive.addAction(Intent.ACTION_SCREEN_ON);
    ifInteractive.addAction(Intent.ACTION_SCREEN_OFF);
    registerReceiver(interactiveStateReceiver, ifInteractive);

    // Listen for connectivity updates
    IntentFilter ifConnectivity = new IntentFilter();
    ifConnectivity.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
    registerReceiver(connectivityChangedReceiver, ifConnectivity);

    // Listen for added applications
    IntentFilter ifPackage = new IntentFilter();
    ifPackage.addAction(Intent.ACTION_PACKAGE_ADDED);
    ifPackage.addDataScheme("package");
    registerReceiver(packageAddedReceiver, ifPackage);
}

From source file:de.tudresden.inf.rn.mobilis.mxa.XMPPRemoteService.java

@Override
public IBinder onBind(Intent intent) {
    // Workaround for ServiceDiscoveryManager: this class has a static
    // initializer which is not called in the right moment. That is why
    // we repeat its code here.
    XMPPConnection.addConnectionCreationListener(new ConnectionCreationListener() {
        @Override//from  ww w  .ja  va 2  s. co m
        public void connectionCreated(Connection connection) {
            new ServiceDiscoveryManager(connection);
        }
    });
    // initialize and start worker threads
    xmppWriteWorker = new WriterThread();
    xmppWriteWorker.start();
    xmppReadWorker = new ReaderThread();
    xmppReadWorker.start();

    // read in preferences
    mPreferences = getSharedPreferences("de.tudresden.inf.rn.mobilis.mxa_preferences", Context.MODE_PRIVATE);
    // initialize IQ executor
    mWriteExecutor = Executors.newCachedThreadPool();

    // build the monitor and register the events
    mNetworkMonitor = new NetworkMonitor(this);
    IntentFilter filter = new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION);
    registerReceiver(mNetworkMonitor, filter);

    mIQQueue = new LostIQQueue();
    mIQQueueTimer = new Timer();

    Log.v(TAG, "count: " + mIQQueue.getCount());

    // initialize other members
    mOwnResources = new ArrayList<String>();

    // testIQQueue();
    // testIQ();
    // testHandler();
    // mIQDatabase.printAllEntries();
    return mBinder;
}

From source file:org.eeiiaa.wifi.WifiConnector.java

@Override
    public void onReceive(Context context, Intent intent) {
        // handle stuff related to scanning requested when:
        // normal scan is issued
        // when forgetting a network and re-connecting to a previously configured
        // existing one
        // when connecting and need a scan to verify connection can be established
        Log.i(TAG, "action: " + intent.getAction());
        if (intent.getAction().equals(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION) && (mWaitingScan || mConnecting)) {
            // forgetting current and reconnecting to highest priority existing
            // network

            Log.i(TAG, "ACTION SCAN: mWaitingScan:" + mWaitingScan + " connecting " + mConnecting);

            // normal scan request
            if (mWaitingScan) {
                String json = new String();
                switch (scanResultOption) {
                case GET_ALL:
                    json = getScannedNetworksAllJSON();
                    break;
                case GET_BSSID_ONLY:
                    json = getScannedNetworksJSON();
                    break;
                }// www  .  jav a  2  s .  c o  m
                mScanListener.scanResultsJSON(json);
                mWaitingScan = false;

                // scan is done - unregister
                mContext.unregisterReceiver(this);
                Log.i(TAG, "processing scan results as JSON");

            }

            if (mConnecting && !mWaitingConnection) {
                // look for the network we want to connect to in the scanned results
                ScanResult scannedNet = searchNetwork(mNetssid);
                if (scannedNet == null) {
                    Log.i(TAG, "ssid not found...: " + mNetssid);
                    mConnecting = false;
                    mContext.unregisterReceiver(this);
                    notifyConnectionFailed();
                    return; // didn't find requested network noting to connect
                }

                WifiConfiguration configuredNet = searchConfiguration(scannedNet);
                boolean result_ok = false;

                if (configuredNet != null) {
                    // configuration exits connect to a configured network
                    mWaitingConnection = true;
                    result_ok = Wifi.connectToConfiguredNetwork(mContext, mWifiMgr, configuredNet, false);
                    Log.i(TAG, "configuration exits connect to a configured network");
                } else {
                    // configure and connect to network
                    mWaitingConnection = true;
                    result_ok = Wifi.connectToNewNetwork(mContext, mWifiMgr, scannedNet, mPwd, MAX_OPEN_NETS);
                    Log.i(TAG, "configure and connect to network");
                }

                // failed to connect - unregister and notify
                if (!result_ok) {
                    mContext.unregisterReceiver(this);
                    mWaitingConnection = false;
                    mConnecting = false;
                    Log.e(TAG, "error connecting Wifi.connect returned error");
                    notifyConnectionFailed();
                }
            }
        }

        else if (intent.getAction().equals(ConnectivityManager.CONNECTIVITY_ACTION)
                && (mConnected || (mConnecting && mWaitingConnection))) {
            Log.i(TAG, "ACTION CONNECTIVITY: mWaitingScan:" + mWaitingScan + " forgetting: " + forgetting_
                    + " connecting " + mConnecting);

            NetworkInfo networkInfo = intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO);

            if (!mConnected && networkInfo.getType() == ConnectivityManager.TYPE_WIFI
                    && networkInfo.isConnected()) {

                if (mWifiMgr.getConnectionInfo().getSupplicantState() == SupplicantState.COMPLETED) {

                    Log.i(TAG, " getConnectionInfo: " + mWifiMgr.getConnectionInfo() + " getSSID: "
                            + mWifiMgr.getConnectionInfo().getSSID());
                    String connectionSsid = unQuote(mWifiMgr.getConnectionInfo().getSSID());
                    // when phone turns into AP mode, wifimgr returns null...
                    // fail protection for such cases...
                    if (connectionSsid != null) {
                        Log.i(TAG, "mNetssid: |" + mNetssid + "| connectionSsid |" + connectionSsid + "|");
                        if (connectionSsid.equals(mNetssid)) {
                            mConnected = true;
                            mConnecting = false;
                            mWaitingConnection = false;
                            forgetting_ = false;

                            Log.i(TAG, "VERIFIED SUCCESSFUL CONNECTION to: " + mNetssid);
                            // connection done notify - do not unregister to get disconnection detected
                            notifyConnectionListener();
                        }
                    }
                }
            } else if (mConnected && networkInfo.getType() == ConnectivityManager.TYPE_WIFI
                    && !networkInfo.isConnected()) {

                Log.i(TAG, "network is disconnected...");

                // Wifi is disconnected
                mConnected = false;
                mWaitingConnection = false;
                if (mDataListener != null && used_ != null) {
                    used_.updateUsageCounters();
                    transmitted = used_.getWifiTransmitted();
                    received = used_.getWifiReceived();
                }
                // network lost was not expected (when forgetting we expect network to
                // be lost)
                if (!forgetting_) {
                    Log.i(TAG, "network lost " + networkInfo);
                    notifyNetworkLost(networkInfo);
                    mContext.unregisterReceiver(this);
                } else {
                    Log.i(TAG, "network lost when forgetting " + networkInfo);
                }
            }

            Log.i(TAG, "end of CONNECTIVITY_ACTION");
        }

    }

From source file:co.beem.project.beem.FacebookTextService.java

/**
 * {@inheritDoc}/*from  w w w  .  j ava2s  . com*/
 */
@Override
public void onCreate() {
    super.onCreate();
    smackAndroid = SmackAndroid.init(FacebookTextService.this);
    StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
    StrictMode.setThreadPolicy(policy);
    savingMessageQueue = new LinkedBlockingQueue<co.beem.project.beem.service.Message>();
    loadingUserAvatarQueue = new LinkedBlockingDeque<String>();
    stateChangeQueue = new LinkedBlockingQueue<User>();
    databaseHelper = getHelper();
    try {
        setupDatabaseConnection();
    } catch (Exception e) {
        e.printStackTrace();
    }
    isRunning = true;
    sessionManager = new SessionManager(FacebookTextService.this);
    savingMessageOnBackgroundThread(new SavingNewMessageTask());
    savingMessageOnBackgroundThread(new UpdateUserStateTask());
    handler = new Handler();
    registerReceiver(mReceiver, new IntentFilter(ConnectivityManager.CONNECTIVITY_ACTION));
    registerReceiver(mOnOffReceiver, new IntentFilter(FacebookTextApplication.GET_AVATAR));
    registerReceiver(mOnOffReceiver, new IntentFilter(FacebookTextApplication.UPDATE_USER_STATE));
    registerReceiver(mOnOffReceiver,
            new IntentFilter(FacebookTextApplication.PUSH_NOTIFICATION_FAVORITE_ONLINE));
    mSettings = PreferenceManager.getDefaultSharedPreferences(this);
    mSettings.registerOnSharedPreferenceChangeListener(mPreferenceListener);
    if (mSettings.getBoolean(FacebookTextApplication.USE_AUTO_AWAY_KEY, false)) {
        mOnOffReceiverIsRegistered = true;
        registerReceiver(mOnOffReceiver, new IntentFilter(Intent.ACTION_SCREEN_OFF));
        registerReceiver(mOnOffReceiver, new IntentFilter(Intent.ACTION_SCREEN_ON));
        // registerReceiver(sma, filter)
    }
    String tmpJid = mSettings.getString(FacebookTextApplication.ACCOUNT_USERNAME_KEY, "").trim();
    mLogin = StringUtils.parseName(tmpJid);
    boolean useSystemAccount = mSettings.getBoolean(FacebookTextApplication.USE_SYSTEM_ACCOUNT_KEY, false);
    mPort = DEFAULT_XMPP_PORT;
    mService = StringUtils.parseServer(tmpJid);
    mHost = mService;
    initMemorizingTrustManager();

    if (mSettings.getBoolean(FacebookTextApplication.ACCOUNT_SPECIFIC_SERVER_KEY, false)) {
        mHost = mSettings.getString(FacebookTextApplication.ACCOUNT_SPECIFIC_SERVER_HOST_KEY, "").trim();
        if ("".equals(mHost))
            mHost = mService;
        String tmpPort = mSettings.getString(FacebookTextApplication.ACCOUNT_SPECIFIC_SERVER_PORT_KEY, "5222");
        if (!"".equals(tmpPort))
            mPort = Integer.parseInt(tmpPort);
    }
    if (mSettings.getBoolean(FacebookTextApplication.FULL_JID_LOGIN_KEY, false) || "gmail.com".equals(mService)
            || "googlemail.com".equals(mService) || useSystemAccount) {
        mLogin = tmpJid;
    }

    configure(ProviderManager.getInstance());

    mNotificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);

    Roster.setDefaultSubscriptionMode(SubscriptionMode.manual);
    mBind = new XmppFacade(this);
    savingMessageOnBackgroundThread(new DownloadAvatarTask());
    Log.d(TAG, "Create FacebookTextService \t id: " + mLogin + " \t host: " + mHost + "\tmPort" + mPort
            + "\t service" + mService);
}