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
Related
I'm working wallpaper application and having a problem with set wallpaper intent. I'm tried FileProvider, nothing changed.
My code showing this intent:
(1) https://i.ibb.co/RcW15qb/1.png
after select:
(2) https://i.ibb.co/nsQNvms/Screenshot-1568305811.png
but I want like this:
(3) https://i.ibb.co/F53p6sv/Screenshot-1568305398.png
fun setWallpaper (uri:Uri) {
val intent = Intent(Intent.ACTION_ATTACH_DATA)
intent.addCategory(Intent.CATEGORY_DEFAULT)
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
intent.setDataAndType(uri, "image/*")
intent.putExtra("mimeType", "image/*")
startActivity(Intent.createChooser(intent, "Set as:"))}
I'm searched and tried smiliar set wallpaper intent example. Working but picture 1 and 2. I need intent like picture 3
Edit: I found but without scrolling and fixed options
val intent = Intent("android.service.wallpaper.CROP_AND_SET_WALLPAPER")
(4) https://i.ibb.co/H4vqdGF/Screenshot-1568315850.png
I am using the following code to open android gallery when an image is clicked in my app
Intent intent = new Intent (Intent.AUri.parse( "content://media/internal/images/media" ));
intent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY);
mActivity.startActivity(intent);
how can i modify my code to open a particular image directory or a particular image
According to me you should try this.
In your MainActivity introduce a method to create intend for that
and use syntax
intent.setComponent(new ComponentName("com.example.administrator.YOUR GALLERY APP NAME","com.example.administrator.YOUR APP.MainActivity"));
where com.example.administration is the initial name of your package
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.
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);
How can I use default Android gallery to display only application's photos? Basically I need to display only my application photos on gallery.
Many Thanks
Sure! You have to parametrize the Intent that is launching the Gallery Application: Set Action to Intent.ACTION_PICK. Set MIME type to one of the image types, or image/* . Set the data to the file to be shown's Uri.
Intent galleryStarter = new Intent();
galleryStarter.setAction(Intent.ACTION_PICK);
galleryStarter.setType("image/*");
galleryStarter.setData(Uri.fromFile(imageFileToShow));
context.startActivity(galleryStarter);