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

android動(dòng)態(tài)壁紙調(diào)用的簡(jiǎn)單實(shí)例

 更新時(shí)間:2013年06月04日 10:28:04   作者:  
動(dòng)態(tài)壁紙的實(shí)現(xiàn)其實(shí)就是在Activity中調(diào)用動(dòng)態(tài)壁紙服務(wù),通過綁定服務(wù)得到IWallpaperService,調(diào)用該接口中的attach函數(shù)實(shí)現(xiàn)壁紙的調(diào)用。

調(diào)用后動(dòng)態(tài)壁紙其實(shí)是顯示在Activity的后面,而Activity則是透明顯示,這樣就可以看到下面的動(dòng)態(tài)壁紙,如果Activity不是透明的則什么也看不到。

代碼中有用到兩個(gè)接口

IWallpaperService mService;

IWallpaperEngine mEngine;

我們可以看到該目錄下面有三個(gè)aidl接口,分別是

復(fù)制代碼 代碼如下:

interface IWallpaperConnection {

    void attachEngine(IWallpaperEngine engine);

    ParcelFileDescriptor setWallpaper(String name);

}

oneway interface IWallpaperService {

    void attach(IWallpaperConnection connection,

            IBinder windowToken, int windowType, boolean isPreview,

            int reqWidth, int reqHeight);

}


oneway interface IWallpaperEngine {

    void setDesiredSize(int width, int height);

    void setVisibility(boolean visible);

    void dispatchPointer(in MotionEvent event);

    void dispatchWallpaperCommand(String action, int x, int y,            int z, in Bundle extras);

    void destroy();

}

定義壁紙管理和壁紙信息變量

復(fù)制代碼 代碼如下:

private WallpaperManager mWallpaperManager = null;

private WallpaperInfo mWallpaperInfo = null;

private WallpaperConnection mWallpaperConnection = null;

private Intent mWallpaperIntent;

初始化這些變量

復(fù)制代碼 代碼如下:

mWallpaperManager = WallpaperManager.getInstance(this);

mWallpaperInfo = mWallpaperManager.getWallpaperInfo();//如果返回null則說明當(dāng)前不是動(dòng)態(tài)壁紙

mWallpaperIntent = new Intent(WallpaperService.SERVICE_INTERFACE);

mWallpaperIntent.setClassName(mWallpaperInfo.getPackageName(), mWallpaperInfo.getServiceName());

綁定動(dòng)態(tài)壁紙服務(wù)

復(fù)制代碼 代碼如下:

bindService(mIntent, this, Context.BIND_AUTO_CREATE);

IWallpaperService mService;//這里有一個(gè)adil接口

在連接監(jiān)聽中試著attach

復(fù)制代碼 代碼如下:

public void onServiceConnected(ComponentName name, IBinder service) {

                mService = IWallpaperService.Stub.asInterface(service);

                try {

                    mService.attach(this, view.getWindowToken(),

                    //        WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA_OVERLAY,
                            WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA,

                                  true, root.getWidth(), root.getHeight());

                } catch (RemoteException e) {

                    Log.w("", "Failed attaching wallpaper; clearing", e);
                }
        }


在bindService的時(shí)候發(fā)現(xiàn)總是失敗,后來發(fā)現(xiàn)是權(quán)限問題,只有擁有系統(tǒng)權(quán)限的apk才可以使用WallpaperService.SERVICE_INTERFACE服務(wù),所以問題就變成了怎么獲取系統(tǒng)權(quán)限。

相關(guān)文章

  • Android編程實(shí)現(xiàn)長(zhǎng)按彈出選項(xiàng)框View進(jìn)行操作的方法

    Android編程實(shí)現(xiàn)長(zhǎng)按彈出選項(xiàng)框View進(jìn)行操作的方法

    這篇文章主要介紹了Android編程實(shí)現(xiàn)長(zhǎng)按彈出選項(xiàng)框View進(jìn)行操作的方法,結(jié)合實(shí)例形式分析了Android事件響應(yīng)及彈窗的功能、布局相關(guān)操作技巧,需要的朋友可以參考下
    2017-06-06
  • Android CountDownTimer案例總結(jié)

    Android CountDownTimer案例總結(jié)

    這篇文章主要介紹了Android CountDownTimer案例總結(jié),本篇文章通過簡(jiǎn)要的案例,講解了該項(xiàng)技術(shù)的了解與使用,以下就是詳細(xì)內(nèi)容,需要的朋友可以參考下
    2021-08-08
  • 利用Android 防止系統(tǒng)字體變化、顯示大小變化影響

    利用Android 防止系統(tǒng)字體變化、顯示大小變化影響

    這篇文章主要介紹了利用Android 防止系統(tǒng)字體變化、顯示大小變化影響方法的相關(guān)資料,需要的朋友可以參考下面文章的具體內(nèi)容,希望對(duì)你有所幫助
    2021-10-10
  • android使用gesturedetector手勢(shì)識(shí)別示例分享

    android使用gesturedetector手勢(shì)識(shí)別示例分享

    這篇文章主要介紹了android使用手勢(shì)識(shí)別的方法,介紹了單擊觸摸屏觸發(fā)的事件和雙擊事件的使用等方法,大家參考使用吧
    2014-01-01
  • Android仿京東分類模塊左側(cè)分類條目效果

    Android仿京東分類模塊左側(cè)分類條目效果

    這篇文章主要為大家詳細(xì)介紹了Android仿京東分類模塊左側(cè)分類條目效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2018-02-02
  • 自定義TextView跑馬燈效果可控制啟動(dòng)/停止/速度/焦點(diǎn)

    自定義TextView跑馬燈效果可控制啟動(dòng)/停止/速度/焦點(diǎn)

    Android自帶的跑馬燈效果不太好控制,不能控制速度,不能即時(shí)停止和啟動(dòng),而且還受焦點(diǎn)的影響蛋疼不已。由于項(xiàng)目需求需所以自己寫了一個(gè)自定義的TextView,感興趣的朋友可以了解下
    2013-01-01
  • 最新評(píng)論