欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

android 設置wallpaper的操作方法

 更新時間:2017年08月21日 07:56:16   投稿:jingxian  
下面小編就為大家?guī)硪黄猘ndroid 設置wallpaper的操作方法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧

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的操作方法就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關文章

最新評論