Android get wallpaper name - android

I am developing an Android app for our company which sets the wallpaper to a specific company wallpaper every time the phone is booted. It would be preferable to check to see if the wallpaper has been changed rather than running the code to change the wallpaper.
Is there any way to get identifying information (e.g. filename etc.) from the current wallpaper?
WallpaperManager wallpaperManager = WallpaperManager.getInstance(context);
WallpaperInfo wallpaperInfo = wallpaperManager.getWallpaperInfo();
returns null for wallpaperInfo.
Code for wallpaper change:
public static void setWallpaper(Context context) {
// Has wallpaper changed?
if (/*--wallpaperNotChanged--*/) {
return;
}
try {
// Setup
Drawable drawable = context.getResources().getDrawable(R.drawable.test);
DisplayMetrics displayMetrics = new DisplayMetrics();
WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
WallpaperManager wallpaperManager = WallpaperManager.getInstance(context);
// Get display sizes
windowManager.getDefaultDisplay().getMetrics(displayMetrics);
// Create Bitmap
Bitmap unscaledWallpaper = BitmapFactory.decodeResource(context.getResources(), R.drawable.test);
Bitmap wallpaper = Bitmap.createScaledBitmap(unscaledWallpaper, displayMetrics.widthPixels, displayMetrics.heightPixels, true);
// Set wallpaper
wallpaperManager.setBitmap(wallpaper);
} catch (Exception e){
Toast.makeText(context, e.getMessage(), Toast.LENGTH_LONG).show();
}
}

Please read this get-current-wallpaper. And Get current wallpaper absolute path
final Drawable wallpaperManager = wallpaperManager.getDrawable();
For better info you can visit:
https://developer.android.com/reference/android/app/WallpaperInfo.html

WallpaperManager API Reference
public WallpaperInfo getWallpaperInfo ()
Here it says:
If the current wallpaper is a live wallpaper component, return the information about that wallpaper. Otherwise, if it is a
static image, simply return null.
You must be having a static image wallpaper in your background, not a live one.

Related

Home screen wallpaper gets zoomed when it goes to the background

I have scheduled background service to change device home screen wallpaper periodically. The wallpaper changes successfully and they are perfectly set to the screen size.
But when I move away from the home screen and return the image gets zoomed in too much,leaving only a portion of the image visible.Below given is the code I use
Bitmap theBitmap = null;
try {
DisplayMetrics metrics = new DisplayMetrics();
WindowManager windowManager = (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);
windowManager.getDefaultDisplay().getMetrics(metrics);
int height = metrics.heightPixels;
int width = metrics.widthPixels;
theBitmap = Glide.with(mContext)
.load(PhotoPath)
.asBitmap().into(width, height).get();
WallpaperManager wm = WallpaperManager.getInstance(mContext);
wm.setWallpaperOffsetSteps(1, 1);
wm.suggestDesiredDimensions(width, height);
try {
wm.setBitmap(theBitmap);Album
} catch (IOException e) {
}
} catch (InterruptedException e) {
e.printStackTrace();
} catch (ExecutionException e) {
e.printStackTrace();
}
}
Try not to rush and flag this question as a duplicate. There are questions stating the image appears zoomed in when set but My wallpaper gets set perfectly,atleast initially it does. Why does it zoom in when I move homescreen to the background.

Image gets zoomed while setting as wallpaper in my android application

I am trying to set my image as wallpaper but it gets zoomed/cropped when set as wallpaper. I have tried almost everything but nothing works.
Here is my piece of code:
public void setAswallpaper(Bitmap wallpaper)
{
WindowManager wm = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int width = size.x;
int height = size.y;
System.out.println("screen dimensions "+width+" "+height);
System.out.println("wallpaper dimensions "+wallpaper.getWidth()+" "+wallpaper.getHeight());
wallpaper = Bitmap.createScaledBitmap(wallpaper, width*2 , height, true);
try {
WallpaperManager wallpaperManager=WallpaperManager.getInstance(context);
wallpaperManager.suggestDesiredDimensions(width,height);
System.out.println("wallpaper manager dimensions "+wallpaperManager.getDesiredMinimumWidth()+" "+wallpaperManager.getDesiredMinimumHeight());
wallpaperManager.setBitmap(wallpaper); }
}
catch (IOException e)
{
e.printStackTrace();
Toast.makeText(context,
"Wallpaper Not Set",
Toast.LENGTH_SHORT).show();}
}
I need help so that I can set my complete image as wallpaper
My image size is : 640*960
bitmap size is : 1960*2880
screen dimensions : 1080*1960

Android SavePhoto Rotate Bitmap Prior to Save

