简体   繁体   English

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

[英]How to save image extracted from com.android.contacts, Android?

I extracted photo URL from contacts list and got following path: 我从联系人列表中提取了照片URL并获得了以下路径:

content://com.android.contacts/contacts/1237/photo

Before to upload to javascript (I use Cordova) I want to get image and save it as png file in local storage. 在上传到javascript之前(我使用Cordova)我想获取图像并将其保存为本地存储中的png文件。

This is what I did so far: 这是我到目前为止所做的:

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

But I get file not found Exception 但我得到的文件没有找到Exception

Any ideas? 有任何想法吗?

Thanks, 谢谢,

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

This thing will give you the path of file which is stored in your phone memory and pass this to your Java method using Cordova Plugin. 这件事将为您提供存储在手机内存中的文件路径,并使用Cordova插件将其传递给Java方法。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何打开com.android.contacts / .CallDetalActivity - how to open com.android.contacts/.CallDetalActivity android 中 content://com.android.contacts 的用途是什么 - What is use of content://com.android.contacts in android android联系人源代码com.android.contacts - android contact source code com.android.contacts 执行applyBatch时未找到权限com.android.contacts异常 - Authority com.android.contacts not found exception when doing applyBatch ShowCallLog Intent 在由“com.android.contacts”处理时不起作用 - ShowCallLog Intent not working when handled by "com.android.contacts" java.io.FileNotFoundException:content://com.android.contacts/contacts/24093/photo仅适用于旧照片 - java.io.FileNotFoundException: content://com.android.contacts/contacts/24093/photo for old photos only 使用什么代替Contacts.Intents.UI.LIST_STARRED_ACTION在com.android.contacts中显示已加星标的联系人? - What to use instead of Contacts.Intents.UI.LIST_STARRED_ACTION to display starred contacts in com.android.contacts? Adobe air内容:\\\\ com.android.contacts \\ display_photo \\加载照片 - Adobe air content:\\com.android.contacts\display_photo\ load a photo 未能为用户 0 找到提供者 com.android.contacts,预计会为此权限找到有效的内容提供者 - failed to find provider com.android.contacts for user 0, expected to find a valid contentprovider for this authority 无法传递结果ResultInfo {who = null,request = 1,result = -1,data = Intent {dat = content://com.android.contacts/contacts/lookup…}} - Failure delivering result ResultInfo{who=null, request=1, result=-1, data=Intent { dat=content://com.android.contacts/contacts/lookup…}}
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM