Today I am going to show to how to build a free wallpapers app using Picasa Web Albums API. In this tutorial you can learn how to integrate multiple android components like splash screen, navigation drawer, grid view, volley library in a single app.

As this tutorial seems very lengthy, I divided this into two parts. In 1st part we do all basic setup like creating the Picasa albums, planning the app design and creating the android project and write some reusable components required for the app. In the 2nd part the actual implementation of the app starts where we add one by one module to the app like splash screen, navigation drawer, grid view and other things to complete the app.

android free wallpapers app part 2

1. Prerequisite

As this app is a complete application we need to integrate several components together. Please go through below articles before getting into this tutorial as these concepts are main building blocks for this app.

1. How to implement Android Splash Screen This explains how to add a splash screen to your app when the app needs to make few HTTP calls and fetch some data before going in to actual app flow.

2. Android Sliding Menu using Navigation Drawer This article helps in adding a slider menu for the app where we can show list of categories for wallpapers.

3. Android working with Volley Library We use volley to make network calls like downloading the json and images. Also another main advantage of using volley is image cache which makes the app faster.

4. Android Full Screen Image Slider with Swipe and Pinch Zoom Gestures This is another important article helps in creating the app’s main Grid View screen where the thumbnail preview of each wallpaper will be displayed in a grid fashion.

2. Google’s Picasa Web Albums API

The major and difficult task in this app is building the server side components like an admin panel to manage your wallpaper data by providing file upload option and other things. For this you should also able to code in other technologies like HTML, CSS, JSP, PHP or MySQL which is again a difficult task for android beginners.

So I selected Picasa Web Albums as a robust solution for this. Picasa web albums is free of cost and importantly it exposes an API (json and xml) for developers. You can go through Picasa Web Albums Data API to know more about the API’s exposed.

We are specifically interested in following API calls for this app which doesn’t require any authentication as we perform read operations only on public albums.

1. Request a list of albums
(username should be replaced with your Google username)

https://picasaweb.google.com/data/feed/api/user/username?kind=album&alt=json

2. List photos recently uploaded
(username should be replaced with your Google username)

https://picasaweb.google.com/data/feed/api/user/username?kind=photo&alt=json

3. List photos in album
(albumid should be replaced with actual album id which can find in albums response)

https://picasaweb.google.com/data/feed/api/user/username/albumid/albumid?alt=json

If you want to provide more options like providing user to comment, edit or delete options you need to implement authentication as mentioned in the document.

Hint: alt parameter decides the type of response we are expecting either json or xml. Pass alt=json in the url to get the response in JSON format.

3. Adding wallpapers in Picasa Web Albums

Before starting the app, we’ll add few wallpapers in Picasa albums for testing. You can login into Picasa using your Google account. Follow below steps to create albums and wallpapers in Picasa web albums.

1. Login into Picasa.
(If you are redirected to your Google+ account, click on Click here to go back to Picasa Web Albums to navigate back to Picasa Web or go with Google+ if you are comfortable)

2. Click on upload and enter your album name. These albums act as wallpaper categories in our app which will be listed in navigation drawer menu. Example: Animals, Cars, Food, Movies, Vintage etc.,

3. Once you created the album, upload few wallpapers to the album. Make sure that you are uploading the wallpapers with good high resolution.

4. Now make the album visibility as Public by clicking on Edit link displayed on the right. Note: If you don’t make your album as public, it will not be accessible via your android app. In other words you can’t see the album in the json response.

5. Follow 2nd, 3rd and 4th steps to create few more albums and wallpapers.

Checkout the below video which takes you through uploading process.


4. Designing The App

The design of this app is very minimalistic with very few color combinations. Overall it contains following components.

1. Navigation drawer (Slider Menu) to display wallpaper categories.
2. Grid view screen to display the thumbnail of wallpapers under a category.
3. Full screen view of wallpaper with Set As Wallpaper and Download Wallpaper options.
4. Settings screen to configure Picasa username, number of columns in grid and gallery image directory.

Below are screen shots of the final app.

Splash Screen

android freewallpapers app splash screen

Navigation Drawer

android wallpapers navigation drawer

Wallpapers thumbnail view

android wallpapers app grid view

Full screen view with Set As Wallpaper and Download options

android wallpapers app fullscreen view

Settings view

android wallpapers settings screen

5. Downloading Volley Library (volley.jar)

To make calls to Picasa API we are going to use Volley Library instead of using the java library mentioned in the documentation. I already published an article about Volley Library explaining about the advantages of choosing volley. In this project it plays a major role in caching the images.

Download the precompiled volley.jar

Now it’s time to start the android app. I am naming this app as Awesome Wallpapers.

6. Creating New Project

1. In Eclipse create a new project by navigating to File ⇒ New ⇒ Android Application Project and fill required details. I gave my project package name as info.androidhive.awesomewallpapers

2. Once the project is created paste the volley.jar in libs folder.

3. Download the resources and place them in your project’s respective folders. In this downloaded zip you will find splash screen background image and other app icons.

4. Now add below resource values in strings.xml, colors.xml. These values are used in various places in the project.

