Passing the image to the default wallpaper Application through intent - android

We are trying to set the downloaded image (and stored inside galley under our own folder) as wallpaper using our application, and its working using the below code.
public void Set_Current_wallpaper() {
File f = new File(mCurrentWallpaperPath); // mCurrentWallpaperPath is Our folder inside gallery
Uri contentUri = Uri.fromFile(f);
Intent intent = new Intent(Intent.ACTION_ATTACH_DATA);
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.setDataAndType(contentUri, "image/*");
intent.putExtra("mimeType", "image/*");
startActivity(intent);
}
Problem is right now when above code is running below is how set wallpaper application screen looks like, But if we directly open the image from gallery and set as wallpaper, this is the wallpaper set screen looks like. Why is it opening in different way? Attaching the screens Actual vs Expected here.
Actual Result
Expected Result

Have you tried WallpaperManager?
WallpaperManager wallpapermgr = WallpaperManager.getInstance(this);
wallpapermgr.setBitmap(yourbitmap);

Related

Displaying Images in Gallery and sharing them

My application is capable of capturing images and saving them (in the public Pictures directory, retrieved by Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).
Now, I want to be able to display those images in the system's gallery application. In order to achieve that, I create an Intent like this (filePath is a String containing the image's path):
Intent viewIntent = new Intent();
viewIntent.setAction(Intent.ACTION_VIEW);
Uri uri = Uri.fromFile(new File(filePath));
viewIntent.setDataAndType(uri, "image/jpeg");
startActivity(Intent.createChooser(viewIntent, null));
Displaying an image this way works perfectly fine, but the gallery's Share functionality doesn't seem to work:
When I press the Share-button, I get to choose the app I want to share to; but once I select it, nothing happens, as if the target application does not receive any data.
Is there any explanation why this behaviour occurs and how it can be fixed?
Edit: I used Intent Intercept to capture the Intent created by the Gallery/Photos app:

android set home wallpaper using intent from drawable

I'm kind of new in android developing and i want to set home wallpaper with drawable image .
i wrote this code for setting but don't work and in visual android device at first i have dialog but next when i click as background i get this message :
"you need to insert sd card before using camera ..."
also i need use my drawable as source of images ...
here is my code :
Intent intent = new Intent(Intent.ACTION_ATTACH_DATA);
MimeTypeMap map = MimeTypeMap.getSingleton();
String mimeType = map.getMimeTypeFromExtension("jpg");
Uri uri = Uri.parse("#drawable/wall_7");
intent.setDataAndType(uri,"image/jpeg" );
intent.putExtra("mimeType", mimeType);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
this.startActivityForResult(Intent.createChooser(intent,"Set as"),200);
and i going to have a slidable wallpaper , not a fix image . i'm using this intent bcs it let user crop image .
First of all you need to add this permession to your manifest.xml
<uses-permission android:name="android.permission.SET_WALLPAPER" />
Then you can use this to set it using the wallpaperManager :
WallpaperManager wallpaperManager = WallpaperManager.getInstance(MyActivity.this);
Drawable drawable = getResources().getDrawable(R.drawable.wallpaper_img);
Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
wallpaperManager.setBitmap(bitmap);
Or you can use this
to set the wallpaper using intent
You can directly set background in your xml file using android:background tag.Let me know if you have any further queries.

Android Setting Wallpaper with service chooser

I am developing an application which have a lot of wallpapers in it.
I want to build a dialog that will appears when the user clicks on the images , and ask the user which service to use for setting wallpaper. (home screen, home and lock screen , whatsup , etc.)
I have found the solution by myself , here is my code ;
File f = new File(path); //
Uri picUri = Uri.fromFile(f);
Intent setAs = new Intent(Intent.ACTION_ATTACH_DATA);
setAs.setDataAndType(picUri, "image/*");
//setAs.putExtra(Intent.EXTRA_STREAM,picUri);
startActivityForResult(Intent.createChooser(setAs, "Set As"), 0);

Open image from drawable into gallery intent

I would like to open just one image and have pitch-zoom function, so (as I think) easiest way to do that is to open that image in gallery intent. Anybody can share example of how to call gallery intent with particular picture from drawable?
I tried to used something like that but can't make it working (wrong file patch?).
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse("com.me.example/drawable/thisimage.png"), "image/*");
startActivity(intent);
According to this post
You should do something like:
String uriStr = "android.resource://"+ "com.example.myapp"+ "/" + R.drawable.photo_h01;
Uri uri = Uri.parse(uriStr);
I have not Eclipse in front of me but that's what I have found on several sources

Android How to preview an image, using its file path from SDcard, from my application

File is present in sdcard/image.jpg
I would like to create my own application (activity).
On a button press, the image stored in the sdcard needs to be displayed using the built-in image viewer.
On pressing the back button from the Image viewer, it should go back to my running application.
Need some help.
you can create an Intent with proper uri and mimetype for this.Intent i = new Intent(Intent.ACTION_VIEW);
i.setDataAndType(Uri.parse("file:///sdcard/image.jpg"), "image/jpeg");
startActivity(i);
Intent photoPickerIntent = new Intent(Intent.ACTION_PICK);
photoPickerIntent.setType("image/*");
startActivityForResult(photoPickerIntent, 1);
This code use for display all images from your SD card

Categories

Resources