Is it possible to create a separate folder for keeping images and sounds
Hi I need to keep my images and their sounds on a separate folder inside res folder structure.After that i need to read and display image from that fold开发者_StackOverflower to my application please reply
Yes , You can create a separate folder named raw within res folder (res/raw) and keep your drawable and sounds in that folder.
You can save your images to res/drawable and your sound files to res/raw.
If you really want to create a separate folder for your sound and image files, you can create it on your SD Card. Please see the example codes below:
File fileList= new File("/sdcard/MyFiles/");
//Store the file names within MyFiles folder to pathList[]
pathList = fileList.list();
//Create the URI path of your files here
StringBuilder sb = new StringBuilder();
sb.append("/sdcard/MyFiles/"+pathList[index1]);
pathList[index1]=sb.toString();
//Here is how you can play your sound files
MediaPlayer mp = new MediaPlayer();
mp.setDataSource(PATH_TO_FILE);
mp.prepare();
mp.start();
精彩评论