开发者

Accessing Android DCIM Images

How does one obtain images from the /DCIM/100ANDRO folder?

I have tried

 File rootsd = Environment.getExternalStorageDirectory();
        File dcim = new File(rootsd.getAbsolutePath() + "/DCIM/100ANDRO");
        File[] imagelist = dcim.listFiles(new FilenameFilter(){

        public boolean accept(File dir, String name)
        {
            return (开发者_如何学Python(name.endsWith(".jpg"))||(name.endsWith(".png")));
        }
    });
        mFiles = new String[imagelist.length];

        for(int i= 0 ; i< imagelist.length; i++)
        {
            mFiles[i] = imagelist[i].getAbsolutePath();
        }
        mUrls = new Uri[mFiles.length];

        for(int i=0; i < mFiles.length; i++)
        {
            mUrls[i] = Uri.parse(mFiles[i]);   
        }   

but I got a Null Pointer Exception.


Have you remembered to give the app permission to write the external memory? It is done in the AndroidManifest.xml file, by adding "android.permission.WRITE_EXTERNAL_STORAGE"

Since you are making a new file object, this is needed, I would guess.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