2011-04-14 73 views
0

我有一個登錄頁面,它工作正常,當我把正確的用戶名和密碼,但登錄失敗它不工作如何處理這個。 Android中我沒有任何想法,如果任何人能提供代碼,請登錄問題在android

這裏是我的代碼

package com.android; 

import java.io.IOException; 
import android.app.Activity; 
import android.app.AlertDialog; 

import android.content.Context; 

import android.content.Intent; 
import android.graphics.Typeface; 

import android.os.Bundle; 
import android.util.Log; 
import android.view.View; 
import org.json.JSONException; 
import org.json.JSONObject; 
import org.ksoap2.SoapEnvelope; 
import org.ksoap2.SoapFault; 
import org.ksoap2.serialization.SoapObject; 
import org.ksoap2.serialization.SoapPrimitive; 
import org.ksoap2.serialization.SoapSerializationEnvelope; 
import org.ksoap2.transport.AndroidHttpTransport; 
import org.xmlpull.v1.XmlPullParserException; 
import android.view.View.OnClickListener; 
import android.view.Window; 
import android.widget.*; 

public class Login extends Activity { 
    private static final String NAMESPACE = "http://tempuri.org/"; 

    private static final String URL ="http:.asmx?op=LoginRequest";  

    private static final String SOAP_ACTION = "http://tempuri.org/Login"; 
    //private String login=""; 

    private static final String METHOD_NAME = "Login"; 
    ImageButton login_button,sign_button; 
    TextView m,p,f,email,password,forgot_password; 
    EditText emailid,epassword; 
    AlertDialog authProgressDialog; 

    /** Called when the activity is first created. */ 
    @Override 

    public void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     requestWindowFeature(Window.FEATURE_NO_TITLE); 
     setContentView(R.layout.login); 
     email=(TextView)findViewById(R.id.email); 
     password=(TextView)findViewById(R.id.password); 
     forgot_password=(TextView)findViewById(R.id.forgot); 

     Context context = email.getContext(); 
     Typeface font=Typeface.createFromAsset(context.getAssets(),"arial.ttf");   
     email.setTypeface(font); 

     Context con = password.getContext(); 
     Typeface face=Typeface.createFromAsset(con.getAssets(),"arial.ttf"); 
     password.setTypeface(face); 

     Context con1 = forgot_password.getContext(); 
     Typeface face1=Typeface.createFromAsset(con1.getAssets(),"arial.ttf");   
     forgot_password.setTypeface(face1); 

//  new theTask().execute(); 

     login_button=(ImageButton)findViewById(R.id.login); 
     sign_button=(ImageButton)findViewById(R.id.signup); 

