我有一项服务,我正在使用它来更改 android 壁纸。我将图像路径传递给服务,然后使用以下代码将图像设置为墙纸:
@Override
public void run() {
try {
final String imagePath[] = mSelectedImgPath.split(",");
while (true) {
for (int i = 0; i < imagePath.length; i++) {
bitmap = BitmapFactory.decodeFile(imagePath[i]);
this.setWallpaper(bitmap);
Thread.sleep(1000 * time);
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
我收到以下错误:
01-25 15:59:12.410: E/AndroidRuntime(1702): FATAL EXCEPTION: Thread-149
01-25 15:59:12.410: E/AndroidRuntime(1702): java.lang.OutOfMemoryError
01-25 15:59:12.410: E/AndroidRuntime(1702): at android.graphics.BitmapFactory.nativeDecodeStream(Native Method)
01-25 15:59:12.410: E/AndroidRuntime(1702): at android.graphics.BitmapFactory.decodeStream(BitmapFactory.java:493)
01-25 15:59:12.410: E/AndroidRuntime(1702): at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:299)
01-25 15:59:12.410: E/AndroidRuntime(1702): at android.graphics.BitmapFactory.decodeFile(BitmapFactory.java:324)
01-25 15:59:12.410: E/AndroidRuntime(1702): at com.wallpaper.demo.WallpaperChangeService.run(WallpaperChangeService.java:55)
01-25 15:59:12.410: E/AndroidRuntime(1702): at java.lang.Thread.run(Thread.java:856)
谢谢