<uses-permission android:name="android.permission.SET_WALLPAPER"/>
wallpaperManager =WallpaperManager.getInstance(this);
PendingIntent pi = PendingIntent.getService(this,0, new Intent("SERVICE_TO_SETWALL"), PendingIntent.FLAG_UPDATE_CURRENT);
AlarmManager alarmManager = (AlarmManager) getSystemService(Service.ALARM_SERVICE);
// 类型 ,执行延迟的时间,实行时间间隔,动作
alarmManager.setRepeating(alarmManager.RTC_WAKEUP, 0, 2000, pi);
import android.app.Service;
import android.app.WallpaperManager;
import android.content.Intent;
import android.os.IBinder;
/**
* 实现效果 -- 墙纸的切换 , 背景图片
* @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; // 资源索引
// 绑定服务
public IBinder onBind(Intent intent) {
return null;
}
// 创建服务
public void onCreate() {
super.onCreate();
wallpaperManager = WallpaperManager.getInstance(WallService.this); // 获取壁纸管理器对象
}
// 销毁服务
public void onDestroy() {
super.onDestroy();
}
/**
* 启动服务
* 每次启动开始获取资源
*/
public void onStart(Intent intent, int startId) {
super.onStart(intent, startId);
try{
if(index>=3){
index = 0;
}
wallpaperManager.setResource(res[index++]); // 设置资源
}catch(Exception ex){
ex.printStackTrace();
}
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有