strings.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="app_name">Awesome Wallpapers</string>
    <string name="action_settings">Settings</string>
    <string name="nav_drawer_recently_added">Recently Added</string>
    <string name="toast_saved">Wallpapaer saved to #</string>
    <string name="toast_saved_failed">Sorry! Failed to save wallpaper</string>
    <string name="toast_wallpaper_set">Wallpapaer updated!</string>
    <string name="toast_wallpaper_set_failed">Sorry! Unable to set wallpapaer</string>
    <string name="splash_error">Unable to download wallpapers. Verify your google\'s user name in settings or device doesn\'t have internet connection!</string>
    <string name="set_wallpaper">Set</string>
    <string name="download_wallpaper">Download</string>
    <string name="msg_unknown_error">Sorry! Unknown error occurred.</string>
    <string name="msg_wall_fetch_error">Sorry! Unable to fetch wallpaper(s). Verify app settings or device doesn\'t have internet connection.</string>
    <string name="toast_enter_google_username">Please enter google username</string>
    <string name="toast_enter_valid_grid_columns">Please enter valid number of columns</string>
    <string name="toast_enter_gallery_name">Please enter gallery directory name</string>
    <string name="lbl_google_username">Google username</string>
    <string name="lbl_no_grid_columns">Number of grid columns</string>
    <string name="lbl_gallery_name">Gallery directory name</string>
    <string name="lbl_btn_save">Save</string>

</resources>

colors.xml

<?xml version="1.0" encoding="utf-8"?>
<resources>

    <color name="list_item_title">#d7ddee</color>
    <color name="list_background">#1a1b1d</color>
    <color name="list_background_pressed">#131315</color>
    <color name="list_divider">#272727</color>
    <color name="counter_text_bg">#626262</color>
    <color name="counter_text_color">#c5c4c4</color>
    <color name="black">#000000</color>
    <color name="grid_bg">#000000</color>
    <color name="grid_item_bg">#1a1b1d</color>
    <color name="action_bar">#141416</color>
    <color name="action_bar_title">#ffffff</color>
    <color name="white">#ffffff</color>
    <color name="settings_label">#323232</color>

</resources>

5. Now create five packages named app, helper, util and picasa.model under src folder. Right Click on src ⇒ New ⇒ Package.

info.androidhive.awesomewallpapers.app
info.androidhive.awesomewallpapers.helper
info.androidhive.awesomewallpapers.picasa.model
info.androidhive.awesomewallpapers.util

6. Now create AppConst.java in app package. All the app configuration like google username, picasa api urls, gallery directory name and other static variables goes in this class.

package info.androidhive.awesomewallpapers.app;


public class AppConst {

	// Number of columns of Grid View
	// by default 2 but user can configure this in settings activity
	public static final int NUM_OF_COLUMNS = 2;

	// Gridview image padding
	public static final int GRID_PADDING = 4; // in dp

	// Gallery directory name to save wallpapers
	public static final String SDCARD_DIR_NAME = "Awesome Wallpapers";

	// Picasa/Google web album username
	public static final String PICASA_USER = "freewallpapersapp";

	// Public albums list url
	public static final String URL_PICASA_ALBUMS = "https://picasaweb.google.com/data/feed/api/user/_PICASA_USER_?kind=album&alt=json";

	// Picasa album photos url
	public static final String URL_ALBUM_PHOTOS = "https://picasaweb.google.com/data/feed/api/user/_PICASA_USER_/albumid/_ALBUM_ID_?alt=json";

	// Picasa recenlty added photos url
	public static final String URL_RECENTLY_ADDED = "https://picasaweb.google.com/data/feed/api/user/_PICASA_USER_?kind=photo&alt=json";

}

7. Create another class named AppController.java under app package. This class extends from Application and this is a singleton class which initializes volley’s core objects and few other classes those can be used across the app.

package info.androidhive.awesomewallpapers.app;

import info.androidhive.awesomewallpapers.util.LruBitmapCache;
import info.androidhive.awesomewallpapers.util.PrefManager;
import android.app.Application;
import android.text.TextUtils;

import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.toolbox.ImageLoader;
import com.android.volley.toolbox.Volley;

public class AppController extends Application {

	public static final String TAG = AppController.class.getSimpleName();

	private RequestQueue mRequestQueue;
	private ImageLoader mImageLoader;
	LruBitmapCache mLruBitmapCache;

	private static AppController mInstance;
	private PrefManager pref;

	@Override
	public void onCreate() {
		super.onCreate();
		mInstance = this;
		pref = new PrefManager(this);
	}

	public static synchronized AppController getInstance() {
		return mInstance;
	}

	public PrefManager getPrefManger() {
		if (pref == null) {
			pref = new PrefManager(this);
		}

		return pref;
	}

	public RequestQueue getRequestQueue() {
		if (mRequestQueue == null) {
			mRequestQueue = Volley.newRequestQueue(getApplicationContext());
		}

		return mRequestQueue;
	}

	public ImageLoader getImageLoader() {
		getRequestQueue();
		if (mImageLoader == null) {
			getLruBitmapCache();
			mImageLoader = new ImageLoader(this.mRequestQueue, mLruBitmapCache);
		}

		return this.mImageLoader;
	}

	public LruBitmapCache getLruBitmapCache() {
		if (mLruBitmapCache == null)
			mLruBitmapCache = new LruBitmapCache();
		return this.mLruBitmapCache;
	}

	public <T> void addToRequestQueue(Request<T> req, String tag) {
		req.setTag(TextUtils.isEmpty(tag) ? TAG : tag);
		getRequestQueue().add(req);
	}

	public <T> void addToRequestQueue(Request<T> req) {
		req.setTag(TAG);
		getRequestQueue().add(req);
	}

	public void cancelPendingRequests(Object tag) {
		if (mRequestQueue != null) {
			mRequestQueue.cancelAll(tag);
		}
	}
}

8. Create Utils.java under util package. This class contains few helper methods.

package info.androidhive.awesomewallpapers.util;

import info.androidhive.awesomewallpapers.R;

