获取电子邮件并在android textview上显示

时间:2012-12-31 04:44:00

标签: java android web-services textview fetch

我必须开发一个Android应用程序。

在这里,我必须获取beloning用户的电子邮件,并在android textview.how上显示该电子邮件,我可以开发这些。请给我任何想法。

这是我的网络服务代码:

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。如果我的登录不正确意味着显示登录失败消息。那么我的webservice代码是正确的。

如果我的登录成功,则意味着必须在android textview上显示电子邮件。否则必须显示登录失败的消息。

但在这里我遇到了一个问题:

如果我输入正确的登录详细信息意味着时间也显示登录失败的消息。但是如果我的登录成功意味着显示电子邮件,则需要o / p,否则登录失败消息。

我的代码出了什么问题。请为我提供解决方案。

这是我的android端代码:

    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"))

在输入正确的登录deatils后,在textview中收到电子邮件。

在这里,我如何从webservice获取电子邮件,并在textview上设置电子邮件。

我必须编写像

这样的代码
                   if(status.equals(email))

表示仅显示登录失败消息。但我的登录详细信息仅为正确。

请有人给我这些解决方案。

0 个答案:

没有答案