How to read a serialized object from a file in the raw folder in android?

In my previous post I showed how to serialize an object and save it in sdcard in a file and retrieve it.

Pull out the file from the sdcard and then create a folder named “raw” inside the “res” folder and copy it.

Serialization pull out file.
This example shows how to retreive it when it is in the res/raw folder.

Here is the code that does this.

 public void readFromResources(){
    	 try
         {
         	InputStream is = getResources().openRawResource(R.raw.save_object);
         	ObjectInputStream ois = new ObjectInputStream(is);
         	Person person = (Person)ois.readObject();
         	Log.v("Person : >> Name : ",person.getName() + ", Address : " + person.getAddress() + ", Number : " + person.getNumber());
         }
         catch(Exception ex)
         {
        	 Log.v("Serialization Error >> ",ex.getMessage());
         	 ex.printStackTrace();
         }
    }

You are done. Go on and run it.
Check the Logcat for the results.

How to set wallpaper in ANDROID?

Following example shows how to set a Bitmap as wallpaper in ANDROID.
After running this code your wallpaper on the ANDROID phone will change.

Make sure that you have an image named ‘my_wallpaper’ in your drawable folder.

And You have to set this permission in the Manifest.

<uses-permission android:name="android.permission.SET_WALLPAPER"/>
Bitmap wallpaper = BitmapFactory.decodeStream(getResources().openRawResource(R.drawable.my_wallpaper));
    	try
    	{
    			getApplicationContext().setWallpaper(wallpaper);
    	} catch (IOException e)
    	{
    			e.printStackTrace();
    	}