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

android 設(shè)置wallpaper的操作方法

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

1、調(diào)用系統(tǒng)的Intent.ACTION_ATTACH_DATA,該Intent會喚起所有的設(shè)置壁紙程序以及設(shè)置聯(lián)系人頭像程序,用戶可以通過ChooseActivity進(jìn)行選擇:

該Intent是一個標(biāo)準(zhǔn)Intent,因此所有設(shè)置都會支持

 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設(shè)置

該方法可以直接將圖片置為壁紙,對于所有平臺的Android系統(tǒng)都使用,但無法裁剪/調(diào)整圖片。

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中需要申明權(quán)限:

<uses-permission android:name = "android.permission.SET_WALLPAPER"/>

以上這篇android 設(shè)置wallpaper的操作方法就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論