hey guys plz help me out with tis ... i want to authenticate the user
through my application(using eclipse and android sdk) using
clientlogin. The code is as follows but it is giving me io
exception... plz help me out...
import android.app.Activity;



import java.io.BufferedReader;

import java.io.BufferedWriter;

import java.io.FileNotFoundException;

import java.io.FileWriter;

import java.io.BufferedInputStream;
import java.io.OutputStreamWriter;
import java.io.OutputStream;

import java.io.UnsupportedEncodingException;


import java.io.IOException;


import java.io.InputStream;


import java.io.InputStreamReader;


import java.net.HttpURLConnection;
import java.net.URI;

import java.net.MalformedURLException;

import java.net.URLConnection;

import java.net.URLEncoder;


import java.net.URL;


//import org.omg.CORBA.portable.OutputStream;

//import android.app.Activity;
import android.os.Bundle;


import android.view.View;


import android.widget.Button;
import android.widget.TextView;


import android.widget.EditText;

public class hiii extends Activity {



      /** Called when the activity is first created. */
    static EditText addr;
    static EditText pass;
    private Button btsin;
    private String tokenValue;
    private TextView tv ;
    private TextView tv1;

   @Override


    public void onCreate(Bundle savedInstanceState) {

    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    this.addr=(EditText) findViewById(R.id.editName);
    this.pass=(EditText) findViewById(R.id.editPasswd);
    this.btsin=(Button) findViewById(R.id.buttonSignIn);
    this.tv=(TextView) findViewById(R.id.text1);
    this.tv1=(TextView)findViewById(R.id.text2);


    this.btsin.setOnClickListener(new View.OnClickListener() {

        final String account = addr.toString();

         final  String password = pass.toString();




     public void onClick(View v)  {
                                                                        try {


                                                                                
authenticate(account,password);
                                                                                
        } catch (UnsupportedEncodingException e) {

                                                                                
                //addr.setText("1");
                                                                                
                e.printStackTrace();
                                                                                
        } catch (MalformedURLException e) {

                                                                                
                //addr.setText("2");
                                                                                
                e.printStackTrace();
                                                                                
        } catch (IOException e) {

                                                                                
                tv.setText("IOException occured");
                                                                                
                e.printStackTrace();
                                                                                
        }
                                  }
    });

   }
     public  void authenticate(String user,String pass)throws
IOException
     {
         String serviceURL="https://www.google.com/accounts/ClientLogin";;
         HttpURLConnection con = null;
         try {
                 String enc = "UTF-8";
                 URL googleUrl = new URL(serviceURL);
                 String authentication =
"accountType=HOSTED_OR_GOOGLE&Email="
                                 + URLEncoder.encode(user, enc) +
"&Passwd=" + URLEncoder.encode(pass, enc)
                                 + "&source=test&service=cl";
                addr.setText("requesting " + googleUrl);
                 con = (HttpURLConnection)
googleUrl.openConnection();
                 con.setRequestMethod("POST");
                 con.setRequestProperty("Content-Type", "application/x-
www-form-urlencoded");
 
con.setFixedLengthStreamingMode(authentication.length());
                // addr.setText("reached it");

                 con.setDoOutput(true);
                 con.setDoInput(true);
                 con.connect();
                BufferedWriter writer = new BufferedWriter(new
OutputStreamWriter(con.getOutputStream()));
                 writer.write(authentication);
                 writer.flush();
                 writer.close();
                 //addr.setText("hello reached here");

                 tv.setText(con.getResponseCode() + ": " +
con.getResponseMessage());
                tv1.setText("Headers:\n" + con.getHeaderFields());

         }
         catch (IOException exc) {
                 throw exc;
         }
         finally {
                 con.disconnect();
         }
     }

}
thanking you in adv...

-- 
You received this message because you are subscribed to the Google Groups 
"Google Health Developers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/googlehealthdevelopers?hl=en.

Reply via email to