Search code examples
javaandroidmysqlweb-servicesandroid-ksoap2

login form with mysql calling soap webservice in android 4.0


I have to develop an one android application.

Here i have using following code.

  public class MainActivity extends Activity {
  String status;
  EditText username,userPassword;
    SoapSerializationEnvelope envelope;
    private final String NAMESPACE = "http://pricealert.com";
    private final String URL = "http://192.168.2.102:8085/PriceAlert/services/Login?wsdl";
    private final String SOAP_ACTION = "http://pricealert.com/authentication";
    private final String METHOD_NAME = "authentication";
    private String uName;
    HttpTransportSE androidHttpTransport;
     /**Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

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

      new LoginOperation().execute();

      }
     });
       }
      class LoginOperation extends AsyncTask<String, Void, String> {
      private ProgressDialog Dialog = new ProgressDialog(MainActivity.this);

      @Override
  protected String doInBackground(String... aurl) {
 // TODO Auto-generated method stub
    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);
 username = (EditText) findViewById(R.id.tf_userName);
 String user_Name = username.getText().toString();
 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 it means 
 //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);

  envelope = new SoapSerializationEnvelope(
         SoapEnvelope.VER12);
 envelope.setOutputSoapObject(request);
 androidHttpTransport = new HttpTransportSE(URL);
 runOnUiThread(new Runnable() {
     @Override
     public void run() {
 try{

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

                  }
       catch(Exception e){
         }
     }
     });
     return null;
      }

     protected void onPreExecute() {
    Dialog.setMessage("Loading...");
    Dialog.show();
    }

    protected void onPostExecute(String resultGot) {
    Dialog.dismiss();
       }
       }
             }

If i have to add the application on android 2.2 means its working perfectly and returns success and failure values.

But the same code is running on android 4.0 version means didn't get the any(sucess or failure )toast message and also didn't getting any error on my logcate window ??? What's wrong in my code ??? please provide me some solution to resolve these issues ???


Solution

  • You are calling the webservice on the UI thread. That's a strict mode violation. You should never do an DB or network operations on the UI thread. Newer versions of Android are much more strict about this that's why it is working on other versions. The code in doInBackground() by default runs on a separate thread so you don't need to run anything on the UI thread.

    To update the UI after the call, use a Handler