开发者社区> 问答> 正文

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 

展开
收起
蛮大人123 2016-06-16 15:41:43 2350 0
1 条回答
写回答
取消 提交回答
  • 我说我不帅他们就打我,还说我虚伪

    photo 的值是确定的,

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

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

    2019-07-17 19:41:05
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
58同城Android客户端Walle框架演进与实践之路 立即下载
Android组件化实现 立即下载
蚂蚁聚宝Android秒级编译——Freeline 立即下载