如何保存从com.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.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();
                      }
              }
  }

但是我得到file not found 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 Plugin将其传递给你的Java方法。

最新更新