Skip to content
Permalink
Browse files
CB-11368 android: Resolve content URLs produced by contacts plugin
This bug was happening because of invalid assignment of null value to variable of primitive type

 This closes #192
  • Loading branch information
matrosov-nikita authored and vladimir-kotikov committed Aug 23, 2016
1 parent 47a428f commit 9860bbb8567a7ab8994996a3a66313510a05f64a
Showing 3 changed files with 59 additions and 5 deletions.
@@ -124,16 +124,19 @@ public JSONObject getFileMetadataForLocalURL(LocalFilesystemURL inputURL) throws
String mimeType = resourceApi.getMimeType(nativeUri);
Cursor cursor = openCursorForURL(nativeUri);
try {
if (cursor != null && cursor.moveToFirst()) {
size = resourceSizeForCursor(cursor);
if (cursor != null && cursor.moveToFirst()) {
Long sizeForCursor = resourceSizeForCursor(cursor);
if (sizeForCursor != null) {
size = sizeForCursor.longValue();
}
Long modified = lastModifiedDateForCursor(cursor);
if (modified != null)
lastModified = modified.longValue();
} else {
} else {
// Some content providers don't support cursors at all!
CordovaResourceApi.OpenForReadResult offr = resourceApi.openForRead(nativeUri);
size = offr.length;
}
size = offr.length;
}
} catch (IOException e) {
FileNotFoundException fnfe = new FileNotFoundException();
fnfe.initCause(e);
@@ -39,5 +39,6 @@
android:exported="false" />
</config-file>
<asset src="www/fixtures/asset-test" target="fixtures/asset-test" />
<dependency id="cordova-plugin-contacts" />
</platform>
</plugin>
@@ -3837,6 +3837,37 @@ exports.defineManualTests = function (contentEl, createActionButton) {
}, logError("requestFileSystem"));
}

function resolveFsContactImage() {
navigator.contacts.pickContact(function(contact) {
var logBox = document.getElementById("logContactBox");
logBox.innerHTML = "";
var resolveResult = document.createElement("p");
if (contact.photos) {
var photoURL = contact.photos[0].value;
resolveLocalFileSystemURL(photoURL, function(entry) {
var contactImage = document.createElement("img");
var contactLabelImage = document.createElement("p");
contactLabelImage.innerHTML = "Result contact image";
contactImage.setAttribute("src", entry.toURL());
resolveResult.innerHTML = "Success resolve\n" + entry.toURL();
logBox.appendChild(contactLabelImage);
logBox.appendChild(contactImage);
logBox.appendChild(resolveResult);
},
function(err) {
console.log("resolve error" + err);
});
}
else {
resolveResult.innerHTML = "Contact has no photos";
logBox.appendChild(resolveResult);
}
},
function(err) {
console.log("contact pick error" + err);
});
}

function clearLog() {
var log = document.getElementById("info");
log.innerHTML = "";
@@ -3914,4 +3945,23 @@ exports.defineManualTests = function (contentEl, createActionButton) {
'should be successfully resolved. Status box should say Successfully resolved. Both blue URLs below ' +
'that should match.'));
contentEl.appendChild(div);

div = document.createElement('h2');
div.appendChild(document.createTextNode('Resolving content urls'));
div.setAttribute("align", "center");
contentEl.appendChild(div);

div = document.createElement('div');
div.setAttribute("id", "contactButton");
div.setAttribute("align", "center");
contentEl.appendChild(div);

div = document.createElement('div');
div.setAttribute("id", "logContactBox");
div.setAttribute("align", "center");
contentEl.appendChild(div);

createActionButton('show-contact-image', function () {
resolveFsContactImage();
}, 'contactButton');
};

0 comments on commit 9860bbb

Please sign in to comment.