I am trying multiple solutions but all are requiring user interaction to set the live wallpaper (I don't want user interaction), where I want to set it automatically only on first run of application means right after installation not always on opening the app which is done through keeping record in preference.
I used following code to make it happen but it is requiring user interaction.
SharedPreferences p = PreferenceManager
.getDefaultSharedPreferences(this);
boolean firstRun = p.getBoolean(PREFERENCE_FIRST_RUN, true);
if (firstRun) {
p.edit().putBoolean(PREFERENCE_FIRST_RUN, false).commit();
try {
Intent intent = new Intent(
WallpaperManager.ACTION_CHANGE_LIVE_WALLPAPER);
ComponentName component = new ComponentName(this,
MyWallpaperService.class);
intent.putExtra(
WallpaperManager.EXTRA_LIVE_WALLPAPER_COMPONENT,
component);
startActivityForResult(intent, 0);
} catch (Exception e) {
Toast.makeText(this, "Error setting wallpaper",
Toast.LENGTH_SHORT).show();
}
}
Please guide me if there is any way of doing this, thanks