import java.io.File;
import java.io.FileOutputStream;
import java.util.Random;

import android.app.WallpaperManager;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Point;
import android.os.Environment;
import android.util.Log;
import android.view.Display;
import android.view.WindowManager;
import android.widget.Toast;

public class Utils {
	private String TAG = Utils.class.getSimpleName();
	private Context _context;
	private PrefManager pref;

	// constructor
	public Utils(Context context) {
		this._context = context;
		pref = new PrefManager(_context);
	}

	/*
	 * getting screen width
	 */
	@SuppressWarnings("deprecation")
	public int getScreenWidth() {
		int columnWidth;
		WindowManager wm = (WindowManager) _context
				.getSystemService(Context.WINDOW_SERVICE);
		Display display = wm.getDefaultDisplay();

		final Point point = new Point();
		try {
			display.getSize(point);
		} catch (java.lang.NoSuchMethodError ignore) {
			// Older device
			point.x = display.getWidth();
			point.y = display.getHeight();
		}
		columnWidth = point.x;
		return columnWidth;
	}

	public void saveImageToSDCard(Bitmap bitmap) {
		File myDir = new File(
				Environment
						.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),
				pref.getGalleryName());

		myDir.mkdirs();
		Random generator = new Random();
		int n = 10000;
		n = generator.nextInt(n);
		String fname = "Wallpaper-" + n + ".jpg";
		File file = new File(myDir, fname);
		if (file.exists())
			file.delete();
		try {
			FileOutputStream out = new FileOutputStream(file);
			bitmap.compress(Bitmap.CompressFormat.JPEG, 90, out);
			out.flush();
			out.close();
			Toast.makeText(
					_context,
					_context.getString(R.string.toast_saved).replace("#",
							"\"" + pref.getGalleryName() + "\""),
					Toast.LENGTH_SHORT).show();
			Log.d(TAG, "Wallpaper saved to: " + file.getAbsolutePath());

		} catch (Exception e) {
			e.printStackTrace();
			Toast.makeText(_context,
					_context.getString(R.string.toast_saved_failed),
					Toast.LENGTH_SHORT).show();
		}
	}

	public void setAsWallpaper(Bitmap bitmap) {
		try {
			WallpaperManager wm = WallpaperManager.getInstance(_context);

			wm.setBitmap(bitmap);
			Toast.makeText(_context,
					_context.getString(R.string.toast_wallpaper_set),
					Toast.LENGTH_SHORT).show();
		} catch (Exception e) {
			e.printStackTrace();
			Toast.makeText(_context,
					_context.getString(R.string.toast_wallpaper_set_failed),
					Toast.LENGTH_SHORT).show();
		}
	}
}

9. Create LruBitmapCache.java and paste the below code. This class used to keep the volley cached objects on the disk.

package info.androidhive.awesomewallpapers.util;

import com.android.volley.toolbox.ImageLoader.ImageCache;

import android.graphics.Bitmap;
import android.support.v4.util.LruCache;

public class LruBitmapCache extends LruCache<String, Bitmap> implements
		ImageCache {
	public static int getDefaultLruCacheSize() {
		final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);
		final int cacheSize = maxMemory / 8;

		return cacheSize;
	}

	public LruBitmapCache() {
		this(getDefaultLruCacheSize());
	}

	public LruBitmapCache(int sizeInKiloBytes) {
		super(sizeInKiloBytes);
	}

	@Override
	protected int sizeOf(String key, Bitmap value) {
		return value.getRowBytes() * value.getHeight() / 1024;
	}

	@Override
	public Bitmap getBitmap(String url) {
		return get(url);
	}

	@Override
	public void putBitmap(String url, Bitmap bitmap) {
		put(url, bitmap);
	}
}

10. Create two classes named Category.java and Wallpaper.java under picasa.model package. These POJO classes will be useful while parsing the json data fetched from Picasa.

package info.androidhive.awesomewallpapers.picasa.model;

public class Category {
	public String id, title;

	public Category() {		
	}

	public Category(String id, String title) {		
		this.id = id;
		this.title = title;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}
}
package info.androidhive.awesomewallpapers.picasa.model;

import java.io.Serializable;

public class Wallpaper implements Serializable {
	private static final long serialVersionUID = 1L;
	private String url, photoJson;
	private int width, height;

	public Wallpaper() {
	}

	public Wallpaper(String photoJson, String url, int width, int height) {		
		this.photoJson = photoJson;
		this.url = url;
		this.width = width;
		this.height = height;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public String getPhotoJson() {
		return photoJson;
	}

	public void setPhotoJson(String photoJson) {
		this.photoJson = photoJson;
	}

	public int getWidth() {
		return width;
	}

	public void setWidth(int width) {
		this.width = width;
	}

	public int getHeight() {
		return height;
	}

	public void setHeight(int height) {
		this.height = height;
	}
}

11. Finally create another class named PrefManager.java under utils package. This class takes care of storing the data in Shared Preferences. The data like google username, picasa wallpaper categories, gallery name and other things will be stored in shared preferences.

package info.androidhive.awesomewallpapers.util;

import info.androidhive.awesomewallpapers.app.AppConst;
import info.androidhive.awesomewallpapers.picasa.model.Category;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import android.content.Context;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.util.Log;

import com.google.gson.Gson;

public class PrefManager {
	private static final String TAG = PrefManager.class.getSimpleName();

	// Shared Preferences
	SharedPreferences pref;

	// Editor for Shared preferences
	Editor editor;

	// Context
	Context _context;

	// Shared pref mode
	int PRIVATE_MODE = 0;

	// Sharedpref file name
	private static final String PREF_NAME = "AwesomeWallpapers";

