New Update Version 1.6:

  • Add cropping function
  • Scale bitmap data before setting as wallpaper

To create an Android wallpaper app, the cropping picture function is quite necessary. To support multiple Android screens, I have to make sure to assign the right size pictures to Android wallpaper. In my solution, I will prepare a set of high resolution pictures to fit the majority Android screen size. When users choose one picture, I will let them to trim the pictures in a specific aspect ratio to perfectly fit the screen size. For example, I will prepare the big image in 1600×1000. When users want to set wallpaper on their 480×800 Android phone, I will provide a cropping tool which can only trims the image in 3:5 aspect ratio. Now, let me show you how I add this cropping feature in my Android Wallpaper app.

This Android Wallpaper App example includes four tutorials:

Adding Cropper Project in Eclipse

I am using the 3rd party Android library to implement the cropping function in my Wallpaper project. When you get my source code zip package, you will find there are two project, one is Cropper library project. You follow these steps to import the library project in Eclipse.

  • Choose File -> Import menu item
  • Select “Archive File” in the popup window
  • Choose the Cropper.zip file in the next window
  • Click finish to import the project in Eclipse

eclipse-cropper-library-project

import cropper 2

import cropper 3

You can use the same steps to import my project in the Eclipse. After that, you need to add Cropper library in Android Wallpaper example project. Here are the steps:

  • Right click on Android Wallpaper project
  • Select Properties option
  • Go to Android section and add Cropper library

add cropper library

Using CropImageView in previewpanel.xml

When users select one picture, I will show the image in the preview panel. In this preview panel, I will provide a crop tool for them to trim the image. Here is the layout xml example source code:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >
    <com.edmodo.cropper.CropImageView
        xmlns:custom="http://schemas.android.com/apk/res-auto"
        android:id="@+id/CropImageView"
        android:layout_below="@+id/adsContainerInPreview"
        android:layout_above="@+id/adsContainerInPreview2"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_gravity="center"/>
</RelativeLayout>

Load Image into Cropper

Now, let’s talk about how to load the image into cropper image widget. Actually it is very simple. But here I will set the crop widget to keep aspect ratio. Android requires the wallpaper resolution 2 times wider than the actually screen resolution. So I have to set the crop ratio 2 times wider than the Android screen size resolution aspect ratio. Here is some example code:

File cacheDir = GlobalClass.instance().getCacheFolder(this);
File cacheFile = new File(cacheDir, wallpaperFilePath);
InputStream fileInputStream = new FileInputStream(cacheFile);
BitmapFactory.Options bitmapOptions = new BitmapFactory.Options();
bitmapOptions.inSampleSize = scale;
bitmapOptions.inJustDecodeBounds = false;
Bitmap wallpaperBitmap = BitmapFactory.decodeStream(fileInputStream, null, bitmapOptions);

cropImageView = (CropImageView)this.findViewById(R.id.CropImageView);
cropImageView.setImageBitmap(imageBitmap);
cropImageView.setFixedAspectRatio(true);
cropImageView.setAspectRatio(screenWidth * 2, screenHeight);

crop image

Crop Image to Prepare Wallpaper For Android

Now, users can crop the images by dragging the corner. After users decide the size and area they want to set as wallpaper, they can click “set wallpaper” menu to set the Android wallpaper. Here is the android example source code to demonstrate how to trim the bitmap from original image.

RectF rect = cropImageView.getActualCropRect();
int cropx = (int) rect.left * scale;
int cropy = (int) rect.top * scale;
int cropw = (int) rect.width() * scale;
int croph = (int) rect.height() * scale;
Bitmap bitmapSource = BitmapFactory.decodeStream(fileInputStream);
final Bitmap croppedBitmap = Bitmap.createBitmap(bitmapSource, cropx, cropy, cropw, croph);
wallpaperManager.setBitmap(croppedBitmap);

Try Example Android App

You can download and install this android app by click the following link, or scan the following QR code to download and install on your android phone simply. If you feel it is helpful, please support me by clicking the banner inside the app.
Download and Run This Example on Your Android Phone
chart

Get Full Source Code under $6.99


You will get whole Android Wallpaper App source code at $6.99. With this source code, you can do everything you want:

  • Load your own wallpaper;
  • Monetize the app with your own AdMob publish id;
  • Use the source code in your own project;
  • Publish this app in your android develop account;
Previous PostNext Post

54 Comments

  1. Hi james,

    Very Good U did IT :-D, How to get the link of download ? (given that I already buy in step 4) ?

    Thanks Man 🙂

    1. Hi,

      You may get some error messages. I think it is because missing of Google Play service lib. If you don’t need the Admob ads banner, you can delete all adview, adrequest stuff.

  2. Hi James,
    Given that I already paid, can you send me the link for the update 1.6 package by email please.

    Thank you 🙂

      1. I don’t realy want to publish il in public :p Nevertheless, when I post this comment I put my email, can you see it ? :p

        Thanks

  3. i need this source code bt i haven’t paypal account …can u please sent ur account number i ll transfer u..thanks for advance

  4. Hello I bought your code but I cannot run the ads. It gives me the error “There was a problem getting an ad response. ErrorCode: 0”. I changed the error in manifest so this is not the problem.

    In addition, I tried to install the example but I cannot. Could you please fix it?

    1. What do you mean “I tried to install the example”? You are able to debug the app in your device, aren’t you? After you build an apk file, you’d better uninstall the debug version on your device, then install the released apk file.

      1. The example that you give in your post, is not working in my device.

        Anyway could you help me with the admob problem?

  5. hi there,
    On 21-4-2015 i had paid for this Android Wallpaper App full source code
    twice by mistake,But still my Purchase Failed to Download and i was unable to Get this Source Code.
    In other words…I have paid $6.99 + $6.99 to you…and i have nothing.
    Please check this Problem and i am requesting you to solve this
    problem and Refund my Money back.
    Regards,
    Akash.

  6. hi James, thanks for the template. I paid your fee and I did get the the main project.zip but I did not receive the cropper.zip that you said was included. Would you be able to email me a copy please? Thank you!

  7. Hi James I see u are doing a great job here. OK am really new to android development and I wanna created a wallpaper app. Ok I have android studio and eclipse on my PC . it looks like d tutorial is broken into parts(example) can u compile d whole source code into one downloadable file so I can download and import directly to my eclipse . to avoid concussion cuz am kind of confused looking at it example by example. Thanks

  8. And pls how can I set image wallpaper from my resources drawable directly instead downloading I want something completely off line. Thanks in advance

  9. Ok thanks for ur reply. But what I dont understand is I want create a wallpaper app. In my eclipse project and u have d source code broken can I get d full source code download to important in my eclipse or is there a way to join or merge each example together to get work. Thanks

    1. Hi,

      My website is too busy and the download service goes unfunctional. Now everything is going well. For your purchased source code, I will send it to your email.

      Thanks

Leave a Reply to Akash Singh Cancel reply

Your email address will not be published. Required fields are marked *