AndroidからWebサービスを使う

  • 4,902 views
Uploaded on

 

More in: Technology , Education
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
4,902
On Slideshare
0
From Embeds
0
Number of Embeds
1

Actions

Shares
Downloads
28
Comments
0
Likes
3

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Now Loading. Please Wait ... Re:Kayo-System Co.,Ltd.2012 2 15
  • 2. Re:Kayo-System Co.,Ltd.2012 2 15
  • 3. Re:Kayo-System Co.,Ltd.2012 2 15
  • 4. Re:Kayo-System Co.,Ltd.2012 2 15
  • 5. Re:Kayo-System Co.,Ltd.2012 2 15
  • 6. Re:Kayo-System Co.,Ltd.2012 2 15
  • 7. Re:Kayo-System Co.,Ltd.2012 2 15
  • 8. Re:Kayo-System Co.,Ltd.2012 2 15
  • 9. Re:Kayo-System Co.,Ltd.2012 2 15
  • 10. Re:Kayo-System Co.,Ltd.2012 2 15
  • 11. Re:Kayo-System Co.,Ltd.2012 2 15
  • 12. Re:Kayo-System Co.,Ltd.2012 2 15
  • 13. Re:Kayo-System Co.,Ltd.2012 2 15
  • 14. Re:Kayo-System Co.,Ltd.2012 2 15
  • 15. Re:Kayo-System Co.,Ltd.2012 2 15
  • 16. Re:Kayo-System Co.,Ltd.2012 2 15
  • 17. Re:Kayo-System Co.,Ltd.2012 2 15
  • 18. Re:Kayo-System Co.,Ltd.2012 2 15
  • 19. Re:Kayo-System Co.,Ltd.2012 2 15
  • 20. Re:Kayo-System Co.,Ltd.2012 2 15
  • 21. • Ecrair/Froyo Apache HTTP Client • Gingerbread HttpURLConnection API Android • HttpURLConnection Re:Kayo-System Co.,Ltd.2012 2 15
  • 22. Re:Kayo-System Co.,Ltd.2012 2 15
  • 23. Re:Kayo-System Co.,Ltd.2012 2 15
  • 24. Re:Kayo-System Co.,Ltd.2012 2 15
  • 25. Re:Kayo-System Co.,Ltd.2012 2 15
  • 26. oogle Maps API Re:Kayo-System Co.,Ltd.2012 2 15
  • 27. Re:Kayo-System Co.,Ltd.2012 2 15
  • 28. Re:Kayo-System Co.,Ltd.2012 2 15
  • 29. Re:Kayo-System Co.,Ltd.2012 2 15
  • 30. Re:Kayo-System Co.,Ltd.2012 2 15
  • 31. Re:Kayo-System Co.,Ltd.2012 2 15
  • 32. Re:Kayo-System Co.,Ltd.2012 2 15
  • 33. Re:Kayo-System Co.,Ltd.2012 2 15
  • 34. Re:Kayo-System Co.,Ltd.2012 2 15
  • 35. package jp.co.kayo.android.localplayer.ds.ampache.test; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.URI; import java.net.URISyntaxException; import java.net.URLEncoder; import android.test.AndroidTestCase; import android.util.Log; public class MapAPITest extends AndroidTestCase { final String TAG = "MapAPI Test"; public void testCallService() { try { URI uri = new URI("http://maps.google.com/maps/api/geocode/json?address=".concat( URLEncoder.encode(" ")).concat("&sensor=false")); HttpURLConnection con = (HttpURLConnection) uri.toURL().openConnection(); InputStream is = con.getInputStream(); BufferedReader reader = new BufferedReader(new InputStreamReader(is)); String line; while ((line = reader.readLine()) != null) { Log.d("", line); } is.close(); reader.close(); } catch (URISyntaxException e) { Log.d(TAG, "URI Syntax error", e); } catch (MalformedURLException e) { Log.d(TAG, "URL Malformed Error", e); } catch (IOException e) { Log.d(TAG, "IO error", e); } } } Re:Kayo-System Co.,Ltd.2012 2 15
  • 36. Re:Kayo-System Co.,Ltd.2012 2 15
  • 37. try { URI uri = new URI("http://maps.google.com/maps/api/geocode/json?address=".concat( URLEncoder.encode(" ")).concat("&sensor=false")); HttpURLConnection con = (HttpURLConnection) uri.toURL().openConnection(); InputStream is = con.getInputStream(); BufferedReader reader = new BufferedReader(new InputStreamReader(is)); StringBuilder json = new StringBuilder(); String line; while ((line = reader.readLine()) != null) { Log.d("", line); json.append(line); } is.close(); reader.close(); } catch (URISyntaxException e) { Log.d(TAG, "URI Syntax error", e); } catch (MalformedURLException e) { Log.d(TAG, "URL Malformed Error", e); } catch (IOException e) { Log.d(TAG, "IO error", e); } Re:Kayo-System Co.,Ltd.2012 2 15
  • 38. StringBuilder json = new StringBuilder(); String line; while ((line = reader.readLine()) != null) { Log.d("", line); json.append(line); } { "results" : [ { "address_components" : [ { "long_name" : " ", "short_name" : " ", "types" : [ "locality", "political" ] }, { "long_name" : " ", "short_name" : " ", "types" : [ "administrative_area_level_1", "political" ] }, Re:Kayo-System Co.,Ltd.2012 2 15
  • 39. { "long_name" : " ", "short_name" : " ", "types" : [ "locality", "political" ] } "formatted_address" : " , ", "geometry" : { "bounds" : { "northeast" : { "lat" : 31.63195899999999, "lng" : 130.82772330 }, "southwest" : { "lat" : 31.41453820, "lng" : 130.68629260 } }, "location" : { "lat" : 31.49273440, "lng" : 130.70091430 }, Re:Kayo-System Co.,Ltd.2012 2 15
  • 40. private void printAddress(String str){ try { JSONObject json = new JSONObject(str); JSONArray results = json.getJSONArray("results"); int count = results.length(); for(int i=0; i<count; i++){ JSONObject item = results.getJSONObject(i); String formatted_address = item.getString("formatted_address"); JSONObject geom = item.getJSONObject("geometry"); JSONObject location = geom.getJSONObject("location"); String lat = location.getString("lat"); String lng = location.getString("lng"); Log.d(TAG, "formatted_address"+ formatted_address); Log.d(TAG, "(lat, lng)="+lat+","+lng); } } catch (JSONException e) { Log.d(TAG, "Json Error", e); } } Re:Kayo-System Co.,Ltd.2012 2 15
  • 41. Re:Kayo-System Co.,Ltd.2012 2 15