android 自定义桌面

阅读更多
1、 把背景图片push到SDCard中

  adb push MM-320x480。png /sdcard/

  确认是否已经存在了,可以到SDCard看一下:

  adb shell

  cd sdcard

  ls

public static final String TAG = "WallpaperActivity";
/** * 背景图片名称 */
private static final String FILE_NAME = "MM-320x480.png";
/** * @see android.app.Activity#onCreate(android.os.Bundle) */
public void onCreate(Bundle cycle) {
super.onCreate(cycle);
super.setContentView(R.layout.wallpaper);
// 取得背景图片
Bitmap wallpaper = this.getWallpager();
// 设置桌面背景
this.putWallpaper(wallpaper);
}
/** * 取得SDCard中的背景图片 */
private Bitmap getWallpager() {
// SDCard的路径,也就是“/sdcard/”
File root = Environment.getExternalStorageDirectory();
// MM图片
File wall = new File(root, FILE_NAME);
// MM图片路径
String path = wall.getAbsolutePath();
Log.d(TAG, "文件路径为:" + path);
return BitmapFactory.decodeFile(path);
}
/** * 设置桌面背景 */
private void putWallpaper(Bitmap bitmap) {
try {
WallpaperManager wallpaperManager = WallpaperManager.getInstance(this); wallpaperManager.setBitmap(bitmap);
} catch (IOException e) {
String msg = "设置桌面背景发生异常:" + e.getLocalizedMessage();
Log.e(TAG, "设置桌面背景发生异常!", e);
Toast.makeText(this, msg, Toast.LENGTH_LONG).show();
}[size=x-large]


[/size]
转自:http://www.eoeandroid.com/thread-101982-1-1.html

你可能感兴趣的:(android 自定义桌面)