	// Google's username
	private static final String KEY_GOOGLE_USERNAME = "google_username";

	// No of grid columns
	private static final String KEY_NO_OF_COLUMNS = "no_of_columns";

	// Gallery directory name
	private static final String KEY_GALLERY_NAME = "gallery_name";

	// gallery albums key
	private static final String KEY_ALBUMS = "albums";

	public PrefManager(Context context) {
		this._context = context;
		pref = _context.getSharedPreferences(PREF_NAME, PRIVATE_MODE);

	}

	/**
	 * Storing google username
	 * */
	public void setGoogleUsername(String googleUsername) {
		editor = pref.edit();

		editor.putString(KEY_GOOGLE_USERNAME, googleUsername);

		// commit changes
		editor.commit();
	}

	public String getGoogleUserName() {
		return pref.getString(KEY_GOOGLE_USERNAME, AppConst.PICASA_USER);
	}

	/**
	 * store number of grid columns
	 * */
	public void setNoOfGridColumns(int columns) {
		editor = pref.edit();

		editor.putInt(KEY_NO_OF_COLUMNS, columns);

		// commit changes
		editor.commit();
	}

	public int getNoOfGridColumns() {
		return pref.getInt(KEY_NO_OF_COLUMNS, AppConst.NUM_OF_COLUMNS);
	}

	/**
	 * storing gallery name
	 * */
	public void setGalleryName(String galleryName) {
		editor = pref.edit();

		editor.putString(KEY_GALLERY_NAME, galleryName);

		// commit changes
		editor.commit();
	}

	public String getGalleryName() {
		return pref.getString(KEY_GALLERY_NAME, AppConst.SDCARD_DIR_NAME);
	}

	/**
	 * Storing albums in shared preferences
	 * */
	public void storeCategories(List<Category> albums) {
		editor = pref.edit();
		Gson gson = new Gson();

		Log.d(TAG, "Albums: " + gson.toJson(albums));

		editor.putString(KEY_ALBUMS, gson.toJson(albums));

		// save changes
		editor.commit();
	}

	/**
	 * Fetching albums from shared preferences. Albums will be sorted before
	 * returning in alphabetical order
	 * */
	public List<Category> getCategories() {
		List<Category> albums = new ArrayList<Category>();

		if (pref.contains(KEY_ALBUMS)) {
			String json = pref.getString(KEY_ALBUMS, null);
			Gson gson = new Gson();
			Category[] albumArry = gson.fromJson(json, Category[].class);

			albums = Arrays.asList(albumArry);
			albums = new ArrayList<Category>(albums);
		} else
			return null;

		List<Category> allAlbums = albums;

		// Sort the albums in alphabetical order
		Collections.sort(allAlbums, new Comparator<Category>() {
			public int compare(Category a1, Category a2) {
				return a1.getTitle().compareToIgnoreCase(a2.getTitle());
			}
		});

		return allAlbums;

	}

	/**
	 * Comparing albums titles for sorting
	 * */
	public class CustomComparator implements Comparator<Category> {
		@Override
		public int compare(Category c1, Category c2) {
			return c1.getTitle().compareTo(c2.getTitle());
		}
	}
}

Now we have all the required classes in place. So let’s start adding one by one component to the app in Android Building Free Wallpapers App – Part 2

Ravi is hardcore Android programmer and Android programming has been his passion since he compiled his first hello-world program. Solving real problems of Android developers through tutorials has always been interesting part for him.
  • Cool!
    will try this!

  • عثمان السليماني المغرب

    or the best

  • kamran

    yesss

  • Dear Ravi,

    On Click Recently Added, Volley getting Error: Could not Delete cache entry for key=https://picasaweb.google.com/data/feed/api/user/nilay.scet?albumid/5637447830974140801?alt=json, filename=-1830143455-280059811

    and also give same error in Profile Photos

  • AK

    Hi Ravi nice tutorial.. i have doubt. I saved the wall paper but I couldn’t find the saved picture in Gallery but it’s exist storage/pictures/awesome wallpapers. what may be the issue? Please solve the problem and update the code. Thanks in advance

    • WhiteOne

      hello, did you find a solution for this problem? thanks

  • Guest

    error @ import com.google.gson.Gson;
    in PrefManager

    • MackAttack

      you need to download the google gson library from google.

  • aniket

    how to hide profile picture and scrapbook pictures ….as they are public by default…they are showed up in recently added category…. 🙁

  • Suat

    best tuttorial. it works stable

    • Capkin

      hi i have some problem can you help me?

  • sokea

    thank for your tutorial .Can you make tutorial about How to play youtube in fragment ? using your Tutorial Menu using Navigation Drawer

  • Capkin

    error @ ActionBarDrawerToogle in MainActivity

  • chien

    thank for your tutorial…but it is low loading

  • Mardoqueu Sousa

    I didn’t understand, I tried several times get my own wallpapers from picasa chaging PICASA_USER by the mine, could explain me what should I to do??? I just wanted get my own pictures from picasa…

  • Byron Viljoen

    Download links not working… seems to be timing out.

  • Khalil Serano

    guys can anyone tell me how to change Package name without getting errors please

    • Hector Franco

      If you are using Android Studio, you can go to “bulid.grade” file in your proyect and change the line
      applicationid for your new package name, and it’s not necessary doing something else.

      defaultConfig {

      applicationId “com.studios.rev.tech.wallpapergallery”

      minSdkVersion 14

      targetSdkVersion 19

      }

  • Mohammad

    Hi Ravi,
    How Can i get image with HTTP protocol? Because in same device in my country can’t view image 🙁
    Please Help me!

