shihyingru
8/23/2018 - 2:53 AM

Json String

  • Create a Json String

Photo Handle

Intent調用相簿 onActivityReslut callback pic(JPEG) picture to Base64 string

判斷照片為橫向或者為直向,並進入ScalePic判斷圖片是否要進行縮放 包含判斷解析度和照片橫向直向縮放 (http://dean-android.blogspot.com/2013/05/android.html)

Okhttp 'Patch' Method

REST call with method "PATCH"

OkHttpClient client = new OkHttpClient();

MediaType mediaType = MediaType.parse("application/json");

String url = "http://devtest.bizcapps.com:8080/books";

String requestBody = "{\"language\" : \"java\"}";

RequestBody body = RequestBody.create(mediaType, requestBody);

Request request = new Request.Builder()
.url(url)
.patch(body)
.addHeader("content-type", "application/json")
.addHeader("cache-control", "no-cache")
.build();

Response response = client.newCall(request).execute();

return response.body().string();

Create a Json String

(https://stackoverflow.com/questions/8079116/android-create-a-json-string)

JSONObject jArrayFacebookData = new JSONObject(); JSONObject jObjectType = new JSONObject();

// put elements into the object as a key-value pair
jObjectType.put("type", "facebook_login");

jArrayFacebookData.put("system", jObjectType);

// 2nd array for user information
JSONObject jObjectData = new JSONObject();

// Create Json Object using Facebook Data
jObjectData.put("facebook_user_id", id);
jObjectData.put("first_name", first_name);
jObjectData.put("last_name", last_name);
jObjectData.put("email", email);
jObjectData.put("username", username);
jObjectData.put("birthday", birthday);
jObjectData.put("gender", gender);
jObjectData.put("location", place);
jObjectData.put("display_photo", display_photo_url);

jArrayFacebookData.put("data", jObjectData);

{ "system":{ "type":"facebook_login" }, "data":{ "birthday":"06/22/1986", "first_name":"Harsha", "username":"harshamv", "location":"Bangalore, India", "email":"hmv2206@gmail.com", "last_name":"Mv", "gender":"male", "facebook_user_id":"1423671254", "display_photo":"http://graph.facebook.com/1423671254/picture?type=large" } }