1、調用系統(tǒng)的Intent.ACTION_ATTACH_DATA,該Intent會喚起所有的設置壁紙程序以及設置聯(lián)系人頭像程序,用戶可以通過ChooseActivity進行選擇:
該Intent是一個標準Intent,因此所有設置都會支持
Intent intent = new Intent(Intent.ACTION_ATTACH_DATA); intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); intent.putExtra("mimeType", "image/*"); Uri uri = Uri.parse(MediaStore.Images.Media .insertImage(getActivity().getContentResolver(), ((BitmapDrawable) wallpaper).getBitmap(), null, null)); intent.setData(uri); startActivityForResult(intent, SET_WALLPAPER);2、通過WallpaperManager設置
該方法可以直接將圖片置為壁紙,對于所有平臺的Android系統(tǒng)都使用,但無法裁剪/調整圖片。
try { WallpaperManager wpm = (WallpaperManager) getActivity().getSystemService( Context.WALLPAPER_SERVICE); if (wallpaper != null) { wpm.setBitmap(bitmap); Log.i("xzy", "wallpaper not null"); }} catch (IOException e) { Log.e(TAG, "Failed to set wallpaper: " + e);}AndroidManifest.xml中需要申明權限:
<uses-permission android:name = "android.permission.SET_WALLPAPER"/>
以上這篇android 設置wallpaper的操作方法就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持VEVB武林網(wǎng)。
新聞熱點
疑難解答
圖片精選