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

Android 中WallpaperManager用法實(shí)例

 更新時(shí)間:2017年09月01日 11:29:23   投稿:lqh  
這篇文章主要介紹了Android 中WallpaperManager用法實(shí)例的相關(guān)資料,希望通過本文能幫助到大家實(shí)現(xiàn)這樣的功能,需要的朋友可以參考下

Android 中WallpaperManager用法實(shí)例

注意:壁紙的設(shè)置得加入權(quán)限:

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

1、WallpaperManager  對(duì)象的獲得:

wallpaperManager =WallpaperManager.getInstance(this); 

2、設(shè)置壁紙的方法:

方法一:wallpaperManager.setBitmap(); // 參數(shù)
方法二:wallpaperManager.setResource();  // 參數(shù)為資源ID
方法三:通過ContextWrapper 類中的setWallpaper();  方法 // 參數(shù)為一個(gè)輸入流

3、定時(shí)更換壁紙:

使用 AlarmManager 系統(tǒng)定時(shí)服務(wù)

PendingIntent pi = PendingIntent.getService(this,0, new Intent("SERVICE_TO_SETWALL"), PendingIntent.FLAG_UPDATE_CURRENT); 

AlarmManager alarmManager = (AlarmManager) getSystemService(Service.ALARM_SERVICE); 
// 類型 ,執(zhí)行延遲的時(shí)間,實(shí)行時(shí)間間隔,動(dòng)作 
alarmManager.setRepeating(alarmManager.RTC_WAKEUP, 0, 2000, pi); 

下列為一個(gè)服務(wù)用來設(shè)置墻紙:


import android.app.Service; 
import android.app.WallpaperManager; 
import android.content.Intent; 
import android.os.IBinder; 
 
 
/** 
 * 實(shí)現(xiàn)效果 -- 墻紙的切換 , 背景圖片 
 * @author Administrator 
 * 
 */ 
public class WallService extends Service { 
 
  private int[] res = new int[]{R.drawable.a,R.drawable.b,R.drawable.c}; // 切換圖片資源 
  private WallpaperManager wallpaperManager; //墻紙管理器 
  private int index; // 資源索引 
 
  // 綁定服務(wù) 
  public IBinder onBind(Intent intent) { 
 
    return null; 
  } 
 
  // 創(chuàng)建服務(wù) 
  public void onCreate() { 
    super.onCreate(); 
    wallpaperManager = WallpaperManager.getInstance(WallService.this); // 獲取壁紙管理器對(duì)象 
  } 
 
  // 銷毀服務(wù) 
  public void onDestroy() { 
    super.onDestroy(); 
     
  } 
 
  /** 
   * 啟動(dòng)服務(wù) 
   * 每次啟動(dòng)開始獲取資源 
   */ 
  public void onStart(Intent intent, int startId) { 
    super.onStart(intent, startId); 
    try{ 
      if(index>=3){ 
        index = 0; 
      } 
      wallpaperManager.setResource(res[index++]); // 設(shè)置資源 
    }catch(Exception ex){ 
      ex.printStackTrace(); 
    } 
  } 
} 

以上就是Android  WallpaperManager的實(shí)例,如有疑問請(qǐng)留言或者到本站社區(qū)交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對(duì)本站的支持!

相關(guān)文章

最新評(píng)論