android p动态壁纸,android开发实现动态壁纸

释放双眼,带上耳机,听听看~!

代码中有用到两个接口

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

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值