-3

I am making a project in which wallpaper will be changed after every 10 seconds I am able to set Bitmap array to the Service class using this code

resized[i]=    Bitmap.createScaledBitmap(yourbitmap, 480,800, true);
Intent i = new Intent(MainActivity.this,WallService.class);
                    i.putExtra("Imagess", resized);
                    startService(i);

In the service class i am using this code:

 String[] Bits = intent.getStringArrayExtra("Imagess");
        for(int i =0; i<Bits.length;i++){

        getApplicationContext().setWallpaper(Bits[i]);
        Thread.sleep(10000);
        }

It is giving error in this line The method setWallpaper(Bitmap) in the type Context is not applicable for the arguments (String). So what must I do so that i can set wallpapers by conerting String[] to Bitmap[]


Update 1:

Bitmap[] Bits = (Bitmap[]) intent.getExtras().getParcelableArray("Imagess");
        for(int i =0; i<Bits.length;i++){


        try {
            getApplicationContext().setWallpaper(Bits[i]);
            Thread.sleep(10000);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        }
nawaab saab
  • 1,892
  • 2
  • 20
  • 36
  • May i know why my question is downvoted – nawaab saab May 06 '14 at 06:51
  • How do you get "Bits" array? Like this: Bitmap[] Bits = (Bitmap[]) getIntent().getExtras().getParcelableArray("Imagess"); ? – krossovochkin May 06 '14 at 06:53
  • 1
    possible duplicate of [How many ways to convert bitmap to string and vice-versa?](http://stackoverflow.com/questions/13562429/how-many-ways-to-convert-bitmap-to-string-and-vice-versa) – Manish Dubey May 06 '14 at 06:56

1 Answers1

0

You are wrong using this code line:

 String[] Bits = intent.getStringArrayExtra("Imagess");

You put Parcelable[] to intent extras, but trying to get String[]. Use:

Bitmap[] Bits = (Bitmap[]) getIntent().getExtras().getParcelableArray("Imagess");

Update: If you init Bits array in Service onStart(Intent intent, int startId) method, then update this line:

Bitmap[] Bits = (Bitmap[]) getIntent().getExtras().getParcelableArray("Imagess");

to:

Bitmap[] Bits = (Bitmap[]) intent.getExtras().getParcelableArray("Imagess");

As you see, I replaced getIntent() method by intent argument from onStart(Intent intent, int startId) method

krossovochkin
  • 12,030
  • 7
  • 31
  • 54