如何保存从com.android.contacts提取的图像,android?

如何保存从com.android.contacts提取的图像,android?,android,Android,我从联系人列表中提取照片URL并获得以下路径: content://com.android.contacts/contacts/1237/photo 在上传到javascript(我使用Cordova)之前,我想获取图像并将其保存为本地存储中的png文件 这就是我目前所做的: private void savefile(String name, String path){ File direct = new File(Environment.getExternalSto

我从联系人列表中提取照片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();
                      }
              }
  }
private void保存文件(字符串名称、字符串路径){
File direct=新文件(Environment.getExternalStorageDirectory()+“/myApp/images/”;
File File=新文件(Environment.getExternalStorageDirectory()++“/myApp/images/“+name+”.png”);
如果(!direct.exists()){
direct.mkdir();
}
如果(!file.exists()){
试一试{
createNewFile();
FileChannel src=newfileinputstream(path).getChannel();//
这个东西将为您提供存储在手机内存中的文件路径,并使用Cordova插件将其传递给Java方法

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);
  }