android doesn't support data to save photo for contact by image data base64 encoded
Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/repo Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/commit/367f04b6 Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/tree/367f04b6 Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/diff/367f04b6 Branch: refs/heads/master Commit: 367f04b6d369c6fcd4372218e4d685ab002e4b74 Parents: bb89256 Author: Benjamin <[email protected]> Authored: Sat Oct 29 20:59:19 2016 -0400 Committer: filmaj <[email protected]> Committed: Tue Apr 25 17:08:58 2017 -0700 ---------------------------------------------------------------------- src/android/ContactAccessorSdk5.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cordova-plugin-contacts/blob/367f04b6/src/android/ContactAccessorSdk5.java ---------------------------------------------------------------------- diff --git a/src/android/ContactAccessorSdk5.java b/src/android/ContactAccessorSdk5.java index 89a7ad0..5ae5368 100644 --- a/src/android/ContactAccessorSdk5.java +++ b/src/android/ContactAccessorSdk5.java @@ -1709,6 +1709,21 @@ public class ContactAccessorSdk5 extends ContactAccessor { * @throws IOException */ private InputStream getPathFromUri(String path) throws IOException { + if (path.startsWith("data:")) { // data:image/png;base64,[ENCODED_IMAGE] + String dataInfos = path.substring(0, path.indexOf(',')); + dataInfos = dataInfos.substring(dataInfos.indexOf(':') + 1); + String baseEncoding = dataInfos.substring(dataInfos.indexOf(';') + 1); + // [ENCODED_IMAGE] + if("base64".equalsIgnoreCase(baseEncoding)) { + String img = path.substring(path.indexOf(',') + 1); + byte[] encodedData = img.getBytes(); + ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(encodedData, 0, encodedData.length); + Base64InputStream base64InputStream = new Base64InputStream(byteArrayInputStream, Base64.DEFAULT); + return base64InputStream; + } else { + Log.w(LOG_TAG, "Could not decode image. The found base encoding is " + baseEncoding); + } + } if (path.startsWith("content:")) { Uri uri = Uri.parse(path); return mApp.getActivity().getContentResolver().openInputStream(uri); --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
