0

Hello Everyone I'm having problem in my android application. I have android app install in ubuntu 16.0.4 which work fine in my work pc but when I imports my app in window 8.1. From login it doesnot work. First Off My android studio doesn't recognized my mobile in window 8.1 so I have install pdaNet and it work fine. when I debug my code An established connection was aborted by the software in your host machine ConnectivityManager return both true as well as false. It never did in linux

  ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);

    if (connectivityManager != null) {
        NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
        if (networkInfo != null && networkInfo.isAvailable()
                && networkInfo.isConnected()) {
            return true;
        } else {
            return false;
        }
    } else {
        return false;
    }

I dont know what's the problem with window 8.1 but I connected my mobile with my laptop sharing same wifi and web services run on

http://192.168.0.102:8080/payroll-services-ws/api/secured/message

and When I checked on Postman, It is working correctly..

So here is my code of login

public class Login extends AppCompatActivity {

private ProgressBar progressBar;
List<MyTask> myTasksList;
private static final String RESTLOGIN="http://192.168.0.102:8080/payroll-services-ws/api/secured/message";
private EditText usernameEditText;
private EditText passwordEdittext;



@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login);
    progressBar =(ProgressBar)findViewById(R.id.progressBarLogin);
    progressBar.setVisibility(View.INVISIBLE);
    myTasksList = new ArrayList<>();

    usernameEditText = (EditText)findViewById(R.id.etUsername);
    passwordEdittext = (EditText)findViewById(R.id.etPass);
}

public void onBtnClick(View view){
    Button buttonLogin = (Button)findViewById(R.id.btnSingIn);
    if (view.getId()==R.id.btnSingIn){
        //updateDisplay();
        if (isOnline()){
            requestData(RESTLOGIN);
        }
        else{
            Toast.makeText(Login.this, "Not Connect WIth Network", Toast.LENGTH_LONG).show();
        }
    }
    else if (view.getId()==R.id.btnSignUp){
        Intent intent = new Intent(Login.this,Register.class);
        startActivity(intent);
    }
}
protected boolean isOnline(){
    ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);

    if (connectivityManager != null) {
        NetworkInfo networkInfo = connectivityManager.getActiveNetworkInfo();
        if (networkInfo != null && networkInfo.isAvailable()
                && networkInfo.isConnected()) {
            return true;
        } else {
            return false;
        }
    } else {
        return false;
    }
}
private void requestData(String uri){
    MyTask myTask = new MyTask();
    myTask.execute(uri,usernameEditText.getText().toString(),passwordEdittext.getText().toString());
}
public void updateDisplay(){
    Toast.makeText(Login.this, "Login Successfull", Toast.LENGTH_SHORT).show();
    Intent mainActivity = new Intent(Login.this,Home.class);
    mainActivity.putExtra("username",usernameEditText.getText().toString());
    mainActivity.putExtra("password",passwordEdittext.getText().toString());
    startActivity(mainActivity);
}
//param progress and result
private class MyTask extends AsyncTask<String,String,String>{
    @Override
    protected void onPreExecute() {
        if (myTasksList.size()==0){
            progressBar.setVisibility(View.VISIBLE);
        }
        myTasksList.add(this);
    }


    @Override
    protected String doInBackground(String... params) {
        //param 0 which is come from requestData
        String content = HttpManager.getData(params[0],params[1],params[2]);
        return content;

    }

    //content of dobackground pass to the dopostexcute
    @Override
    protected void onPostExecute(String result) {

        myTasksList.remove(this);
        if (myTasksList.size()==0){
            progressBar.setVisibility(View.INVISIBLE);
        }
        if (result==null){
            Toast.makeText(Login.this,"Sorry Username or password doesnot match",Toast.LENGTH_LONG).show();
            return;
        }

        //list of object from content
        //from json

        updateDisplay();
    }

}

}

I can only access in postman via localhost:8080

Bibek Shakya
  • 1,233
  • 2
  • 23
  • 45
  • What is the problem? The Android code, or the actual server? – OneCricketeer Jul 21 '16 at 23:27
  • code is fine im sure but i cant access it by using 192.168.0.102:8080 address on both postman and with android – Bibek Shakya Jul 21 '16 at 23:31
  • 1
    Okay, when you use postman on the same computer, though, `127.0.0.1`, or `192.168.0.102` just fallback to `127.0.0.1` in the routing table. If you cannot access `192.168.0.102` on a separate device in the LAN, then that is a networking problem. 1) The server must be publicly accessible and 2) The port must be listening, then 3) The firewall must be open to allow the port – OneCricketeer Jul 21 '16 at 23:34
  • how can I do it??? In server side i have no problem it is working fine in linux. – Bibek Shakya Jul 21 '16 at 23:37
  • 1
    I don't know. There is not enough detail here to help, and I don't think the problem is the Android code if it all works in linux. – OneCricketeer Jul 21 '16 at 23:47
  • thank u sir for ur kind infromation. – Bibek Shakya Jul 21 '16 at 23:49

1 Answers1

0

problem occur due to the firewall of window 8.1 are blocking any public IP address, So editing the firewall setting esp TCP 80 port solve the problem for me.

Bibek Shakya
  • 1,233
  • 2
  • 23
  • 45