How do i create folders in sdcard containing images while installing application on device?
I am using gridview example with image adapter to render images with difference that these images are retrieved from a particular folder in sdcard for e.g. /sdcard/images. I am testing this application开发者_如何学Python on emulator.For this i have firstly configured sdcard on emulator and then pushed the images on this particular folder through DDMS under eclipse.
What i want to know is that is it possible to create images folder containing images in sdcard when a user installs the application on the real device and if possible what is the way to do it?
I'm not aware of a way to do it (which is not to say that it cant be done). One thing that you definitely can do is create the folder when the user first runs the application, and fill it with the images.
You should read the Android Documentation covering the External Storage section.
I think it is possible . you can put all images in a asset folder and when you application will start you can copy it to a particular folder in SD Card. Here is the link for copy the database form asset folder to application . You can try it for copy the images form asset folder to SDCard. http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/
You can copy images from assets to SDcard
This method copies images from assets folder to your Sdcard .here Jaydeep's Folder is the name of my folder on sdcard.You can use your folder name in that place.
public void copyImagesInSdcard()
{
assetManager = mycontext.getAssets();
assetManager1 = mycontext.getAssets();
System.out.println("In copyImagesInSdcard");
try
{
str1=assetManager.list("");
ss=assetManager1.list(str1[1]);
InputStream is;
//System.out.println(ss[0]);
File file=new File(Environment.getExternalStorageDirectory().getPath() + "/Jaydeep's Folder");
if(file.exists()!=true)
{
file.mkdir();
}
else
{
if(file.length()==0)
{
file.mkdir();
}
System.out.println("Length:"+file.length());
}
for(int i=0;i<ss.length;i++)
{
is=assetManager1.open(str1[1] + "/" + ss[i]);
file=new File(Environment.getExternalStorageDirectory().getPath() + "/Jaydeep's Folder/" + ss[i] );
FileOutputStream out=new FileOutputStream(file);
//Bitmap bi = BitmapDrawable.createFromStream(is,ss[0]);
byte b[] =new byte[4096];
while (is.read(b) != -1) {
out.write(b);
}
out.close();
}
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}
This can be done by creating zip of all resources and put them in assets folder and then unzip these folder into sdcard using following reference: http://www.jondev.net/articles/Unzipping_Files_with_Android_%28Programmatically%29
精彩评论