마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

안드로이드 로그인 구현

0 추천

apm이랑 이클립스로 인터넷에 나온 예제 보고 만들었는데요

회원가입없이 mysql에 있는 테이블에 직접 아이디랑 비밀번호 넣고 안드로이드 로그인 화면에서 로그인하면

데이터를 찾아서 성공시키는 것을 하려고 하는데

로그인버튼을 막상 누르면 로딩만 되고 데이터를 못불러오는것 같더라구요 뭐가 문제인지 모르겠어서 질문드려요

안드로이드 완전 생초보 입니다 ㅜㅜ

 

main.java

public class MainActivity extends Activity{ 
ViewFlipper vf; //웹뷰로드
Button Btnlogin;
EditText inputID, inputPW;
HttpPost httppost;
HttpResponse response;
HttpClient httpclient;
List<NameValuePair> nameValuePairs;
ProgressDialog dialog = null;
//LinearLayout layout01;
 
//private static final String SERVER_ADDRESS = "http://내아이피:8080";
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
      
        StrictMode.ThreadPolicy Policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
        StrictMode.setThreadPolicy(Policy);
        
        Btnlogin = (Button)findViewById(R.id.login);
        inputID = (EditText)findViewById(R.id.idlogin);
        inputPW = (EditText)findViewById(R.id.pwlogin);
        
        Btnlogin.setOnClickListener(new OnClickListener(){
        public void onClick(View v){
        dialog = ProgressDialog.show(MainActivity.this,"","validating user...",true);
        new Thread(new Runnable(){
        public void run(){
        Looper.prepare();
        login();
        Looper.loop();
        }
        }).start();
        }
        });
        }
    
void login(){
try{
httpclient=new DefaultHttpClient(); 
httppost=new HttpPost("http://내아이피:8080/logcheck.php");
nameValuePairs = new ArrayList<NameValuePair>(2);
nameValuePairs.add(new BasicNameValuePair("id",inputID.getText().toString()));
nameValuePairs.add(new BasicNameValuePair("password",inputPW.getText().toString()));
httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
response=httpclient.execute(httppost);
ResponseHandler<String> responseHandler = new BasicResponseHandler();
final String response = httpclient.execute(httppost, responseHandler);
System.out.println("Response :" + response);
runOnUiThread(new Runnable(){
public void run(){
dialog.dismiss();
}
});
 
if(response.equalsIgnoreCase("user Found")){
runOnUiThread(new Runnable(){
public void run(){
Toast.makeText(MainActivity.this,"login Success",Toast.LENGTH_SHORT).show();
}
});
//layout01.setBackgroundColor(Color.GREEN);
//startActivity(new Intent(MainActivity.this,TapView.class));
finish();
}else{
//layout01.setBackgroundColor(Color.RED);
Toast.makeText(MainActivity.this,"Login Fail",Toast.LENGTH_SHORT).show();
}
}catch(Exception e){
dialog.dismiss();
System.out.println("Exception:" + e.getMessage());
}
}
 
 
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }
 
    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();
        if (id == R.id.action_settings) {
            return true;
        }
        return super.onOptionsItemSelected(item);
    }
}
 
 
php
<?php
$hostname_localhost = "127.0.0.1:3306";
$database_localhost = "swumap";
$username_localhost = "root";
$password_localhost = "";
$localhost = mysql_connect($hostname_localhost,$username_localhost,$password_localhost) or trigger_error(mysql_error(),E_USER_ERROR);
 
mysql_select_db($database_localhost,$localhost);
 
$id=$_POST['id'];
$password=$_POST['password'];
$query_search="select * from login where id = '".$id."'AND password='".$password."'";
$query_exec = mysql_qury($query_search) or die(mysql_error());
$rows = mysql_num_rows($quert_exec);
 
if($row ==0){
echo "no such user found";
}
else{
echo "user found";
}
?>

 

익명사용자 님이 2015년 5월 11일 질문

1개의 답변

0 추천

System.out.println("Response :" + response); 여기서 뭐가찍히는지 보시구요.

그 값과 php에 echo 값과 동일한지 확인해보세요

콜벳 (7,150 포인트) 님이 2015년 5월 11일 답변
로딩되고 로그인실패 메시지까지는 뜨는데 문제는
데이터베이스에 있는 아이디랑 패스워드를 동일하게 입력했는데도
로그인실패라고 메시지가 뜨는데 서버랑 연결이 안된건가요?
...