Android Wallpaper Manager is merging images - android

I have developed an android app in which I have implemented a background service using AlarmManager, which executes after every 20 seconds and change the home screen wallpaper of device, its working fine. But, there is an issue which is very frequent, the android Wallpapermanager mix up 2 images (one is device default wallpaper) and start showing the combination of 2 images on my home screen. if home screen wallpaper is set as scrolling wallpaper. you can see in attached image, which is very annoying. I have tried to fix this up, by increase service execution delay but all in vain. Will you please suggest me a suitable solution for this. here is my code
final WallpaperManager myWallpaperManager = WallpaperManager.getInstance(getApplicationContext());
Bitmap bm = null;
File imgFile = new File(imageURL);
if(imgFile.exists()){
bm = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
}
if(bm == null) return;
try {
myWallpaperManager.setBitmap(bm);
bm.recycle();
} catch (IOException e) {
e.printStackTrace();
}

Related

The most efficient way to show the local image in android

I am currently work on a magazine like apps. Since there is an option to zoom in(150%, 200%, 250% of original source) , I would prefer not to scale down the image. However , the app will force restart when I try to decode the image because of the out of memory. Are there any suggestion to fix that?
The image are local (SD card) , can be retrieve in any approach, but eventually need to be a bitmap as I use something like cavans.drawbitmap to display it. I tried, input stream-> bytes , input stream->bitmap etc... but are there any most efficient way or at least
I can sure the app does not force restart / close? Thanks
try {
InputStream is = (InputStream) new URL(url).getContent();
try {
return BitmapFactory.decodeStream(is);
} finally {
is.close();
}
} catch (Exception e) {
return BitmapFactory.decodeResource(context.getResources(), defaultDrawable);
}
You should consider using nostra's image loader, it deals with memory quite efficiently, you can specify lots of config stuffs, im using it and its working pretty well for large images aswell
This is what smartImageView(by loopj - you can find him on http://loopj.com/) uses to retrieve files from the drive/sd.
private Bitmap getBitmapFromDisk(String imgID) {
Bitmap bitmap = null;
if(diskCacheEnabled){
String filePath = getFilePath(imgID);
File file = new File(filePath);
if(file.exists()) {
bitmap = BitmapFactory.decodeFile(filePath);
}
}
return bitmap;
}

Set local photo as wallpaper on Android

I use below code to set photo as wallpaper:
try {
File f = new File(PhotoPath);
InputStream in = new FileInputStream(f);
this.setWallpaper(in);
} catch (IOException e) {
e.printStackTrace();
}
For some photo, it can set as wallpaper success.
But for some photo, the wallpaper will be set to device default wallpaper or all black.
Is there any limitation of the photo which be set to wallpaper?
Or this code how to modify to fix issue?
Try this method from this link : developer.
public void setStream (InputStream data);
Currently image must be either a JPEG or PNG. This method supports from API Level 5.

Android ImageButton setImageBitmap goes on the wrong element

I have a situation with three image buttons:
Take a photo by the camera
Delete the photo
Show a cropped2fit version of the image taken
I'm using the camera of the phone.
My problem is that SOMETIMES, apparently without no explanation, when I set the photo with setImageBitmap, it goes on the wrong imageButton (seems to be always the delete button, but I'm not really sure). Rebooting the device seems to solve the problem.
The code is as simple as it should be: I use findViewById casting the object into an ImageButton and setting the image with setImageBitmap.
ImageView iv = ((ImageView) findViewById(R.id.imgFotoPrima));
iv.setImageBitmap(fn.setupImage(data, PrimaOutputFileUri));
iv.setScaleType(ScaleType.CENTER_CROP);
public static Bitmap setupImage(Intent data, Uri outputFileUri) {
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 2; // SAMPLE_SIZE = 2
Bitmap tempBitmap = null;
Bitmap bm = null;
try {
tempBitmap = (Bitmap) data.getExtras().get("data");
bm = tempBitmap;
Log.v("ManageImage-hero", "the data.getData seems to be valid");
FileOutputStream out = new FileOutputStream(outputFileUri.getPath());
tempBitmap.compress(Bitmap.CompressFormat.JPEG, 100, out);
}
catch (NullPointerException ex) {
Log.v("ManageImage-other", "another phone type");
bm = otherImageProcessing(options, outputFileUri);
}
catch (Exception e) {
Log.e("ManageImage-setupImage", "problem setting up the image", e);
}
return bm;
}
The elements in the xml have different id.
I've tried the application on a Lenovo (7') and a Galaxy Tab 7 II.
It seems to happen only on the Galaxy Tab.
Could it be a problem on the tablet?? Anyone in my situation?

Fb profile pic not coming with a better quality

I have used the following code, able to get the image but when I am trying to put it on Layout background(Linear Layout), the image quality gets reduced and it shows a blurred image.
URL img_value = null;
try {
img_value = new URL("http://graph.facebook.com/"+userId+"/picture?type=large");
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Bitmap mIcon1 = null;
try {
BitmapFactory.Options opt=new BitmapFactory.Options();
opt.inSampleSize=1;
// mIcon1 = BitmapFactory.decodeFile(pathoffile,opt);
mIcon1 = BitmapFactory.decodeStream(img_value.openConnection().getInputStream(),null,opt);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
ll=(LinearLayout) findViewById(R.id.ll);
BitmapDrawable background = new BitmapDrawable(mIcon1);
ll.setBackgroundDrawable(background);
It looks like you're trying to set that image to the background of a LinearLayout. I am going to assume that this background is roughly the size of the phone's screen.
I just tried out that facebook URL and the size of the image I am getting back is 180x195.
Considering the smallest Android screen I am aware of is 240x320, that image will have to be blown up on every single Android phone. This will cause the image to look blurry, as the resolution of the image is much lower than that of Android screens.
I recommend you find higher resolution images for your backgrounds.

using android intent to call and receive a result from camera app no matter if it is custom built

here is the problem: i have searched for an answer for this and so far i made it work for the custom camera app that comes with htc phones.
i have the folowing
protected void onActivityResult(int requestCode, int resultCode, Intent data){
if (requestCode == REQUEST_FROM_CAMERA && resultCode == RESULT_OK) {
InputStream is=null;
File file=mInterface.getTempFile();
try {
is=new FileInputStream(file);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
if(is==null){
try {
u = data.getData();
is=getContentResolver().openInputStream(u);
mInterface.saveStringPreferences(GlobalInterface.URI_SAVENAME, u.toString());
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
//Now "is" stream contains the required photo, you can process it
setImage(is);
}
//and this is the code to the function that calls the intent:
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
// intent.putExtra(MediaStore.EXTRA_OUTPUT,Uri.fromFile(mInterface.getTempFile()));
startActivityForResult(intent, REQUEST_FROM_CAMERA);
the remaining functions getTempFile() is to create a temp file on /sdcard/blabla.tmp
and a function to set the captured image in an image view.
so the problem is that i tested this code on the custom camera on a lg phone and it crashes. the question is: is there a way to get an uri for the image location (i dont need a specific save location it could be the default set from the camera) and there were also some issues i came across which i dont need to solve like getting a smaller resolution image. i just need one image and to be able to set it in an imageView and the method to work for every camera app that is there, custom or native regardless.
is this possible or i need to create a new camera class for this? in my opinion the camera apps that come with the phone are more adjusted to the phone model so i would prefer using them against building a custom one.
tnx.
Try this:
Bitmap thumbnail = (Bitmap) data.getExtras().get("data");
Source

Categories

Resources