[英]set an image from gallery for background of desktop phone (android-java)
I have one app that like a Slide show or gallery but i want when anybody use this app be able to set the image to background on android phone 我有一个应用程序,如幻灯片放映或画廊,但我想当任何人使用此应用程序能够将图像设置为Android手机上的背景
the app can show image i just want to able set image to background - and its can be enough if i can set address of image in Variable and then i can use this Code 该应用程序可以显示图像我只想将图像设置为背景 - 如果我可以设置变量中的图像的地址,它就足够了然后我可以使用此代码
WallpaperManager wpm = WallpaperManager.getInstance(getApplicationContext());
try {
wpm.setResource(R.drawable.image_1);
} catch (IOException e) {
e.printStackTrace();
}
Here is a simple tutorial for it. 这是一个简单的教程。 visit this link And if you have imagePath then use following code as :-
访问此链接如果您有imagePath,请使用以下代码: -
is = new FileInputStream(new File(imagePath));
bis = new BufferedInputStream(is);
Bitmap bitmap = BitmapFactory.decodeStream(bis);
Bitmap useThisBitmap = Bitmap.createScaledBitmap(
bitmap, parent.getWidth(), parent.getHeight(), true);
bitmap.recycle();
if(imagePath!=null){
wallpaperManager = WallpaperManager.getInstance(this);
wallpaperDrawable = wallpaperManager.getDrawable();
wallpaperManager.setBitmap(useThisBitmap);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.