0

1 つの Android アプリケーションを開発する必要があります。

ここでは、所属するユーザーの電子メールを取得し、その電子メールを Android textview に表示する必要があります。これらを開発するにはどうすればよいですか。アイデアを教えてください。

これは私のWebサービスコードです:

public class Login {
  public String authentication(String username,String password){

       String retrievedUserName = "";
       String retrievedPassword = "";
       String retrievedEmail = "";
       String status = "";
       try{
        Class.forName("com.mysql.jdbc.Driver");
        Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/xcart-432pro","root","");
       PreparedStatement statement =  con.prepareStatement("SELECT * FROM xcart_customers WHERE login = '"+username+"'");
         ResultSet result = statement.executeQuery();
         while(result.next()){  
          retrievedUserName = result.getString("login");
          retrievedPassword = result.getString("password");
          retrievedEmail = result.getString("email");   
           }
         if(retrievedUserName.equals(username)&&retrievedPassword.equals(password)&&!(retrievedUserName.equals("") && retrievedPassword.equals(""))){
         status = retrievedEmail;
           }

       else {
        status = "Login fail!!!";
          }

            }

          catch(Exception e){
          e.printStackTrace();
            }
         return status;

             }

              }

ここでこれらの Web サービス コードを実行する必要があるのは、ログインが成功した場合、電子メール ID が正常に表示されたことを意味します。

ログインが成功した場合は、android textview に電子メールを表示する必要があることを意味します。それ以外の場合は、ログイン失敗メッセージを表示する必要があります。

しかし、ここで私は1つの問題に直面しました:

正しいログイン詳細を入力した場合、その時間もログイン失敗メッセージが表示されたことを意味します.しかし、ログイン成功が電子メールを表示することを意味する場合、そうでない場合はログイン失敗メッセージを表示する場合のように、o / pが必要です。

私のコードで何が問題なのですか。これらの解決策を教えてください。

これは私のアンドロイド側のコードです:

    public class CustomerLogin extends Activity {
    private static final String SPF_NAME = "vidslogin";
    private static final String USERNAME = "login";
    private static final String PASSWORD = "password";
   private static final String PREFS_NAME = null;


         private String login;
       String mGrandTotal,total,mTitle,mTotal,mQty,mCost;

      EditText username,userPassword;
      private final String NAMESPACE = "http://xcart.com";
      private final String URL = "http://10.0.0.75:8085/XcartLogin/services/Login?wsdl";
      private final String SOAP_ACTION = "http://xcart.com/authentication";
      private final String METHOD_NAME = "authentication";
      private String uName;

         /**Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.customer_login);
        username = (EditText) findViewById(R.id.tf_userName);
        userPassword = (EditText) findViewById(R.id.tf_password);

         Button login = (Button) findViewById(R.id.btn_login);
         login.setOnClickListener(new View.OnClickListener() {

         public void onClick(View arg0) {
          loginAction();

          }
         });
          }
          private void loginAction(){


             SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
            EditText username = (EditText) findViewById(R.id.tf_userName);
                 String user_Name = username.getText().toString();
              EditText userPassword = (EditText) findViewById(R.id.tf_password);
               String user_Password = userPassword.getText().toString();

                 //Pass value for userName variable of the web service
               PropertyInfo unameProp =new PropertyInfo();
               unameProp.setName("username");//Define the variable name in the web service method
               unameProp.setValue(user_Name);//set value for userName variable
        unameProp.setType(String.class);//Define the type of the variable
        request.addProperty(unameProp);//Pass properties to the variable

      //Pass value for Password variable of the web service
        PropertyInfo passwordProp =new PropertyInfo();
        passwordProp.setName("password");
        passwordProp.setValue(user_Password);
        passwordProp.setType(String.class);
        request.addProperty(passwordProp);

        SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
        envelope.setOutputSoapObject(request);
        HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);

        try{
            androidHttpTransport.call(SOAP_ACTION, envelope);
               SoapPrimitive response = (SoapPrimitive)envelope.getResponse();
               String status = response.toString();
               TextView email = (TextView) findViewById(R.id.tv_status);
               email.setText(response.toString());

               if(status.equals(email))
               {


if(isUserValidated && isPasswordValidated)
{

    Intent intent = new Intent(CustomerLogin.this,PayPalIntegrationActivity.class);


  startActivity(intent);

      }
       }

                       else
                          {

                           LayoutInflater inflater = getLayoutInflater();
                           View layout = inflater.inflate(R.layout.toast_custom_layout,
                                (ViewGroup) findViewById(R.id.toast_layout_root));
                          Toast toast = new Toast(getApplicationContext());
                          toast.setGravity(Gravity.TOP, 0, 30);
                          toast.setDuration(Toast.LENGTH_LONG);
                          toast.setView(layout);
                          toast.show();

                          }
                         }
              catch(Exception e){

                  }
                 }

          }

編集:

ここで私は手段のようなコードを書きました

               if(status.equals("krishnaveniveeman@gmail.com"))

正しいログイン情報を入力した後、テキストビューで電子メールを取得しています。

ここで、Webサービスからメールを取得し、テキストビューでメールを設定するにはどうすればよいですか.

次のようなコードを書く必要があります

                   if(status.equals(email))

は、ログイン失敗メッセージのみが表示されることを意味します。ただし、ログインの詳細は正しいだけです。

誰か私にこれらの解決策を教えてください。

4

0 に答える 0