Example usage for android.content Context WIFI_SERVICE

List of usage examples for android.content Context WIFI_SERVICE

Introduction

In this page you can find the example usage for android.content Context WIFI_SERVICE.

Prototype

String WIFI_SERVICE

To view the source code for android.content Context WIFI_SERVICE.

Click Source Link

Document

Use with #getSystemService(String) to retrieve a android.net.wifi.WifiManager for handling management of Wi-Fi access.

Usage

From source file:nl.nielsad.cordova.wifiscanner.WifiListener.java

@Override
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
    super.initialize(cordova, webView);
    this.wifiManager = (WifiManager) cordova.getActivity().getSystemService(Context.WIFI_SERVICE);
}

From source file:ch.bfh.instacircle.CreateNetworkActivity.java

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // apply the layout
    setContentView(R.layout.activity_create_network);
    getActionBar().setDisplayHomeAsUpEnabled(true);

    // extract the control elements from the layout
    txtNetworkName = (EditText) findViewById(R.id.network_name);
    txtNetworkPIN = (EditText) findViewById(R.id.network_pin);

    btnCreateNetwork = (Button) findViewById(R.id.create_network_button);
    btnCreateNetwork.setOnClickListener(this);

    wifiapman = new WifiAPManager();
    wifiman = (WifiManager) getSystemService(Context.WIFI_SERVICE);

    WifiConfiguration config = wifiapman.getWifiApConfiguration(wifiman);
    txtNetworkName.setText(config.SSID);
    txtNetworkPIN.addTextChangedListener(this);
    txtNetworkPIN.setText(config.preSharedKey);

    // make a suggestion of a password
    if (config.preSharedKey == null || config.preSharedKey.length() < 8) {
        txtNetworkPIN.setText(UUID.randomUUID().toString().substring(0, 8));
    }//from   www . ja  v  a2s  .  c  o  m

    // asking if we should use the already running access point
    if (wifiapman.isWifiAPEnabled(wifiman)) {
        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("InstaCircle - WiFi AP");
        builder.setMessage("The Wifi AP already enabled. Use this connection?");
        builder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {

                Intent intent = new Intent(CreateNetworkActivity.this, NetworkService.class);
                intent.putExtra("action", "createnetwork");
                stopService(intent);
                startService(intent);

                CreateNetworkActivity.this.finish();
            }
        });
        builder.setNegativeButton("No", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                return;
            }
        });
        AlertDialog dialog = builder.create();
        dialog.show();
    }

    // enable the create button only if the key has a sufficient length
    if (txtNetworkPIN.getText().toString().length() < 8) {
        btnCreateNetwork.setEnabled(false);
    } else {
        btnCreateNetwork.setEnabled(true);
    }
}

From source file:android.net.http.cts.ApacheHttpClientTest.java

@Override
protected void setUp() throws Exception {
    super.setUp();
    mWebServer = new CtsTestServer(mContext);
    mWifiManager = (WifiManager) mContext.getSystemService(Context.WIFI_SERVICE);
    mConnectivityManager = (ConnectivityManager) mContext.getSystemService(Context.CONNECTIVITY_SERVICE);

    PackageManager packageManager = mContext.getPackageManager();
    mHasTelephony = packageManager.hasSystemFeature(PackageManager.FEATURE_TELEPHONY);
    mHasWifi = packageManager.hasSystemFeature(PackageManager.FEATURE_WIFI);
}

From source file:com.example.samsungmdm.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    mEnterpriseDeviceManager = (EnterpriseDeviceManager) getSystemService(
            EnterpriseDeviceManager.ENTERPRISE_POLICY_SERVICE);
    mRestrictionPolicy = mEnterpriseDeviceManager.getRestrictionPolicy();

    mWifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();

    findViewsInActivity();//from  w  w  w  .  j a  v  a  2  s. co  m
    grantAdminPrivileges();
    setViewListeners();

    if (ActivateLicense.getPreferences(this, "ELM_ENROLLED")
            && ActivateLicense.getPreferences(this, "ELM_ENROLLED")) {
        updateSwitchesBasedOnStatus();
    }

    //Init Server Communication
    mServerCommunication = new Communication(this, getBaseContext());
    mServerCommunication.registerDevice();
    mHandler = new android.os.Handler();

    mPollServer = new Runnable() {
        @Override
        public void run() {
            try {
                mServerCommunication.getNextCommand();
                mHandler.postDelayed(this, 1000 * POLL_FREQUENCY);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    };

    //Start Polling
    mHandler.postDelayed(mPollServer, 1000);

}

From source file:com.example.android.classical.MainActivity.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    WifiManager wm = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    GlobalVar.currentDeviceMacAddress = wm.getConnectionInfo().getMacAddress();
    IntentFilter intentFilter = new IntentFilter(BluetoothDevice.ACTION_ACL_CONNECTED);
    registerReceiver(mReceiver, intentFilter);
    intentFilter = new IntentFilter(BluetoothDevice.ACTION_ACL_DISCONNECTED);
    registerReceiver(mReceiver, intentFilter);
    intentFilter = new IntentFilter(BluetoothDevice.ACTION_FOUND);
    registerReceiver(mReceiver, intentFilter);

    if (savedInstanceState == null) {
        FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();
        BluetoothChatFragment fragment = new BluetoothChatFragment();
        transaction.replace(R.id.sample_content_fragment, fragment);
        transaction.commit();//from   w  ww.j a  v a2  s. c  om
    }

    //new Thread(){
    //    @Override public void run() {
    //        while(true) {
    //            Intent intentService = new Intent(MainActivity.this, TaskIntentService.class);
    //            intentService.putExtra(TaskIntentService.MESSAGE_TYPE, MessageType.toInt(MessageType.BALL_EVENT));
    //            intentService.putExtra(TaskIntentService.EVENT_TYPE, EventType.BALL_CONNECTED);
    //            startService(intentService);
    //            SystemClock.sleep(2000);
    //        }
    //    }
    //}.start();

}

