I extracted photo URL from contacts list and got following path:
content://com.android.contacts/contacts/1237/photo
Before to upload to javascript (I use Cordova) I want to get image and save it as png
file in local storage.
This is what I did so far:
private void savefile(String name, String path){
File direct = new File(Environment.getExternalStorageDirectory() + "/myApp/images/");
File file = new File(Environment.getExternalStorageDirectory() + "/myApp/images/"+name+".png");
if(!direct.exists()){
direct.mkdir();
}
if (!file.exists()) {
try {
file.createNewFile();
FileChannel src = new FileInputStream(path).getChannel(); // <- here I get Exception
FileChannel dst = new FileOutputStream(file).getChannel();
dst.transferFrom(src, 0, src.size());
src.close();
dst.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
But I get file not found Exception
Any ideas?
Thanks,
window.resolveLocalFileSystemURI(imageURI, gotFileEntryMessage, fsFailMessage);
function gotFileEntryMessage(fileEntry) {
var Path = fileEntry.fullPath;
alert(Path);
}
function fsFailMessage(error) {
console.log("failed with error code: " + error.code);
}
This thing will give you the path of file which is stored in your phone memory and pass this to your Java method using Cordova Plugin.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.