markdowneide 2013-06-08 01:42 采纳率: 0%
浏览 2496
已采纳

uri字符串不能在android中缓存

我使用的下面的代码

String fileName = "image" + "_" + title.getText().toString()+"_" + val.toString(); 
                    photo = this.createFile(fileName, ".jpg");
                    intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));
                    uriOfPhoto = Uri.fromFile(photo);
                    startActivityForResult(intent, RESULT_CAMERA_SELECT);
                }
            }
            catch(Exception e)
            {
                Log.v("Error", "Can't create file to take picture!");
                displayAlert("Can't create file to take picture!","SDCard Error!");
            }
        }

        private File createFile(String part, String ext) throws Exception
        {
            File tempDir = new File (Environment.getExternalStorageDirectory() + "/MyFolder/Images");
            if(!tempDir.exists())
            {
                tempDir.mkdir();
            }
            tempDir.canWrite();
            return new File(tempDir, part+ext);
        }
    });

UriOfPhoto 给出提示uriString not chached in debug。它不是存储文件中的uri。如何解决这个问题呢?

authority   Uri$Part$EmptyPart  (id=830004244032)   
fragment    Uri$Part$EmptyPart  (id=830004245408)   
host    "NOT CACHED" (id=830003914304)  
path    Uri$PathPart  (id=830067926736) 
port    -2  
query   Uri$Part$EmptyPart  (id=830004245408)   
scheme  "file" (id=830002660688)    
ssp null    
uriString   "NOT CACHED" (id=830003914304)  
userInfo    null 
  • 写回答

2条回答 默认 最新

  • luhuajcdd 2013-06-08 02:12
    关注

    photo 的值是确定的,

    photo = this.createFile(fileName, ".jpg");
    intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(photo));
    uriOfPhoto = Uri.fromFile(photo);
    

    为什么还在这里实例化uriOfPhoto, 有点多余。 在用到的时候在实例化

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作