(http://www.devexchanges.info/2016/01/gridview-with-multiple-selection-in.html)
Intent調用相簿 onActivityReslut callback pic(JPEG) picture to Base64 string
先調用相簿,選取照片後會再叫出裁剪頁面 (http://xxs4129.pixnet.net/blog/post/217841922-android-%E8%AA%BF%E7%94%A8%E7%9B%B8%E7%B0%BF%E5%8F%96%E5%BE%97%E7%85%A7%E7%89%87%E4%B8%A6%E5%81%9A%E8%A3%81%E5%89%AA)
開啟相機-照相功能與相簿-相片集並讀取相片匯入至程式
判斷照片為橫向或者為直向,並進入ScalePic判斷圖片是否要進行縮放 包含判斷解析度和照片橫向直向縮放 (http://dean-android.blogspot.com/2013/05/android.html)
picture to Base64 string (https://stackoverflow.com/questions/4830711/how-to-convert-a-image-into-base64-string)
Bitmap bm = BitmapFactory.decodeFile("/path/to/image.jpg");
ByteArrayOutputStream baos = new ByteArrayOutputStream();
bm.compress(Bitmap.CompressFormat.JPEG, 100, baos); //bm is the bitmap object
byte[] b = baos.toByteArray();
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();
(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" } }