-1

I am a beginner to android and have designed a login GUI for an application where a user will enter the login details. After fetching login details in the Java code (in Strings),how can I pass it to server to check for a valid combination? Also when a new user enter registration details how can I pass it to server and store it in DB (MySQL DB)? What is the purpose of web service? Should I use web service or servlets (this is not the only thing, later in my app I need to send contact details to/from server)?

I have learnt SOAP webservices. Please guide me how to develope this application in android.

Swayam
  • 16,294
  • 14
  • 64
  • 102
Krishna Veni
  • 2,217
  • 8
  • 27
  • 53

2 Answers2

0

see my answer in this post Adding body of call to POST using HttpURLConnection

this will help you to connect to a webservice and pass data to that service

Community
  • 1
  • 1
sunil
  • 6,444
  • 1
  • 32
  • 44
-1

(By Using eclipse) Try this I have done a research and found this

public class AndroidtestingActivity extends ListActivity  {

    /** Called when the activity is first created. */
    @Override
public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);

    String result = null;
    InputStream is = null;
    StringBuilder sb = null;
    ArrayList<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
    List<String> r = new ArrayList<String>();

    try{

    //http post
    HttpClient httpclient = new DefaultHttpClient();
    HttpPost httppost = new HttpPost("YOUR SITE");
    httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
    HttpResponse response = httpclient.execute(httppost);
    HttpEntity entity = response.getEntity();
    is = entity.getContent();
    }
    catch(Exception e){
        Toast.makeText(getBaseContext(),e.toString() ,Toast.LENGTH_LONG).show();
   }

    //Convert response to string  
    try
    {
      BufferedReader reader = new BufferedReader(new InputStreamReader(is,"UTF-8"));

      sb = new StringBuilder();

      String line = null;

      while ((line = reader.readLine()) != null) 
      {
         sb.append(line + "\n");
      }

      is.close();

      result = sb.toString();
    }
    catch(Exception e)
    {
        Toast.makeText(getBaseContext(),e.toString() ,Toast.LENGTH_LONG).show();
    }
    //END Convert response to string   
    try{
            JSONArray jArray = new JSONArray(result);
            JSONObject json_data=null;
            for(int i=0;i<jArray.length();i++)
            {
               json_data = jArray.getJSONObject(i);                   
               r.add(json_data.getString("name")+json_data.getString("id"));
           }
           setListAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_expandable_list_item_1, r));
        }
        catch(JSONException e1){
            Toast.makeText(getBaseContext(),e1.toString() ,Toast.LENGTH_LONG).show();
        } catch (ParseException e1) {
            Toast.makeText(getBaseContext(),e1.toString() ,Toast.LENGTH_LONG).show();
    }

}

public boolean onCreateOptionsMenu(android.view.Menu menu) {
    // TODO Auto-generated method stub
    super.onCreateOptionsMenu(menu);
    MenuInflater blowUp = getMenuInflater();
    blowUp.inflate(R.menu.cool_menu, menu);
    return true;
}

public boolean onOptionsItemSelected(MenuItem item) {
    // TODO Auto-generated method stub
    switch(item.getItemId()){
    case R.id.iadd:
        Intent i = new Intent("android.intent.action.ADD");
        startActivity(i);

        break;  
    }
    return false;
}
}

Connecting Android to server must by using PHP Android - PHP - server/database

Sieryuu
  • 1,510
  • 2
  • 16
  • 41
  • why are you saying that connecting Android to server must use PHP. can you please justify your answer ? – sunil Jul 05 '12 at 07:27
  • U want to make a login form, so u must validate the username and password with server database, so I am using PHP to validate them – Sieryuu Jul 05 '12 at 07:30
  • yes ofcourse... you can use PHP services for validating the username/password combinations. but PHP is not the only way. there are other options also. another thing your answer is not directly related to the asked question – sunil Jul 05 '12 at 07:35
  • soap webservices also possible way only yar – Krishna Veni Jul 05 '12 at 09:14
  • already i done json and mysql,php using example in android login form is successfully.also done sqlite login form tutorial..so ly i asked how is connecting mysql using soap webservices in android(Calling java webservices project with mysql connection in android)now guide me and provide me some solutions and coding – Krishna Veni Jul 05 '12 at 09:17