簡體   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