public class Google_Gdata_Test extends Activity {
/** Called when the activity is first created. */
static String USER_ID;
static String USER_Pass;
static String APP_NAME;
TextView text;
static ArrayList<String> items;
static ArrayList<String> items2;
static ArrayList<String> items3;
JSONArray arr;
String ar;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
USER_ID = "
Áö¸ÞÀÏ °èÁ¤";
USER_Pass = "ºñ¹Ð¹øÈ£";
APP_NAME = "¾ÛÀ̸§";
items = new ArrayList<String>();
items2 = new ArrayList<String>();
items3 = new ArrayList<String>();
text = new TextView(this);
text = (TextView)findViewById(R.id.text);
authdata();
if(ar!=null)
{
getList();
}
if(arr.length()!=0)
{
for(int i=0; i<arr.length(); i++)
{
try {
text.append("\n"+arr.getString(i)+"\n");
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
else{}
}
public void getList()
{
try {
items3=new ArrayList<String>();
URL url = new URL("
http://www.google.com/calendar/feeds/"+USER_ID+"/private/full?alt=json");
HttpURLConnection con = (HttpURLConnection)url.openConnection();
con.setDoOutput(true);
con.setRequestMethod("GET");
con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
con.setRequestProperty("Authorization", "GoogleLogin auth="+ar);
InputStream un = con.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(un));
String ud;
arr = new JSONArray();
while((ud=br.readLine())!=null)
{
arr.put(ud);
}
br.close();
}
catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void authdata()
{
items = new ArrayList<String>();
URL url;
try {
url = new URL("
https://www.google.com/accounts/ClientLogin ");
HttpURLConnection con = (HttpURLConnection)url.openConnection();
con.setDoOutput(true);
con.setRequestMethod("POST");
OutputStreamWriter out = new OutputStreamWriter(con.getOutputStream());
out.write(
"&Email="+USER_ID
// +"&postId="+"1"
//+"&commentId="+"9155368"
+"&Passwd="+USER_Pass
+"&source="+APP_NAME
+"&service="+"cl");
out.flush();
InputStream put = con.getInputStream();
out.close();
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()));
String decodedString;
while((decodedString = in.readLine())!=null)
{
items.add(decodedString);
}
in.close();
ar = items.get(2).substring(5);
System.out.println(ar);
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public void AddEventSce(String Title, String Note, Date Startdate, Date EndDate, String Location)
{
Toast.makeText(getBaseContext(), "login..", Toast.LENGTH_SHORT).show();
try {
URL feedUrl = new URL("
https://www.google.com/calendar/feeds/default/private/full?alt=json");
CalendarEventEntry myEntry = new CalendarEventEntry();
myEntry.setTitle(new PlainTextConstruct("Test_App","utf-8"));
myEntry.setContent(new PlainTextConstruct("¾È³çÇϼ¼¿ä","utf-8"));
Person author = new Person("Test_app",null,USER_ID);
myEntry.getAuthors().add(author);
DateTime startTime = new DateTime(new Date(2011-1900,12-1,3,12,0));
startTime.setTzShift(9);
DateTime endTime = new DateTime(new Date(2011-1900,12-1,3,13,0));
endTime.setTzShift(9);
When eventTimes = new When();
eventTimes.setStartTime(startTime);
eventTimes.setEndTime(endTime);
myEntry.addTime(eventTimes);
Where evLocaiton = new Where();
evLocaiton.setValueString("¼¿ï");
myEntry.addLocation(evLocaiton);
CalendarService myService = new CalendarService("Test_App");
myService.setUserCredentials(USER_ID,USER_Pass);
ContentType ct = new ContentType();
// ct.setType("application/json;charset=utf-8");
// myService.setContentType(ct);
myService.insert(feedUrl, myEntry);
} catch (AuthenticationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (ServiceException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}