Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class WifiReceiver extends BroadcastReceiver {
- private static final String TAG = "WifiReceiver";
- @Override
- public void onReceive(Context context, Intent intent) {
- NetworkInfo networkInfo = intent.getParcelableExtra(WifiManager.EXTRA_NETWORK_INFO);
- if (networkInfo != null && networkInfo.isConnected()) {
- WifiInfo wifiInfo = intent.getParcelableExtra(WifiManager.EXTRA_WIFI_INFO);
- String ssid = wifiInfo.getSSID();
- Toast.makeText(context, "Conectado a: " + ssid, Toast.LENGTH_SHORT).show();
- Log.i(TAG, "Connected to : " + ssid);
- }else{
- Log.e(TAG, "Network not connnected!");
- }
- }
- }
- public class HelperConnection extends AppCompatActivity {
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_helper_connection);
- this.setTitle("Login UCF");
- getSupportActionBar().setDisplayHomeAsUpEnabled(true);
- bindUI();
- Toast.makeText(this, "Siga los pasos para establecer conexión con la red", Toast.LENGTH_LONG)
- .show();
- btnNext.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- if (textInputUser.getText().length() == 0)
- textInputUser.setError("Campo requerido");
- else if (textInputPassw.getText().length() == 0)
- textInputPassw.setError("Campo requerido");
- else {
- mViewFlipper.setInAnimation(AnimationUtils.loadAnimation(mContext, R.anim.in_from_left));
- mViewFlipper.setOutAnimation(AnimationUtils.loadAnimation(mContext, R.anim.out_from_left));
- mViewFlipper.showNext();
- getSupportActionBar().setDisplayHomeAsUpEnabled(false);
- progressBar.performClick();
- if (wifiManager.isWifiEnabled()) {
- wifiManager.removeNetwork(wifiManager.getConnectionInfo().getNetworkId());
- detectWifi();
- } else {
- wifiManager.setWifiEnabled(true);
- wifiManager.removeNetwork(wifiManager.getConnectionInfo().getNetworkId());
- detectWifi();
- }
- }
- }
- });
- btnFinish.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- Intent intent = new Intent(HelperConnection.this, LoginActivity.class);
- intent.putExtra("runWeb", true);
- intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
- intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
- finish();
- startActivity(intent);
- }
- });
- }
- private void bindUI() {
- mViewFlipper = (ViewFlipper) findViewById(R.id.view_flipper);
- mContext = this;
- btnFinish = (Button) findViewById(R.id.btnFinish);
- btnNext = (Button) findViewById(R.id.btnNext);
- progressBar = (ProgressBar) findViewById(R.id.load_steps_login);
- wifiManager = (WifiManager) getSystemService(WIFI_SERVICE);
- textInputPassw = (TextInputEditText) findViewById(R.id.edit_text_passw);
- textInputUser = (TextInputEditText) findViewById(R.id.edit_text_user);
- loginActivity = new LoginActivity();
- }
- private void tryConnection() {
- loginActivity.helperConnect(wifiManager);
- Toast.makeText(this, "Espere...", Toast.LENGTH_SHORT).show();
- IntentFilter intentFilter = new IntentFilter();
- intentFilter.addAction(WifiManager.NETWORK_STATE_CHANGED_ACTION);
- WifiReceiver wifiReceiver = new WifiReceiver();
- registerReceiver(wifiReceiver, intentFilter);
- }
- if (networkInfo != null && networkInfo.isConnected()) {
- WifiInfo wifiInfo = intent.getParcelableExtra(WifiManager.EXTRA_WIFI_INFO);
- String ssid = wifiInfo.getSSID();
- for(final WifiChangeListener listener : listeners) {
- listener.onWifiChange(ssid);
- }
- }
Add Comment
Please, Sign In to add comment