  • Hector Franco

    Hi guys, i want to thank for this tutorial and this app, it’s incrediblely help to me, i have a little problem with Picasa, so, as you can see Picasa is assosiate with Google Plus, when i put my User of Google, it has a Album called Profile Picture, What can i do for the app ignore that album? Thank you guys

    • hanish yadav

      create a new account and do not activate g+ account

  • Ahmet Öney

    Hello. How do I add my own album with this application?

  • deni777

    How to hide album “Profile Photos” ?

    • Urvish

      same question.i need help

    • Why don’t you delete the profile pictures? For my new project, I created a new account and deleted the profile pictures.. Not it is OK…

  • Sahitya Kumar Suman

    @Ravi Tamada

    My app is opening again and again setting activity and saying that your google username is not

    and shows

    Volley Error: java.net.UnknownHostException: Unable to resolve host “picasaweb.google.com”: No address associated with hostname

    following error

  • deni777

    I have problem with quality of wallpapers.I upload wallpapers with size-2560×1600,but wallpapers looks with low quality.On picasa image is over 4 mb wen save same image on my device is over 2mb.

  • hacker don’t have

    running in emulator but not installing in device……………. please help

  • deni777

    Hope that will get help! I try app on emulator and get error-05-22 09:27:51.670: E/dalvikvm-heap(675): Out of memory on a 5753616-byte allocation.

    05-22 09:27:51.770: E/Volley(675): [79] ImageRequest.parseNetworkResponse: Caught OOM for 737392 byte image, url=https://lh3.googleusercontent.com/-X5dAP0vboJM/U-9UskLWBTI/AAAAAAAAAe4/veht1_R2iGQ/d/blue_peacock-wallpaper-2560×1600.jpg

  • deni777

    What should be maximum wallpaper size in px and mb.I got error in emulator for low heap space.Please answer me!

  • 66666666666

    5666666666666

  • romani.kandelaki

    Hi guys, please, how to edit downloaded files? I have just Android Studio – Can I to edit this project here? or I need some program?

  • Bijay Chamlagai

    How to add zoom in and out function and image opens in portrait only

  • Ranjan Mishra

    Can you please update this tutorial with material design 🙂

    • It is already.

      • Nikhil Singh

        Sir , plz tell me how to change the color of status bar. I tried evrything but i failed.:/

  • sarun

    sir i have a problem, saved folder & images not showing in gallery.but can view through file managers.how to update media scanner

    thnxs for the nice tutorials

  • Ala’a Abdullah

    Adding this code i found on stackoverflow to the saveImage2Sd method did the job for the images that are not showing in the gallery.

    private void scanMedia(File path) {

    Uri uri = Uri.fromFile(path);
    Intent scanFileIntent = new Intent(
    Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, uri);
    _context.sendBroadcast(scanFileIntent);
    }

    Hope it helps.

    • sarun

      thank u for the replay
      It worked

      • Nikhil Singh

        bro plz tell me where in saveimage2sd method should i paste this code. i m getting error while pasting it..:( plz help

        • sarun

          Actually it won’t work on new devices 4.4 +

          and media scanner method require more resources, it will slow down devices with more contents on storage

          so i go with the mediastore db update approach

          Try this

          ContentValues values = new ContentValues();

          values.put(MediaStore.Images.Media.DATA,file.getAbsolutePath());

          values.put(MediaStore.Images.Media.MIME_TYPE,”image/jpeg”);

          _context.getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,values);

          happy coding 😉

          • Nikhil Singh

