android 2.0设置壁纸的问题

Vyphn 2010-08-04 11:08:32
在2.0中设置桌面壁纸

if(bp != null){
try {
long t1 = System.currentTimeMillis();
WallpaperManager.getInstance(ctx).setBitmap(bp);
long t2 = System.currentTimeMillis();
Log.i("aaaaa","execute time:"+(t2-t1)/1000.0+" seconds");
} catch (IOException e) {
e.printStackTrace();
}
}



if(bp != null){
try {
long t1 = System.currentTimeMillis();
G.getBaseInstance.setWallpaper(bp);
long t2 = System.currentTimeMillis();
Log.i("aaaaa","execute time:"+(t2-t1)/1000.0+" seconds");
} catch (IOException e) {
e.printStackTrace();
}
}


这两个API来设置桌面壁纸,执行的时间竟然要3至5秒....

有人遇到这个问题吗?请高手解答
...全文
459 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
倒影jw 2011-10-20
  • 打赏
  • 举报
回复
同意楼上的
Vyphn 2010-08-09
  • 打赏
  • 举报
回复
[Quote=引用 14 楼 liujinrui 的回复:]

Java code

public void setStream(InputStream data) throws IOException {
try {
ParcelFileDescriptor fd = sGlobals.mService.setWallpaper(null);
if (fd == null) {
……
[/Quote]

嗯,用setStream明显快了很多
liujinrui 2010-08-07
  • 打赏
  • 举报
回复

public void setStream(InputStream data) throws IOException {
try {
ParcelFileDescriptor fd = sGlobals.mService.setWallpaper(null);
if (fd == null) {
return;
}
FileOutputStream fos = null;
try {
fos = new ParcelFileDescriptor.AutoCloseOutputStream(fd);
setWallpaper(data, fos);
} finally {
if (fos != null) {
fos.close();
}
}
} catch (RemoteException e) {
}
}



你可以试试调用WallpaperManager.setStream,直接设置流,看速度会不会有提升。
liujinrui 2010-08-07
  • 打赏
  • 举报
回复
晕,我搞错了。 2.0之前的好像也是rpc的,只不过没有WallpaperManager和WallpaperManagerService这两个类。
使用Bitmap,应该是压缩bitmap的时候耗时多了。
<code>
public void setBitmap(Bitmap bitmap) throws IOException {
try {
ParcelFileDescriptor fd = sGlobals.mService.setWallpaper(null);
if (fd == null) {
return;
}
FileOutputStream fos = null;
try {
fos = new ParcelFileDescriptor.AutoCloseOutputStream(fd);
bitmap.compress(Bitmap.CompressFormat.PNG, 90, fos);
} finally {
if (fos != null) {
fos.close();
}
}
} catch (RemoteException e) {
}
}
</code>
liujinrui 2010-08-07
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 vyphn 的回复:]
但是我同样的图片,在android 1.6下设置壁纸却很快。。。

引用 7 楼 programmerno1 的回复:

加载时间,跟图片大小也有关系。。
[/Quote]

有可能,因为在2.0之前setWallpaper是在applicationcontext里直接调用的,没有使用ipc;而在2.0之后添加了WallpaperManagerService这个远程调用,可能会耗时多一些。
xy240865163 2010-08-07
  • 打赏
  • 举报
回复
个人觉得可能是图片大小问题
Vyphn 2010-08-06
  • 打赏
  • 举报
回复
顶一下。。。有人碰到这个问题吗?
Vyphn 2010-08-05
  • 打赏
  • 举报
回复
但是我同样的图片,在android 1.6下设置壁纸却很快。。。
[Quote=引用 7 楼 programmerno1 的回复:]

加载时间,跟图片大小也有关系。。
[/Quote]
ProgrammerNO1 2010-08-05
  • 打赏
  • 举报
回复
加载时间,跟图片大小也有关系。。
Vyphn 2010-08-05
  • 打赏
  • 举报
回复
我的bitmap是外部图片,不过在setwallpaper之前已经转换成bitmap了。。
按照你的说法,有没有方法缩短这个时间呢?
[Quote=引用 5 楼 liujinrui 的回复:]

设置内置的墙纸不需要这么长时间,如果是其他图片,需要访问WallpaperManagerService,保存替换掉wallpaper这个文件,然后通知Launcher,确实时间挺长的。特别是图片比较大的时候。
[/Quote]
liujinrui 2010-08-05
  • 打赏
  • 举报
回复
设置内置的墙纸不需要这么长时间,如果是其他图片,需要访问WallpaperManagerService,保存替换掉wallpaper这个文件,然后通知Launcher,确实时间挺长的。特别是图片比较大的时候。
SmallHero007 2010-08-05
  • 打赏
  • 举报
回复
08-05 01:48:01.452: INFO/aaaaa(262): execute time:0.166 seconds
我测试的结果,楼主是不是还进行了其他操作吧?换个墙纸不应该要那么长时间的。
Vyphn 2010-08-05
  • 打赏
  • 举报
回复
试验结果是2者叠加。。。8.8秒。。。
[Quote=引用 2 楼 jindan_jinming 的回复:]

不错的实验!
可以再实验下:
long t1 = System.currentTimeMillis();
WallpaperManager.getInstance(ctx).setBitmap(bp);
G.getBaseInstance.setWallpaper(bp);
long t2 =……
[/Quote]
  • 打赏
  • 举报
回复
不错的实验!
可以再实验下:
long t1 = System.currentTimeMillis();
WallpaperManager.getInstance(ctx).setBitmap(bp);
G.getBaseInstance.setWallpaper(bp);
long t2 = System.currentTimeMillis();
Log.i("aaaaa","execute time:"+(t2-t1)/1000.0+" seconds");
看看时间是不是2者的叠加!
FrankBIBI 2010-08-05
  • 打赏
  • 举报
回复
饿~那我也去测试下 我的1.5版本的时间 呵呵~

80,360

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