繁体   English   中英

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

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM