void login() {
try {
// 인터넷 연결되어 있나 확인
ConnectivityManager connect = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
if (connect.getNetworkInfo(ConnectivityManager.TYPE_MOBILE)
.getState() == NetworkInfo.State.CONNECTED
|| connect.getNetworkInfo(ConnectivityManager.TYPE_WIFI)
.getState() == NetworkInfo.State.CONNECTED) {
// 연결 돼있는 경우
SharedPreferences pref = getSharedPreferences(
"configPreference", 0);
httpclient = new DefaultHttpClient();
httppost = new HttpPost(SERVER_ADDRESS + "/logcheck.php");
nameValuePairs = new ArrayList<NameValuePair>(4);
nameValuePairs.add(new BasicNameValuePair("serverIP", pref
.getString("serverIp", "").trim()));
nameValuePairs.add(new BasicNameValuePair("DBName", pref
.getString("dbName", "").trim()));
nameValuePairs.add(new BasicNameValuePair("name", edtId
.getText().toString().trim()));
nameValuePairs.add(new BasicNameValuePair("price", edtPW
.getText().toString().trim()));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs, "euc-kr"));
response = httpclient.execute(httppost);
ResponseHandler<String> responseHandler = new BasicResponseHandler();
String response = httpclient.execute(httppost, responseHandler);
runOnUiThread(new Runnable() {
public void run() {
// dialog.dismiss();
}
});
if (response.equalsIgnoreCase(" User Found")) {
runOnUiThread(new Runnable() {
public void run() {
SharedPreferences pref = getSharedPreferences(
"configPreference", 0);
SharedPreferences.Editor edit = pref.edit();
if (pref.getBoolean("idCheck", false) == true) {
edit.putString("userId", edtId.getText()
.toString());
} else {
edit.putString("userId", "");
}
if (pref.getBoolean("pwCheck", false) == true) {
edit.putString("userPW", edtPW.getText()
.toString());
} else {
edit.putString("userPW", "");
}
edit.commit();
}
});
Intent intent = new Intent(MainActivity.this, MainMenuActivity.class);
startActivity(intent);
finish();
} else if (response.equalsIgnoreCase(" No Such User Found")) {
showAlert1();
runOnUiThread(new Runnable() {
public void run() {
}
});
} else {
showAlert2();
}
} else {
// 인터넷 연결 돼있지 않은 경우
AlertDialog.Builder builder = new AlertDialog.Builder(
MainActivity.this);
builder.setTitle("Internet Error.");
builder.setMessage("네트워크를 연결해 주세요.")
.setCancelable(false)
.setPositiveButton("OK",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,
int id) {
}
});
AlertDialog alert = builder.create();
alert.show();
}
} catch (Exception e) {
// dialog.dismiss();
System.out.println("Exception : " + e.getMessage());
}
}
안드로이드에서 mysql 에 접속해서 로그인하는 것을 구현하기 위해서 http통신을 사용했습니다.
이제까지 wifi에서만 테스트를 했었는데 lte로 하니 접속이 안되고
Connection to http://서버주소 refuse
Timeline: Activity_idle id:android.os.BinderProxy@4291b340 time:493356258
이라고 로그캣에 뜨더라구요....
제가 구현한 로직으로 lte나 3g일때 로그인할때 그렇게 시간이 많이 걸릴까요?
왜 그런지 혹시 아시면 도움좀 주세요