The following code will help you create an application to install WallPaper.
package com.example.SetWallpaper;
import java.io.IOException;
import android.app.Activity;
import android.app.WallpaperManager;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
public class SetWallpaper extends Activity {
Bitmap bitmap;
int lastImageRef;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button buttonSetWallpaper = (Button)findViewById(R.id.set);
ImageView imagePreview = (ImageView)findViewById(R.id.preview);
imagePreview.setImageResource(R.drawable.five);
buttonSetWallpaper.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View arg0) {
WallpaperManager myWallpaperManager
= WallpaperManager.getInstance(getApplicationContext());
try {
myWallpaperManager.setResource(R.drawable.five);
} catch (IOException e) {
e.printStackTrace();
}
}});
}
}
In the manifest file, add the following permission
<uses-permission android:name="android.permission.SET_WALLPAPER">
layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button
android:id="@+id/set"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/btn" />
<ImageView
android:id="@+id/preview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:contentDescription="@string/hello_world" />
</LinearLayout>
More details: http://www.edumobile.org/android/android-beginner-tutorials/setting-an-image-as-a-wallpaper/
source
share