[英]How to save image extracted from com.android.contacts, Android?
I extracted photo URL from contacts list and got following path: 我从联系人列表中提取了照片URL并获得了以下路径:
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. 在上传到javascript之前(我使用Cordova)我想获取图像并将其保存为本地存储中的
png
文件。
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 但我得到的文件没有找到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.
这件事将为您提供存储在手机内存中的文件路径,并使用Cordova插件将其传递给Java方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.