i am trying to call default wallpaper set as method but its not working
i have tried so many code over stack but its not working so please any one have solution for it please reply
Uri uri = Uri.parse(url.toString());
Intent intent = new Intent(Intent.ACTION_ATTACH_DATA);
intent.setDataAndType(uri, "image/jpg");
intent.putExtra("mimeType", "image/jpg");
startActivityForResult(Intent.createChooser(intent, "Set As"), 200);
Can u try the below code:
Intent intent = new Intent(Intent.ACTION_ATTACH_DATA);
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.setDataAndType(uri, "image/jpeg");
intent.putExtra("mimeType", "image/jpeg");
this.startActivity(Intent.createChooser(intent, "Set as:"));
Related
I am trying to create my own wallpaper app and I can't figure out how to start this intent?
What is this intent? How do I pass image to device default wallpaper app?
Try following code snippet:
Intent intent = new Intent(Intent.ACTION_ATTACH_DATA);
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);//add this if your targetVersion is more than Android 7.0+
intent.setDataAndType(uri, "image/jpeg");
intent.putExtra("mimeType", "image/jpeg");
this.startActivity(Intent.createChooser(intent, "Set as:"));
PS:uri should get from FileProvider in Android 7.0+ if your targetVersion is more than7.0+
You could try this:
private void startWallpaper(){
final Intent pickWallpaper = new Intent(Intent.ACTION_SET_WALLPAPER);
Intent chooser = Intent.createChooser(pickWallpaper,"set wallpaeper");
startActivity(chooser);
}
ref is here
In your manifest file:
<uses-permission android:name="android.permission.SET_WALLPAPER"></uses-permission>
If you want to pass own img, could do like below:
WallpaperManager wpm = WallpaperManager.getInstance(context);
InputStream ins = new URL("absolute/path/of/image").openStream();
wpm.setStream(ins);
I am using the following code to set the wallpaper from an image in a drawable:
Intent setAsIntent = new Intent();
setAsIntent.setDataAndType(uri, "image/*");
setAsIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
setAsIntent.setAction("android.intent.action.ATTACH_DATA");
Intent chooserIntent = Intent.createChooser(
setAsIntent, "set as");
But when startActivity, it only shows a message:
No apps can perform this action
I did discover a workaround:
Intent intent = new Intent(Intent.ACTION_ATTACH_DATA);
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.setDataAndType(uri, "image/jpeg");
intent.putExtra("mimeType", "image/jpeg");
this.startActivity(Intent.createChooser(intent, "Set as:"));
or try to use
WallpaperManager
wallpaperManager = WallpaperManager.getInstance(this);
wallpaperDrawable = wallpaperManager.getDrawable();
mImageView.setImageURI(imagepath);
If you have image bitmap then use this
wallpaperManager.setBitmap(useThisBitmap);
In your manifest file:
<uses-permission android:name="android.permission.SET_WALLPAPER"></uses-permission>
I have Android Xamarin application with imageview
OnClik I lunch intent to preview image
File file = new File(photoPath);
Intent intent = new Intent(Intent.ActionView);
intent.SetDataAndType(Uri.FromFile(file), "image/*");
intent.SetFlags(ActivityFlags.NoHistory);
StartActivity(intent);
from apps I choose 'Gallery'
when the image is opend there are no sharing options
when I open image from device 'Gallery' has sharing options
Image is saved to SD card before preview.
what am I doing wrong ?
solution that worked for me
Intent intent = new Intent();
intent.PutExtra(Intent.ActionView, photoPath);
intent.SetType("image/*");
StartActivity(Intent.CreateChooser(intent, "Select Picture"));
now I get my image opend in gallery and I can use sharing options too
Do it using Intent.ACTION_SEND and you'll get that sharing option.
Also try with Intent.ACTION_GET_CONTENT.
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent,
"Select Picture"), 1);
What I wanna do:
I wanna get the path as a String of a file, which I choose via an Android File Manager.
What I have:
Intent intent = new Intent(Intent.ACTION_GET_CONTENT);
intent.setType("*/*");
startActivityForResult(Intent.createChooser(intent, "Open with ..."), FILE_SELECT_CODE);
This code, works nearly fine for me, but there is one problem. I can only select my file with the following apps:
My Question:
Does anyone have a working code for choosing any file via the Android File Manager?
You can use this:
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
intent.setType("*/*");
startActivityForResult(intent, REQUEST_CODE);
For samsung devices to open file manager use this:
Intent intent = new Intent("com.sec.android.app.myfiles.PICK_DATA");
intent.putExtra("CONTENT_TYPE", "*/*");
intent.addCategory(Intent.CATEGORY_DEFAULT);
For more reference checkout http://developer.android.com/guide/topics/providers/document-provider.html
So for my Samsung device this worked:
Intent intent = new Intent("com.sec.android.app.myfiles.PICK_DATA");
intent.putExtra("CONTENT_TYPE", "*/*");
intent.addCategory(Intent.CATEGORY_DEFAULT);
startActivityForResult(intent, FILE_SELECT_CODE);
I displayed images from webservice using json. Now how to provide user to make image as profile picture for whatsapp or contact photo etc., How to call that intent to open set picture as -> Set as -> showing multiple options -> Contact photo wallpaper, whatsapp profile photo etc.,?
Intent intent = new Intent(Intent.ACTION_ATTACH_DATA);
intent.setDataAndType(Uri.parse(filename.getAbsolutePath()), "image/*");
intent.putExtra("jpg", "image/*");
startActivity(Intent.createChooser(intent, ("set as")));
use this code.
File externalFile=new File("filePath")
Uri sendUri = Uri.fromFile(externalFile)
Intent intent = new Intent(Intent.ACTION_ATTACH_DATA);
intent.setDataAndType(sendUri, "image/jpg");
intent.putExtra("mimeType", "image/jpg");
startActivityForResult(Intent.createChooser(intent, "Set As"), 200);