15 Jun 2012

How to Get Image using Name from Raw or drawable folder in Android.


ImageView mIv = (ImageView) findViewById(R.id.xidIma);

 // create context Object for  to Fetch  image from resourse
   Context mContext=getApplicationContext();

 // getResources().getIdentifier("image_name","res_folder_name", package_name);

 // find out below example
inti=mContext.getResources().getIdentifier("ic_launcher","raw",mContext.getPackageName());

 // now we will get contsant id for that image 
 mIv.setBackgroundResource(i);


I will be happy if you will provide your feedback or follow this blog. Any suggestion and help will be appreciated.

Thank you :)

6 Jun 2012

Check Sdcard is available in device in Android

*Check Whether Sd card is available on Device*
       public boolean isSDCardMounted()
             {
              return android.os.Environment.getExternalStorageState().equals(
                                 android.os.Environment.MEDIA_MOUNTED);
             }
             if(isSDCardMounted)
             {
                    //you code here...
             }
             else
             {
                    //No sdcard
             }

*Create Folder in Sdcard*
           File SDCardRoot = Environment.getExternalStorageDirectory();
            SDCardRoot = new File(SDCardRoot,"FolderName");
            if (!SDCardRoot.exists())
            {
                  SDCardRoot.mkdir();
            }

*Create File in Sdcard*
            file = new File(SDCardRoot,filename);
            if(file.createNewFile())
            {
                  file.createNewFile();
            }



Permission:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
 <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />


I will be happy if you will provide your feedback or follow this blog. Any suggestion and help will be appreciated.

Thank you :)