Java 设置可在android 4中滚动的墙纸
早上好 我有一个正确的代码,可以设置从网上下载的1024x768英寸jpg的壁纸 当我设置墙纸时,它会被分发到所有的家庭屏幕上,但从android 4+上看,它们是不可滚动的,会将图像的一部分固定在所有家庭屏幕上 我想解决这个问题,所以我希望你能帮助我 你好,对不起,英语Java 设置可在android 4中滚动的墙纸,java,android,eclipse,wallpaper,Java,Android,Eclipse,Wallpaper,早上好 我有一个正确的代码,可以设置从网上下载的1024x768英寸jpg的壁纸 当我设置墙纸时,它会被分发到所有的家庭屏幕上,但从android 4+上看,它们是不可滚动的,会将图像的一部分固定在所有家庭屏幕上 我想解决这个问题,所以我希望你能帮助我 你好,对不起,英语 //path is a String with image's url public int setWallpaper(String path) { int width, height; B
//path is a String with image's url
public int setWallpaper(String path) {
int width, height;
Bitmap dbm, bm;
bm = null;
dbm = null;
InputStream is = null;
WallpaperManager wpm = wallpaperManager.getInstance(this);
//all images are 1024x 768
//to scale bitmap the widht have to be 1.33 bigger than screen's height
if((wpm != null) && (dis != null)){
height = dis.getHeight();
width = (int) (height * 1.33);
try {
URLConnection conn = new URL(path).openConnection();
conn.connect();
is = conn.getInputStream();
if (is != null) {
bm = BitmapFactory.decodeStream(new FlushedInputStream(is));
dbm = Bitmap.createScaledBitmap(bm, width, height, false);
wpm.setBitmap(dbm);
}else {
return 2;
}
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} finally {
if (is != null) {
try {
is.close();
}
catch (IOException e) {
e.printStackTrace();
}
}
}
if(bm != null){
bm.recycle();
}
if(dbm != null){
dbm.recycle();
}
}else {
return 1;
}
return 0;
}
它们在android 4上不再可滚动,但是,为了避免它们被放大,您可以执行以下操作:
// get screen dimensions
DisplayMetrics displaymetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
int height = displaymetrics.heightPixels;
int width = displaymetrics.widthPixels;
wpm.suggestDesiredDimensions(width, height);
wpm.setBitmap(dbm);
通过使用suggestDesiredDimensions,您可以指定墙纸的大小
从开发者参考:
建议的公共无效维度(int最小宽度,int
最小高度)
自:API级别5仅由当前主应用程序使用,至
指定要使用的墙纸的大小。这就允许这样做
应用程序的虚拟墙纸要大于
物理屏幕,与工作区大小匹配
请注意开发人员,他们似乎没有读到这篇文章。这是回家的
屏幕显示他们想要什么尺寸的壁纸。没有其他人
应该叫这个!当然不是其他非主屏幕应用程序
换壁纸。这些应用程序应该能够检索
建议的尺寸,以便他们可以构建与之匹配的墙纸
请记住,您还需要通过以下操作请求清单上的“设置壁纸提示”权限:
<uses-permission android:name="android.permission.SET_WALLPAPER_HINTS"/>
它们在android 4上不再可滚动,但是,为了避免它们被放大,您可以执行以下操作:
// get screen dimensions
DisplayMetrics displaymetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
int height = displaymetrics.heightPixels;
int width = displaymetrics.widthPixels;
wpm.suggestDesiredDimensions(width, height);
wpm.setBitmap(dbm);
通过使用suggestDesiredDimensions,您可以指定墙纸的大小
从开发者参考:
建议的公共无效维度(int最小宽度,int
最小高度)
自:API级别5仅由当前主应用程序使用,至
指定要使用的墙纸的大小。这就允许这样做
应用程序的虚拟墙纸要大于
物理屏幕,与工作区大小匹配
请注意开发人员,他们似乎没有读到这篇文章。这是回家的
屏幕显示他们想要什么尺寸的壁纸。没有其他人
应该叫这个!当然不是其他非主屏幕应用程序
换壁纸。这些应用程序应该能够检索
建议的尺寸,以便他们可以构建与之匹配的墙纸
请记住,您还需要通过以下操作请求清单上的“设置壁纸提示”权限:
<uses-permission android:name="android.permission.SET_WALLPAPER_HINTS"/>
我正在寻找一种解决方案,将壁纸在所有家庭影院中共享。您的回复没有反映任何更改,壁纸继续使用图像的相同部分修复所有家庭影院。我正在寻找一种解决方案,将壁纸在所有家庭影院中共享。您的回复没有反映任何更改,壁纸将继续使用图像的同一部分固定到所有家庭屏幕上