     login_button.setOnClickListener(new OnClickListener(){ 

      public void onClick(View v) { 

       String username,password; 
       emailid =(EditText)findViewById(R.id.edemail); 
       epassword =(EditText)findViewById(R.id.edpassword); 

       username = emailid.getText().toString(); 
       password = epassword.getText().toString(); 


       showDialog(0); 


       // TODO Auto-generated method stub 
       SoapObject request=new SoapObject(NAMESPACE,METHOD_NAME); 
       String qry="{\"General\":"+"{\"type\": \"Request\","+"\"application\": \"Mmmmm\","+"\"appver\": \"1.0.0\","+"\"phoneDeviceID\": \"123456789\","+"\"deviceType\": \"Android\","+"\"deviceOSVersion\": \"3.0\"},"+"\"Login\":"+"{\"emailID\":"+"\""+username+"\","+"\"password\":"+"\""+password+"\""+"}"+"}"; 
       Log.i("Input",qry); 

       request.addProperty("JSONRequestString",qry); 
       SoapSerializationEnvelope envelope=new SoapSerializationEnvelope(SoapEnvelope.VER11); 
       envelope.dotNet=true; 
       envelope.bodyOut=request; 
       envelope.encodingStyle=SoapSerializationEnvelope.ENC2001; 
       envelope.setOutputSoapObject(request); 
       AndroidHttpTransport androidHttpTransPort= new AndroidHttpTransport(URL); 

       try 
       { 
        try { 
         androidHttpTransPort.call(SOAP_ACTION,envelope); 
        } catch (IOException e) { 
         // TODO Auto-generated catch block 
         e.printStackTrace(); 
        } 
        SoapPrimitive rest=(SoapPrimitive)envelope.getResponse(); 
        Log.i("output","Result"+rest); 
        // SoapObject var = (SoapObject)rest.getProperty(0); 

        String conv=rest.toString(); 
        JSONObject js=new JSONObject(conv); 

        String login = js.getString("Login"); 
        JSONObject err=new JSONObject(login); 

        String messcode=js.getString("HomePageFooterNewUpdates"); 
        JSONObject code=new JSONObject(messcode); 

        int GetMessageCode=code.getInt("noOfMail"); 
        Log.i("message code ","is " +GetMessageCode); 
        //  String errc=err.getString("errorMsg"); 
        //  Log.i("err",errc); 
        int ResponseForLogin=err.getInt("errorCode"); 
          Log.i("Response ","is "+ResponseForLogin); 

        if(ResponseForLogin==000){ 
         Toast.makeText(Login.this, "Login Successfull", Toast.LENGTH_LONG).show(); 



         // prepare the dialog box 
       /*  ProgressDialog dialog = new ProgressDialog(this); 

         // make the progress bar Cancelable 
         dialog.setCancelable(true); 

         // set a message text 
         dialog.setMessage("Loading..."); 

         // show it 
         dialog.show();*/ 

         Intent i=new Intent(Login.this,Home.class); 
         i.putExtra("messcode", GetMessageCode); 
         startActivity(i); 

        } else { 
         Toast.makeText(Login.this, "Invalid Emailid or Password...Please Try Again", Toast.LENGTH_LONG).show(); 
        } 
       }catch (XmlPullParserException e) { 
        e.printStackTrace(); 
       } 

       catch (JSONException e) { 
        // TODO Auto-generated catch block 
        e.printStackTrace(); 
       } catch (SoapFault e) { 
        // TODO Auto-generated catch block 
        e.printStackTrace(); 
       } 
      } 



     } ); 

     sign_button.setOnClickListener(new OnClickListener(){ 
      public void onClick(View v) { 
       Intent i=new Intent(Login.this, Signup.class); 
       startActivity(i); 
      } 
     }); 


    } 


} 

在此先感謝...

+0

你在說你的應用程序的登錄活動嗎?如果是的話,你可以做一個吐司,通知用戶有關錯誤的登錄名/密碼 – Maxim 2011-04-14 05:28:10

+0

在你下面沒有最大可以檢查要求什麼 – user701735 2011-04-14 07:02:16

+0

@ user701735我們需要看你用來處理登錄的代碼。請修改您的問題以包含此代碼。 – 2011-04-14 08:05:47

回答

0

只是給你一些提示,試着從中獲得幫助。

ImageButton login=(ImageButton)findViewById(R.id.Login); 
EditText editText1=(EditText)findViewById(R.id.emailText); 
EditText editText2=(EditText)findViewById(R.id.passwordText); 

login.setOnClickListener(new OnClickListener() { 

      @Override 
      public void onClick(View v) { 
       // TODO Auto-generated method stub 


       if((editText1.getText()+" ").trim().equals("") || editText1.getText() == null || (editText2.getText()+" ").trim().equals("") || editText2.getText() == null){ 

        //show error message here 

       } 
       else{ 

        //perrform your action here 
        //either start a new activity or do something else 

       } 

      } 
     }); 

希望這會幫助你。

+0

dinesh thats不是我的問題我的問題是當我clik登錄按鈕時用戶名和密碼在後臺從Web服務器得到驗證,並在成功後引發登錄響應我搬到我的主頁。但是當我更改代碼,並把登錄錯誤001登錄失敗登錄比它不工作我必須使用jsontoken如果是的請與我聯繫,該程序 – user701735 2011-04-14 07:01:50

0

我發現下面的教程已經肯定幫助我實現了正確的登錄和使用這些資源註冊屏幕:

材料設計 共享偏好 PHP腳本 MySQL數據庫 SQLlite數據庫

這是教程中的link。 我知道這是非常晚,但我希望它可以幫助你。