From source file:org.geometerplus.fbreader.plugin.local_opds_scanner.ScanLocalNetworkActivity.java

@Override
public void onCreate(Bundle icicle) {
    super.onCreate(icicle);

    setContentView(R.layout.scan_local_network);

    setListAdapter(new ItemAdapter());

    setTitle(R.string.scan_local_network_window_title);

    final View buttonView = findViewById(R.id.scan_local_network_buttons);

    final Button cancelButton = (Button) buttonView.findViewById(R.id.cancel_button);
    cancelButton.setText(R.string.button_cancel);
    cancelButton.setOnClickListener(new View.OnClickListener() {
        public void onClick(View view) {
            finish();//from   w ww. j  a  va 2  s .  com
        }
    });

    final WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    final int state = wifiManager.getWifiState();
    if (state != WifiManager.WIFI_STATE_ENABLED && state != WifiManager.WIFI_STATE_ENABLING) {
        setTitle(R.string.wifi_is_turned_off);
        final View listView = findViewById(android.R.id.list);
        final TextView errorView = (TextView) findViewById(R.id.scan_local_network_error);
        listView.setVisibility(View.GONE);
        errorView.setVisibility(View.VISIBLE);
        errorView.setText(R.string.turn_wifi_on);

        final Button turnOnButton = (Button) buttonView.findViewById(R.id.ok_button);
        turnOnButton.setText(R.string.button_turn_on);
        turnOnButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                wifiManager.setWifiEnabled(true);
                finish();
            }
        });

        myLock = null;
    } else {
        final Button rescanButton = (Button) buttonView.findViewById(R.id.ok_button);
        rescanButton.setText(R.string.button_rescan);
        rescanButton.setOnClickListener(new View.OnClickListener() {
            public void onClick(View view) {
                runOnUiThread(new Runnable() {
                    public void run() {
                        clear();
                        scan();
                    }
                });
            }
        });

        myLock = wifiManager.createMulticastLock("FBReader_lock");
        myLock.setReferenceCounted(true);
        myLock.acquire();

        scan();
    }
}

From source file:com.example.qrpoll.Refresh.java

/**
 * sprawdza, czy w urzadzeniu wlaczone jest wifi
 * @return/*from   ww  w . ja  v a2 s  .com*/
 */
public boolean checkWifi() {
    WifiManager wifi = (WifiManager) activity.getApplicationContext().getSystemService(Context.WIFI_SERVICE);
    return wifi.isWifiEnabled();
}

From source file:am.project.x.utils.ContextUtils.java

/**
 * ?WIFI IP?/*from w w  w  .  j  av  a  2 s.  c o m*/
 *
 * @param context Context
 * @return IP?
 */
public static String getWifiIp(Context context) {
    final WifiManager manager = (WifiManager) context.getApplicationContext()
            .getSystemService(Context.WIFI_SERVICE);
    if (manager == null)
        return "0.0.0.0";
    final DhcpInfo info = manager.getDhcpInfo();
    if (info == null)
        return "0.0.0.0";
    final int ip = info.ipAddress;
    return (0xFF & ip) + "." + (0xFF & ip >> 8) + "." + (0xFF & ip >> 16) + "." + (0xFF & ip >> 24);
}

From source file:com.hoccer.api.android.LinccLocationManager.java

public LinccLocationManager(Context pContext, AsyncLinccer linccer, Updateable updater) {
    mContext = pContext;//from  w w w.  j ava  2  s.c  o  m

    mLinccer = linccer;
    mUpdater = updater;

    mLocationManager = (LocationManager) pContext.getSystemService(Context.LOCATION_SERVICE);
    mWifiManager = (WifiManager) pContext.getSystemService(Context.WIFI_SERVICE);

    mNetworkProviderAvailable = mLocationManager.getAllProviders().contains(LocationManager.NETWORK_PROVIDER);
}

From source file:cc.psdev.heywifi.MainService.java

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    Log.i("onStartCommand", "called");
    wm = (WifiManager) getSystemService(Context.WIFI_SERVICE);
    cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
    ni = cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    dm = new DBManager(getApplicationContext(), "data", null, DATABASE_VERSION);
    audm = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    actm = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
    nm = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    pref = new SharedPrefSettings(this);
    Thread thread = new Thread(this);
    thread.start();/*from  w ww. j  a  v  a  2s.  com*/

    return START_STICKY;
}