I have an Android app which is capturing an image as a CameraPreview image.
Prior to capturing the image is appears on the Phone screen in Portrait mode (as needed).
But when I do a Save, the image goes to the JPG file rotated to Landscape mode.
I have confirmed this by going to MyFiles, finding the image and viewing it with Gallery - it pops up on-screen in Landscape mode.
Additionally when I upload the image files onto my computer they show up in Landscape mode there as well.
The image is correct, but the orientation is wrong.
The method that I am using to Save is as follows:
private boolean savePhoto(Bitmap bm) {
FileOutputStream image = null;
try {
image = new FileOutputStream(mLocation);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
bm.compress(CompressFormat.JPEG, 100, image);
if (bm != null) {
int h = bm.getHeight();
int w = bm.getWidth();
} else {
return false;
}
return true;
}
Can I insert code here or call a routine (if so what code is needed) that can rotate the image into the appropriate orientation prior to the actual Save?
Or is there some other manner to change the resultant JPG image orientation?
POST EDIT - I just now added the following code to examine the Saved JPG file.
ExifInterface exif = new ExifInterface(f.getPath());
int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, ExifInterface.ORIENTATION_NORMAL);
However it returned an Orientation = 0 which is not telling me that it 'thinks' that the JPG was Saved in Landscape orientation so that I might be able to use other posting's code.
Thanks

Android code to set wallpaper to phone screen size

I make use of the following code to set my static images as wallpaper from my android app.. The image dimensions are like 425*700, 280*180, 600*400 etc., so the image dimensions are not the same.
try {
WallpaperManager myWallpaperManager = WallpaperManager
.getInstance(context);
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
int fullWidth = size.x;
int fullHeight = size.y;
// int fullWidth = wManager.getDesiredMinimumWidth();
// int fullHeight = wManager.getDesiredMinimumHeight();
Log.d("Debug", Integer.toString(fullWidth));
Log.d("Debug", Integer.toString(fullHeight));
Bitmap bitmap = BitmapFactory.decodeStream(getResources()
.openRawResource(R.drawable.hello));
Bitmap bitmapResized = Bitmap.createScaledBitmap(bitmap, fullWidth,
fullHeight, true);
myWallpaperManager.suggestDesiredDimensions(
bitmapResized.getWidth(), bitmapResized.getHeight());
myWallpaperManager.setBitmap(bitmapResized);
} catch (IOException e) {
e.printStackTrace();
}
But the images are quite streched and doesn't look good after setting as a wallpaper in the phone.. What am I doing wrong?
I guess problem lies in the resources as you have already mentioned. For a good view/quality of wallpaper we have to use different resources of images as according to the resolution of your device, if you want to use your application of setting the wallpaper to be used by many devices without making any changes(an apk). The crux is, you need a better quality image matching the resolution of your device. Hope it helps.
Edit: The distortion is again because you are resizing your image for covering full screen size. I guess if you do not resize it, it might work, though I havent use it till now.

GestureImageView goes blank when trying to set bitmap from camera programatically

I am using:
https://github.com/jasonpolites/gesture-imageview
on load of the app, it has a placeholder image in a GestureImageView that pinch/zooms appropriately. I have a button that when clicks fires a camera intent, saves the file, and then I wish to set that image to be the source bitmap used in the gestureimageview.
GestureImageView imageView = (GestureImageView) findViewById(R.id.imageViewOne);
ContentResolver cr = getContentResolver();
getContentResolver().notifyChange(imageUriOne, null);
try {
Bitmap mybitmap = android.provider.MediaStore.Images.Media.getBitmap(cr, imageUriOne);
imageView.setImageBitmap(mybitmap);
}
For a normal imageview, that works. But for the GestureImageView, the image stays as the original once returned from the camera intent, and if touched disappears.
To check it's not the bitmap that's the problem, I tried
int idTwo=getResources().getIdentifier("com.jazz.test1:drawable/second_photo", null, null);
imageView.setImageResource(idTwo);
I.e. set the imageview to an existing resource, but this has the same problem.
If I call that setImageResource code before the intent, it does work.
Any ideas how to debug? There are no errors in the logs.
Resolution is here:
https://github.com/jasonpolites/gesture-imageview/issues/21
hadn't noticed it when I initially looked at the github issues.
You have to replace your initMethod function. With this code it will work properly (GestureImageView.java file in com.polites.android package).
protected void initImage() {
if (this.drawable != null) {
this.drawable.setAlpha(alpha);
this.drawable.setFilterBitmap(true);
if (colorFilter != null) {
this.drawable.setColorFilter(colorFilter);
}
// Keppel.Cao
layout = false;
startingScale = -1.0f;
}
if (!layout) {
requestLayout();
// Keppel.Cao
// redraw();
reset();
}
}
Like Dave said. More you can find here Issue 21

Categories

Resources