0

It's been days now, trying to figure how this function works... I have searched for it in stack overflow too ofcourse, Downloading and setting a wallpaper tried that, but got doInBackground error. and many more "seems legit" answer that I have tried. but in the end, I still had no clue how to change my

  final String url2 = "http://icons.iconarchive.com/icons/3xhumed/mega-games-pack-26/256/Call-of-Duty-World-at-War-5-icon.png";

                displaynya.setImageUrl(url2);

to be used when i call it in my button

 case R.id.BTsetWalp:
                                        WallpaperManager myWallpaperManager
                                        = WallpaperManager.getInstance(getApplicationContext());
            try {

                                myWallpaperManager.setResource(// what should i do with this?);

So confusing.. the past days, I'm trying to use only an image that has been stored in the apps, using that case 2

case R.id.ivwall02:
                displaynya.setImageResource(R.drawable.a2);

                setWallp = R.drawable.a2;
                break;

This code is working. but if I use that, my app's size will get huge, because all huge image for wallpaper is stored in the apps. so i want to use a method in case 1 (downloading the image first, then set it to wallpaper), but I'm stuck in there..

==================================================

EDIT 2, updated my code so far

Here is the full code

public class CopyOfGallery extends Activity implements View.OnClickListener {
private SmartImageView displaynya;

Button bWalp;



@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
setContentView(R.layout.gallery);


    bWalp = (Button) findViewById(R.id.BTsetWalp);

    displaynya = (SmartImageView)findViewById(R.id.iVDisplay);


    ImageView image01 = (ImageView) findViewById(R.id.ivwall01);
    ImageView image02 = (ImageView) findViewById(R.id.ivwall02);


    image01.setOnClickListener(this);
    image02.setOnClickListener(this);


    bWalp.setOnClickListener(this);


        }

            @Override
            public void onClick(View vImage) {
                // TODO Auto-generated method stub

                switch (vImage.getId()){

                case R.id.ivwall01:

                    final String url1 ="http://i100.photobucket.com/albums/m21/keitaro3660/komari/Komari02/km_happy.jpg" ;
               displaynya.setImageUrl(url1);




                    break;
                case R.id.ivwall02:

                    final String url2 ="http://i100.photobucket.com/albums/m21/keitaro3660/komari/Komari02/km_awkward.jpg" ;

                    displaynya.setImageUrl(url2);


                    break;



                case R.id.BTsetWalp:


                        // get the Image to as Bitmap 
                            Bitmap bitmap = BitmapFactory.decodeStream(getResources().openRawResource(R.id.iVDisplay));

                                DisplayMetrics metrics = new DisplayMetrics(); 
                                getWindowManager().getDefaultDisplay().getMetrics(metrics);
                                // get the height and width of screen 
                                int height = metrics.heightPixels; 
                                int width = metrics.widthPixels;

                             WallpaperManager wallpaperManager = WallpaperManager.getInstance(this); 
                try {

                    wallpaperManager.setBitmap(bitmap);

                      wallpaperManager.suggestDesiredDimensions(width, height);

                } catch (IOException e) {
                 // TODO Auto-generated catch block
                                    e.printStackTrace();
                }



                            }}

as for

Bitmap bitmap = BitmapFactory.decodeStream(getResources().openRawResource(R.id.iVDisplay));

this function is for fetch whatever image that shown in my R.id.iVDisplay isn't?? exactly what i needed. but why it got crash? :'(

here's my log

01-08 23:39:51.529: E/AndroidRuntime(22803): FATAL EXCEPTION: main

01-08 23:39:51.529: E/AndroidRuntime(22803): java.lang.NullPointerException

01-08 23:39:51.529: E/AndroidRuntime(22803): at android.content.res.Resources.openRawResource(Resources.java:951)

01-08 23:39:51.529: E/AndroidRuntime(22803): at android.content.res.Resources.openRawResource(Resources.java:927)

01-08 23:39:51.529: E/AndroidRuntime(22803): at preff.Gallery.onClick(Gallery.java:355) 01-08 23:39:51.529: E/AndroidRuntime(22803): at android.view.View.performClick(View.java:3526)

01-08 23:39:51.529: E/AndroidRuntime(22803): at android.view.View$PerformClick.run(View.java:14133)

missplacement or do i missing something? :(

Community
  • 1
  • 1
  • "Downloading and setting a wallpaper tried that, but got doInBackground error." What error you are getting ? – Jitender Dev Jan 08 '14 at 04:26
  • Go through this https://github.com/loopj/android-smart-image-view – Jitender Dev Jan 08 '14 at 04:28
  • wow really fast response :D @Brontok hmmm... i think like "AsyncTask #5" error when i try to press the image. it's yesterday and i already change the code... wow cool link! okay i'll try study there first :D thanks – keitaro3660 Jan 08 '14 at 04:55
  • okay in my case, i already finished the [Load an image into the view from a URL:]. but the problem is, how to tell eclipse to actually use that newly downloaded image to set it to wallpaper?? is that back to the basic of [setting a wallpaper from view]? same treatment? – keitaro3660 Jan 08 '14 at 05:02
  • how to apply this [displaynya.setImageUrl(url2);] to this [myWallpaperManager.setResource(setWallp);]?? it's within my grasp, but i don't know what to do, such a frustating feeling :'( – keitaro3660 Jan 08 '14 at 05:06

1 Answers1

0

try this , i think that's help you wallpaper

  • thx for replying back! i nearly lose hope... wow i think this is the solution Bitmap bitmap = BitmapFactory.decodeStream(getResources().openRawResource(R.id.iVDisplay)); . i got no error in implementation in eclipse, but when i instaled it on my phone, and press my [Set Wallpaper] Button, it got crash :( why is this? i have updated [UPDATE 2] my code in the question, please help. just a little more. maybe i missplace something,but i don't know what.. – keitaro3660 Jan 08 '14 at 17:09
  • or is it because my iVDisplay is SmartImageView and not a plain ImageView?? but even if that's the case, the image (or bitmap) is still there... hmmm... – keitaro3660 Jan 08 '14 at 17:37
  • tested in plain ImageView with predetermined R.drawable. got same error log as above... so what's the problem? :( – keitaro3660 Jan 08 '14 at 17:45
  • will you come to help again? :( – keitaro3660 Jan 10 '14 at 03:32