当前位置: 移动技术网 > IT编程>移动开发>Android > android动态壁纸调用的简单实例

android动态壁纸调用的简单实例

2019年07月24日  | 移动技术网IT编程  | 我要评论

湖北男子还不起房贷跳楼,解放轻卡,两泽千晶

调用后动态壁纸其实是显示在activity的后面,而activity则是透明显示,这样就可以看到下面的动态壁纸,如果activity不是透明的则什么也看不到。

代码中有用到两个接口

iwallpaperservice mservice;

iwallpaperengine mengine;

我们可以看到该目录下面有三个aidl接口,分别是

复制代码 代码如下:

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();

}

定义壁纸管理和壁纸信息变量

复制代码 代码如下:

private wallpapermanager mwallpapermanager = null;

private wallpaperinfo mwallpaperinfo = null;

private wallpaperconnection mwallpaperconnection = null;

private intent mwallpaperintent;

初始化这些变量

复制代码 代码如下:

mwallpapermanager = wallpapermanager.getinstance(this);

mwallpaperinfo = mwallpapermanager.getwallpaperinfo();//如果返回null则说明当前不是动态壁纸

mwallpaperintent = new intent(wallpaperservice.service_interface);

mwallpaperintent.setclassname(mwallpaperinfo.getpackagename(), mwallpaperinfo.getservicename());

绑定动态壁纸服务

复制代码 代码如下:

bindservice(mintent, this, context.bind_auto_create);

iwallpaperservice mservice;//这里有一个adil接口

在连接监听中试着attach

复制代码 代码如下:

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的时候发现总是失败,后来发现是权限问题,只有拥有系统权限的apk才可以使用wallpaperservice.service_interface服务,所以问题就变成了怎么获取系统权限。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网