            Thanx bro for the rply!
            i worked like a charm..:) thanx a lot.
            happy coding:)

  • Shirisha Gangula

    While running my is crashed.i dont know what is the error

    my AppConst.java is

    public class AppConst {

    // Number of columns of Grid View
    // by default 2 but user can configure this in settings activity
    public static final int NUM_OF_COLUMNS = 2;

    // Gridview image padding
    public static final int GRID_PADDING = 4; // in dp

    // Gallery directory name to save wallpapers
    public static final String SDCARD_DIR_NAME = “Awesome Wallpapers”;
    // Picasa/Google web album username
    public static final String PICASA_USER = “freewallpapersapp”;

    // Public albums list url
    public static final String URL_PICASA_ALBUMS = “https://picasaweb.google.com/data/feed/api/user/shirishasaikumar?kind=album&alt=json”;

    // Picasa album photos url
    public static final String URL_ALBUM_PHOTOS = “https://picasaweb.google.com/data/feed/api/user/shirishasaikumar/albumid/_ALBUM_ID_?alt=json”;

    // Picasa recenlty added photos url
    public static final String URL_RECENTLY_ADDED = “https://picasaweb.google.com/data/feed/api/user/shirishasaikumar?kind=photo&alt=json”;

    }

    when my app crashes im getting the following things in logcat

    08-12 16:43:22.389 18251-18251/? W/dalvikvm﹕ VFY: unable to resolve virtual method 537: Landroid/content/pm/PackageManager;.getPackageInstaller ()Landroid/content/pm/PackageInstaller;

    08-12 16:43:22.459 18251-18251/? W/GAv4﹕ CampaignTrackingReceiver is not registered, not exported or is disabled. Installation campaign tracking is not possible. See http://goo.gl/8Rd3yj for instructions.

    08-12 16:43:22.839 18312-18312/? I/MultiDex﹕ install

    08-12 16:43:22.859 18312-18312/? I/MultiDex﹕ install done

    08-12 16:43:23.149 18312-18347/? I/dalvikvm﹕ Could not find method android.content.pm.PackageManager.getPackageInstaller, referenced from method com.google.android.gms.common.GooglePlayServicesUtil.zzh

    08-12 16:43:23.149 18312-18347/? W/dalvikvm﹕ VFY: unable to resolve virtual method 517: Landroid/content/pm/PackageManager;.getPackageInstaller ()Landroid/content/pm/PackageInstaller;

    08-12 16:43:25.739 18217-18227/? I/dalvikvm﹕ Could not find method android.content.pm.PackageManager.getPackageInstaller, referenced from method com.google.android.gms.common.kf.a

    08-12 16:43:25.739 18217-18227/? W/dalvikvm﹕ VFY: unable to resolve virtual method 460: Landroid/content/pm/PackageManager;.getPackageInstaller ()Landroid/content/pm/PackageInstaller;

    08-12 16:43:25.999 18312-18312/? W/GAv4﹕ CampaignTrackingReceiver is not registered, not exported or is disabled. Installation campaign tracking is not possible. See http://goo.gl/8Rd3yj for instructions.

    08-12 16:43:26.119 18312-18462/? I/AppsFlyer_1.10-378006025﹕ data: uid=1431711915707-8893133370169098795&model=SM-A500G&af_v=a09035880167c91a707b897124818be0db045fd6&app_version_code=103&af_preinstalled=false&lang=English&network=WIFI&currency=INR&android_id=e8fe1e2b95d7effd&firstLaunchDate=2015-05-15_1115%2B0530&installDate=2015-05-15_1115%2B0530&deviceType=user&date2=2015-08-11_0838%2B0530&carrier=IND+airtel&advertiserIdEnabled=false&sdk=19&dkh=PzctUWAy&date1=2015-05-15_1115%2B0530&appsflyerKey=PzctUWAyaZJq5n58YV8C59&counter=656&imei=356320063877429&operator=airtel&fb=86a46bac-ba5a-49f9-972c-744ab987f5ca&isFirstCall=false&product=a5ltedd&af_timestamp=1439378006025&device=a5lte&brand=samsung&app_version_name=1.9.13&channel=Playstore&advertiserId=af7c612c-9a07-420a-9954-c1857a85fd2b

    08-12 16:43:26.909 18312-18474/? I/AppsFlyer_1.10﹕ Calling server for attribution url: https://api.appsflyer.com/install_data/v3/com.goibibo-Playstore?devkey=PzctUWAyaZJq5n58YV8C59&device_id=1431711915707-8893133370169098795

    08-12 16:43:27.639 18312-18474/? I/AppsFlyer_1.10﹕ AttributionIdFetcher response code: 400 url: https://api.appsflyer.com/install_data/v3/com.goibibo-Playstore?devkey=PzctUWAyaZJq5n58YV8C59&device_id=1431711915707-8893133370169098795

    08-12 16:43:36.139 656-656/? D/Finsky﹕ [1] 5.onFinished: Installation state replication succeeded.

    Please Help me to solve my problem….

  • Shirisha Gangula

    what is picasa username and Where should we give Picasa username.

    I tried by giving it in AppConst.java but my app is crashed

    MY AppConst.java is

    public class AppConst {

    // Number of columns of Grid View
    // by default 2 but user can configure this in settings activity
    public static final int NUM_OF_COLUMNS = 2;

    // Gridview image padding
    public static final int GRID_PADDING = 4; // in dp

    // Gallery directory name to save wallpapers
    public static final String SDCARD_DIR_NAME = “Awesome Wallpapers”;
    // Picasa/Google web album username
    public static final String PICASA_USER = “freewallpapersapp”;

    // Public albums list url
    public static final String URL_PICASA_ALBUMS = “https://picasaweb.google.com/data/feed/api/user/shirishasaikumar?kind=album&alt=json”;

    // Picasa album photos url
    public static final String URL_ALBUM_PHOTOS = “https://picasaweb.google.com/data/feed/api/user/shirishasaikumar/albumid/_ALBUM_ID_?alt=json”;

    // Picasa recenlty added photos url
    public static final String URL_RECENTLY_ADDED = “https://picasaweb.google.com/data/feed/api/user/shirishasaikumar?kind=photo&alt=json”;

    }

    When my app crashing im getting the following in logcat

    08-12 16:43:22.389 18251-18251/? W/dalvikvm﹕ VFY: unable to resolve virtual method 537: Landroid/content/pm/PackageManager;.getPackageInstaller ()Landroid/content/pm/PackageInstaller;

    08-12 16:43:22.459 18251-18251/? W/GAv4﹕ CampaignTrackingReceiver is not registered, not exported or is disabled. Installation campaign tracking is not possible. See http://goo.gl/8Rd3yj for instructions.

    08-12 16:43:22.839 18312-18312/? I/MultiDex﹕ install

    08-12 16:43:22.859 18312-18312/? I/MultiDex﹕ install done

    08-12 16:43:23.149 18312-18347/? I/dalvikvm﹕ Could not find method android.content.pm.PackageManager.getPackageInstaller, referenced from method com.google.android.gms.common.GooglePlayServicesUtil.zzh

    08-12 16:43:23.149 18312-18347/? W/dalvikvm﹕ VFY: unable to resolve virtual method 517: Landroid/content/pm/PackageManager;.getPackageInstaller ()Landroid/content/pm/PackageInstaller;

    08-12 16:43:25.739 18217-18227/? I/dalvikvm﹕ Could not find method android.content.pm.PackageManager.getPackageInstaller, referenced from method com.google.android.gms.common.kf.a

    08-12 16:43:25.739 18217-18227/? W/dalvikvm﹕ VFY: unable to resolve virtual method 460: Landroid/content/pm/PackageManager;.getPackageInstaller ()Landroid/content/pm/PackageInstaller;

    08-12 16:43:25.999 18312-18312/? W/GAv4﹕ CampaignTrackingReceiver is not registered, not exported or is disabled. Installation campaign tracking is not possible. See http://goo.gl/8Rd3yj for instructions.

    08-12 16:43:26.119 18312-18462/? I/AppsFlyer_1.10-378006025﹕ data: uid=1431711915707-8893133370169098795&model=SM-A500G&af_v=a09035880167c91a707b897124818be0db045fd6&app_version_code=103&af_preinstalled=false&lang=English&network=WIFI&currency=INR&android_id=e8fe1e2b95d7effd&firstLaunchDate=2015-05-15_1115%2B0530&installDate=2015-05-15_1115%2B0530&deviceType=user&date2=2015-08-11_0838%2B0530&carrier=IND+airtel&advertiserIdEnabled=false&sdk=19&dkh=PzctUWAy&date1=2015-05-15_1115%2B0530&appsflyerKey=PzctUWAyaZJq5n58YV8C59&counter=656&imei=356320063877429&operator=airtel&fb=86a46bac-ba5a-49f9-972c-744ab987f5ca&isFirstCall=false&product=a5ltedd&af_timestamp=1439378006025&device=a5lte&brand=samsung&app_version_name=1.9.13&channel=Playstore&advertiserId=af7c612c-9a07-420a-9954-c1857a85fd2b

    08-12 16:43:26.909 18312-18474/? I/AppsFlyer_1.10﹕ Calling server for attribution url: https://api.appsflyer.com/install_data/v3/com.goibibo-Playstore?devkey=PzctUWAyaZJq5n58YV8C59&device_id=1431711915707-8893133370169098795

    08-12 16:43:27.639 18312-18474/? I/AppsFlyer_1.10﹕ AttributionIdFetcher response code: 400 url: https://api.appsflyer.com/install_data/v3/com.goibibo-Playstore?devkey=PzctUWAyaZJq5n58YV8C59&device_id=1431711915707-8893133370169098795

    08-12 16:43:36.139 656-656/? D/Finsky﹕ [1] 5.onFinished: Installation state replication succeeded.

    Please help me….

  • Mostafa Mohamad

    where I can find albumid?

  • Error:Execution failed for task ‘:app:dexDebug’.

    > com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process ‘command ‘C:Program FilesJavajdk1.8.0_45binjava.exe” finished with non-zero exit value 2

    Above error is being shown on running the app.

    Can you help me in this?

  • Muhammed Abdullah

    hello Ravi, thanks for the great tutorial and for the free source code. It always helps beginners like me.
    but I need your help in a few things and if you helped me I will click on every ad on your page.
    1st thing is:- I want to add some tabs like “websites, about us, etc…” to the navigation slider with the albums Can I and How? I read “Android Sliding Menu using Navigation Drawer” but I couldn’t add another tab in the sliding menu. Any helps?
    2nd thing is:- I want to add 3 buttons “share photo, back button” and favourite button “the last one is optional for me” in the FullScreenViewActivity.java and also add it in activity_fullscreen_image.xml . Any helps?
    3rd things :- “it is very optional” i want to have the albums in action bar navigation not in slider of the home tab and the tabs that i will add be in the slider How?
    Thanks,
    Muhammed Abdullah
    If anyone can help me please reply to this message

  • Muhammed Abdullah

    hello Ravi, thanks for the great tutorial and for the free source code. It always helps beginners like me.
    but I need your help in a few things and if you helped me I will click on every ad on your page.
    1st
    thing is:- I want to add some tabs like “websites, about us, etc…” to
    the navigation slider with the albums Can I and How? I read “Android Sliding Menu using Navigation Drawer” but I couldn’t add another tab in the sliding menu. Any helps?
    2nd
    thing is:- I want to add 3 buttons “share photo, back button” and
    favourite button “the last one is optional for me” in the
    FullScreenViewActivity.java and also add it in
    activity_fullscreen_image.xml . Any helps?
    3rd things :- “it is very
    optional” i want to have the albums in action bar navigation not in
    slider of the home tab and the tabs that i will add be in the slider
    How?
    Thanks,
    Muhammed Abdullah
    If anyone can help me please reply to this message

  • sarun

    How to add a next and previous buttons in FullScreenViewActivity ?
    Any help will be appreciated
    Thank u

  • Serdar Koçoğlu

    You hide in the code of practice, but you tell me where. Can you tell me where it is.

  • Nikhil Singh

    sir, saved images and there folder is not showing in galary..please if you have any solution about it then help me..:(

  • Milan

    Thanx Ravi, But I need you help I got an error

    Caused by: java.lang.NullPointerException: Attempt to invoke virtual method ‘com.domore.freewallpaper.util.PrefManager com.domore.freewallpaper.app.AppController.getPrefManger()’ on a null object reference

    at com.domore.freewallpaper.SplashActivity.onCreate(SplashActivity.java:40)

    please, Brol help me to solve out this error as soon as possible

    • Bishwajit Nepali

      I have the same problem, I guess there is some error in constants , Let me know if u solved this

  • Milan

    https://picasaweb.google.com/data/feed/api/user/_PICASA_USER_?kind=album&alt=json

    What i need to insert instead of _PICASA_USER_?

    how to find the value to get the list of album?

  • Bishwajit Nepali

    Caused by: java.lang.NullPointerException: Attempt to invoke virtual method ‘com.domore.freewallpaper.util.PrefManager com.domore.freewallpaper.app.AppController.getPrefManger()’ on a null object reference

    I have the same this error if you have make it run please put comment ..what should be kept in google name, Picasa User….??

  • Ahmad Ryandi

    ravi can we change the background colour or maybe we can use another photo for the background?
    if we can change, how ?
    please answer me

  • Dhaval Asodariya

    ERROR. with use of Gradle in AndroidStuio

    java.lang.RuntimeException: Unable to start activity ComponentInfo{com.mountheights.apps.gridviewgalleryexample/com.mountheights.apps.gridviewgalleryexample.SplashActivity}: java.lang.NullPointerException: Attempt to invoke virtual method ‘com.mountheights.apps.gridviewgalleryexample.util.PrefManager com.mountheights.apps.gridviewgalleryexample.app.AppController.getPrefManger()’ on a null object reference

  • Haitham

    Can I use this code inside my app? do I have to take license?

  • Mohd Shah Nawaz

    Hi Ravi, This tutorial is great but I have faced some challenges as some of the APIs that you used are depreciated so I have written the tutorial again using RecyclerView and Material Design. I have mentioned you in the beginning of tutorial and provided the links to this tutorial. I hope you won’t mind it. I am a newbie in the Android world. Here is the link to my tutorial in case you want to have a look.
    http://www.geekmentors.com/tutorial/android-free-wallpaper-with-admob-google-analytics-using-recyclerview-and-drawerlayout-from-start-to-finish-part-1/

  • sarun

    Picasa not returning updated ‘recently added’ content any more
    Google is going to kill picasa service soon,is there any way i can fetch recently added content

    • Mohd Shah Nawaz

      There is a way of doing so but it require a little effort. You will have to download the Desktop Application for Picasa, and you will have to sync the Web Albums with your local directory. This App will create an album something like “Recently Updated” which keep track of the recently added photos. But problem is that Google API returns the album name in Alphabetical order, so this album will not be your first album.

      I have done it already but I am not using it, I am just fetching all the albums and displaying the first album.

      • Hi
        Cant you give me the link of your tutorial ?
        Because i cant acces your site?

        • Mohd Shah Nawaz

          Ohh I see. I will check and try to up the site. I will get back to you.

          • Aldy Putra W

            okay, I hope not too long, because I really need it 🙂

          • Mohd Shah Nawaz

            If you need source code of my project I can share it right away. send me your email Id if you require the source code.

          • Aldy Putra W

            this my email : aldyputraw@gmail.com , 🙂

          • Aldy Putra W

            this my email aldyputraw@gmail.com

  • Sonagara Shailesh

    How to remove “recently uploaded” tab from app. I want only album.

  • Tomas Broten

    Thank you Ravi your post always
    helps so much for me. Please I have only
    one album category and I don’t need navigation drawer and splash screen. When
    the app starts it fetches that category. Please help me to do that. I will wait
    your response

  • Rahul Pawar

    Hi Ravi , Can u plz tell me where can i find those three links of google picasa album..since i found ly 2 and 3 .. i could not find 1st link.. can u please help me out..
    thank u..

  • Mikeli Lekeli

    i just want to display only one album. How can i do this ?

  • Aldy Putra W

    Hi Ravi, my problem is a cant remove recent album, how to remove this?
    thanks

  • mohit

    I got this error :

    AssertionError: Don’t invoke waitForSmartMode from inside read action in dumb mode

  • adi

    Hi, apologies in joining the party late.
    Since the picassa is officially gone now..can i use the same technique to store the images in cloud using drive/dropbox & access them the described manner?

  • Hüseyin Baduk

    We can’t create album as a public album in Picasa API anymore 🙁 Is there a any solution for Google photos?

  • Raj

    I am new to android. Is it fine with u if I can use your code to learn and implement my app. Is there any copyright issue?

  • Umair

    Picasa dying can you make a tutorial on tumblr api for android wallpaper app ?

    • The tutorial intent was to explain how to connect to a remote server and display the wallpapers in the app. You have to take care of migrating to another service which will improvise your programming skills.

      • Hüseyin Baduk

        Picasa is usable still

  • user00

    Hi Ravi

    We cant download source code. Download link is broken.

    • It’s working now. Pls check.

      • user00

        thanks

      • Jadu Kh

        can u pilz update ur tutorial for using flickr API since picasa is dying or.. intregation of googlr photo

  • Jadu Kh

    download not working… picasa is not working… pliz update code for using flickr

  • HI Ravi
    How to remove recent album menu? Its like Picasa not supported recent album now.
    Thks.

  • NewestList

    Hi Ravi

    We cant download source code. Download link is broken.

  • lokesh Kanchi

    hi ravi

    i just want code that only retrieve picasa images in to gridview ……….
    plz upload code for this

  • cindydeveloper

    hi Ravi
    How can i remove Profile Photos album in Google Photos?
    Thks

  • Vikas Kumar

    Picasa web albums is now depreciated it is not giving options to upload photos so what to do now

  • Alex

    picasso does not work, how to make a photo ??

  • Deepanshu Gupta

    part 2 link broken

  • Vinas Zadafiya

    duplicate entry: android/support/v4/print/PrintHelperKitkat$2.class

    Any Help Ravi

    • Digital Buddha

      Just delete the android.support.v4.jar…..you don’t need this anymore in the newest version of android studio

  • Human

    Hello Ravi, first of all thank you for this great tutorial, but I’ve got a problem with implementing my photos library since picasa is not available anymore. Could you suggest an alternative on how and where can we upload and retrieve an image database. Thank you again!