![](/img/trans.png)
[英]how to open com.android.contacts/.CallDetalActivity
[英]How to save image extracted from com.android.contacts, Android?
我從聯系人列表中提取了照片URL並獲得了以下路徑:
content://com.android.contacts/contacts/1237/photo
在上傳到javascript之前(我使用Cordova)我想獲取圖像並將其保存為本地存儲中的png
文件。
這是我到目前為止所做的:
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();
}
}
}
但我得到的文件沒有找到Exception
有任何想法嗎?
謝謝,
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);
}
這件事將為您提供存儲在手機內存中的文件路徑,並使用Cordova插件將其傳遞給Java方法。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.