如何使用系统默认操作设置壁纸

时间:2013-08-19 07:04:59

标签: android crop wallpaper

  

我必须通过调用默认系统操作将sdcard中的图像设置为壁纸。

1 个答案:

答案 0 :(得分:0)

File file = new File(Environment.getExternalStorageDirectory(), "your_image.jpg");
String path = file.getAbsolutePath();
File imageFile = new File(path);

if(imageFile.exists()) {
    Bitmap bitmap = BitmapFactory.decodeFile(path);

    WallpaperManager mWallpaperManager = WallpaperManager.getInstance(this);

    try {
        mWallpaperManager.setBitmap(bitmap);
    } catch (IOException e) {
        e.printStackTrace();
    }
} 

Menifest.xml

中添加以下权限
<uses-permission android:name="android.permission.SET_WALLPAPER" />

启动裁剪活动的代码:

Intent intent = new Intent("com.android.camera.action.CROP", myIntent.getData());
if (myIntent.getStringExtra("mimeType") != null) {
   intent.setDataAndType(myIntent.getData(), myIntent.getStringExtra("mimeType"));
}
intent.putExtra("crop", "true");
intent.putExtra("aspectX", 1);
intent.putExtra("aspectY", 1);
intent.putExtra("outputX", 96);
intent.putExtra("outputY", 96);
intent.putExtra("return-data", true);
startActivityForResult(intent, REQUEST_CROP_PHOTO);