Wallpaper image not displayed in the correct size on all devices

852 views Asked by At

I did an app that sets the wallpaper using several png images on timed intervals. The wallpaper size that is displayed on the screen is not correct an all devices. On a 9.7" tablet, the size is perfect which includes enough room to scroll it left and right. On a phone however, only a small portion of each image can be seen. It looks like it's zoomed in.

What coding do I need to tell Android to display the images in the correct size on all devices?

I was assuming the WallpaperManager did this but it seems I don't know how to use it yet.

Here is how I'm changing the wallpaper:

myWallpaperManager.setResource(R.drawable.muzdalifah);

Edit showing all code used for changing the wallpapers:

public class AlarmReceiverChangeImage extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {

    /*
     * Make the settings available from the settings xml file.
     */
    SharedPreferences mySettings = PreferenceManager
            .getDefaultSharedPreferences(context);

    /*
     * Allow editing.
     */
    SharedPreferences.Editor editor = mySettings.edit();

    /*
     * Get the settings into variables.
     */
    boolean bln_checkbox_changing_is_activated = mySettings.getBoolean(
            "checkbox_changing_is_activated", false);

    String myCurrentImageName = mySettings.getString("current_image",
            "kabanight1");

    WallpaperManager myWallpaperManager = WallpaperManager
            .getInstance(context.getApplicationContext());

    if (bln_checkbox_changing_is_activated == true) {

        if (myCurrentImageName.equals("tentcity")) {

            try {

                myWallpaperManager.setResource(R.drawable.kabacloseup);
                myCurrentImageName = "kabacloseup";

            } catch (IOException e) {
                e.printStackTrace();
            }

        } else if (myCurrentImageName.equals("kabacloseup")) {
            try {

                myWallpaperManager.setResource(R.drawable.kabanight1);
                myCurrentImageName = "kabanight1";

            } catch (IOException e) {
                e.printStackTrace();
            }

        } else if (myCurrentImageName.equals("kabanight1")) {
            try {

                myWallpaperManager.setResource(R.drawable.madina1);
                myCurrentImageName = "madina1";

            } catch (IOException e) {
                e.printStackTrace();
            }

        } else if (myCurrentImageName.equals("madina1")) {
            try {

                myWallpaperManager.setResource(R.drawable.madina2);
                myCurrentImageName = "madina2";

            } catch (IOException e) {
                e.printStackTrace();
            }

        } else if (myCurrentImageName.equals("madina2")) {
            try {

                myWallpaperManager.setResource(R.drawable.kabaday1);
                myCurrentImageName = "kabaday1";

            } catch (IOException e) {
                e.printStackTrace();
            }

        } else if (myCurrentImageName.equals("kabaday1")) {
            try {

                myWallpaperManager.setResource(R.drawable.uhud1);
                myCurrentImageName = "uhud1";

            } catch (IOException e) {
                e.printStackTrace();
            }

        } else if (myCurrentImageName.equals("uhud1")) {
            try {

                myWallpaperManager.setResource(R.drawable.bus);
                myCurrentImageName = "bus";

            } catch (IOException e) {
                e.printStackTrace();
            }

        } else if (myCurrentImageName.equals("bus")) {
            try {

                myWallpaperManager.setResource(R.drawable.muzdalifah);
                myCurrentImageName = "muzdalifah";

            } catch (IOException e) {
                e.printStackTrace();
            }

        } else if (myCurrentImageName.equals("muzdalifah")) {
            try {

                myWallpaperManager.setResource(R.drawable.tentcity);
                myCurrentImageName = "tentcity";

            } catch (IOException e) {
                e.printStackTrace();
            }

        } else {

            try {
                myWallpaperManager.setResource(R.drawable.madina1);
                myCurrentImageName = "madina1";

            } catch (IOException e) {
                e.printStackTrace();
            }
        } // End if myCurrentImageName.equals("kabaday1").
    } // End if bln_checkbox_changing_is_activated == true.

    editor.putString("current_image", myCurrentImageName); // value to store
    editor.commit();
} // End method onReceive.
3

There are 3 answers

2
Vinayak Bevinakatti On BEST ANSWER

The rendering of your image depends on following:

Screen size

Screen density

Resolution

You should better read the below document completely to understand how you handle this situation: Supporting Multiple Screens

1
Padma Kumar On

myWallpaperManager this imageView should be fill_parent. RU giving any fixed size for that?

0
Fereshte Dh On

add to manifest this permissions<uses-permission android:name="android.permission.SET_WALLPAPER_HINTS"/> <uses-permission android:name="android.permission.SET_WALLPAPER" />