Android Setting Wallpaper with service chooser - android

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);

Related

Set as wallpaper,lock screen by action attach data

welcome everyone
I'm trying writing a program to set the wallpaper, lock screen and contact picture etc from imageView by action attach data or any other way of doing the same.
Please see the pictures
image 1
image2
some code :
Intent setAs = new Intent(Intent.ACTION_ATTACH_DATA);
setAs.setDataAndType(uri,"image/jpg");
setAs.putExtra("mimeType", "image/jpg");
startActivity(Intent.createChooser(setAs, "Set Image As"));
When the application runs out show me the message :
no app can perform this action
I add permission in manifest file :
<uses-permission android:name="android.permission.SET_WALLPAPER"></uses-permission>
Thank you very much for your time
I found solution , The cause of the problem is ( URI ) it should be this way :
Intent setAs = new Intent(Intent.ACTION_ATTACH_DATA);
// i : integer variable (index of array contains my images )
setAs.setDataAndType(Uri.parse(new File("/storage/emulated/0/pictures/wall/wall.jpg").toString()), "image/*");
setAs.putExtra("mimeType", "image/*");
setAs.addCategory(Intent.CATEGORY_DEFAULT);
setAs.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(Intent.createChooser(setAs, "Set Image As"));
The above code does not set the image to the contacts .. I am continuing to try and if I find the solution I will put it here

Passing the image to the default wallpaper Application through intent

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);

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:

Displaying a specific folder of photos in the Android Gallery App

I'm looking to display a specific folder of images in an app so that the user can browse through them.
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse("content://sdcard/Pictures/Album"), "image/*");
startActivityForResult(intent, 0);
This seems to display all photos on the phone instead of the images I have in this album. How can I change this code so that the user can browse through images in a specific folder using the gallery app? The idea behind this is not so that the user can choose an image like I've seen in many examples on here but just simply to browse the images.
you can try this
File root = new File(Environment.getExternalStorageDirectory().getPath()
+ "/myFolder/");
Uri uri = Uri.fromFile(root);
Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setData(uri);
startActivityForResult(intent, 1);

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