首页 > 解决方案 > 使用soap webservice在android中的活动之间传递数据

问题描述

您好,我是使用 android 和 soap 进行应用程序开发的新手。我的问题是我想检索登录用户的会话 ID 并在另一个活动中使用它。它是在身份验证期间由 Web 服务在表中提供的响应。我发现创建一个常量类作为解决方案,但我不知道如何去做。有人可以帮忙吗?这是身份验证的代码。

 class AsyncCallWS extends AsyncTask<String, Void, String> {
     private ProgressDialog Dialog = new ProgressDialog(LoginActivity.this);

     @Override
     protected String doInBackground(String... url) {
      loginAction();
         return null;
     }
    @Override
    protected void onPreExecute() {
        Dialog.setMessage("chargement...");
        Dialog.show();
     }

    @Override
    protected void onPostExecute(String result) {
        Dialog.dismiss();

    }

     private void loginAction() {
    SoapObject request = new SoapObject(NAMESPACE, METHOD_NAME);

    login = loginEdit.getText().toString();
    password = passwordText.getText().toString();

    //Pass value for userName variable of the web service
    PropertyInfo unameProp =new PropertyInfo();
    unameProp.setName("login");//Define the variable name in the web service method
    unameProp.setValue(login);//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(password);
    passwordProp.setType(String.class);
    request.addProperty(passwordProp);

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

         try {
             SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
             envelope.setOutputSoapObject(request);
             HttpTransportSE androidHttpTransport = new HttpTransportSE(URL);
             androidHttpTransport.call(SOAP_ACTION, envelope);
             SoapObject result = (SoapObject) envelope.getResponse();
             System.out.println("call Donnnnnnnnnnnnnnnnnnnnnnnnnnne");
             String message0 = result.getProperty(0).toString();
             String message1 = result.getProperty(1).toString();
             //   String message2 = result.getProperty(2).toString();

             Log.e("result", "responceEEEEEEEEEEEEEEEEEEEEEEEE" + result);
             Log.e("result", "Message1 " + message1);
             Log.d("LOG_TAG", envelope.bodyIn.toString());
             switch (message0) {
                 case "0":
                     runOnUiThread(new Runnable() {
                         public void run() {
                             Intent i = new Intent(getApplicationContext(), NFCTagActivity.class);
                             startActivity(i);
                         }
                     });
                     break;
                 default:
                     runOnUiThread(new Runnable() {
                         public void run() {
                             Toast.makeText(LoginActivity.this, "identifiants incorrects ou Le user à deja une session en cours", Toast.LENGTH_LONG).show();
                         }
                     });
                     break;
             }
                 } catch (Exception e) {
             e.printStackTrace();
         }

}
}

标签: javaandroidsoap

解决方案


推荐阅读