Set Image as wallpaper using Intent - android

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>

Related

Set as Wallpaper intent dialog?

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

Set wallpaper without wallpaper manager, call default set as methods

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

Can't share attached image from local folder into marshmallow and more version?

Can't attached image in Facebook and other social service and also set XML file
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:name="android.permission.READ_EXTERNAL_STORAGE"
java file
Uri imageUri = Uri.parse("/sdcard/fildername" + images29.png);
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("image/png");
intent.putExtra(Intent.EXTRA_STREAM, imageUri);
startActivity(Intent.createChooser(intent , "Share"));
You have to write like below.
Uri imageUri = Uri.fromFile("/sdcard/fildername" + images29.png);
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("image/png");
intent.putExtra(Intent.EXTRA_STREAM, imageUri);
startActivity(Intent.createChooser(intent , "Share"));

implement set as picture button in my app

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

How to use bitmap to send to another app

can someone help me how to send an image to another application in android?
I want to send an image to be used as wallpaper, BBM display picture, and other applications that can use it (like WhatsApp, contacts, etc.)
I use this code, but it can only be used for sending text and not images as I want
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT, "This is my text to send.");
sendIntent.setType("text/plain");
startActivity(sendIntent);
Then I tried to use this code to set the wallpaper
public void setAsWallpaper(Bitmap bitmap) {
try {
WallpaperManager wm = WallpaperManager.getInstance(_context);
wm.setBitmap(bitmap);
//disinimas
Toast.makeText(_context,
_context.getString(R.string.toast_wallpaper_set),
Toast.LENGTH_SHORT).show();
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(_context,
_context.getString(R.string.toast_wallpaper_set_failed),
Toast.LENGTH_SHORT).show();
}
}
the problem with the code, bitmap images directly applied as wallpaper. I wanted like sending text above, the user can choose to use another application. So I want a bitmap image that can later be used for wallpaper, BBM display picture, or other applications that support it
bitmap variable already contains the image that I want to, the images obtained from the internet with this code:
Bitmap bitmap = ((BitmapDrawable) fullImageView.getDrawable())
.getBitmap();
I use this code and its work, but give me a message BBM: File not found, WhatsApp: File is not an image:
Bitmap icon = bitmap;
Intent share = new Intent(Intent.ACTION_ATTACH_DATA);
share.setType("image/jpeg");
ContentValues values = new ContentValues();
values.put(Images.Media.TITLE, "title");
values.put(Images.Media.MIME_TYPE, "image/jpeg");
Uri uri = getContentResolver().insert(Media.EXTERNAL_CONTENT_URI,
values);
OutputStream outstream;
try {
outstream = getContentResolver().openOutputStream(uri);
icon.compress(Bitmap.CompressFormat.JPEG, 100, outstream);
outstream.close();
} catch (Exception e) {
System.err.println(e.toString());
}
share.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(share, "Share Image"));
Thanks for your help Antrromet, finally I solved my problem with the following code:
Bitmap icon = bitmap;
// Intent share = new Intent(Intent.ACTION_SEND);
// share.setType("image/*");
ContentValues values = new ContentValues();
values.put(Images.Media.TITLE, "title");
values.put(Images.Media.MIME_TYPE, "image/*");
Uri uri = getContentResolver().insert(Media.EXTERNAL_CONTENT_URI,
values);
OutputStream outstream;
try {
outstream = getContentResolver().openOutputStream(uri);
icon.compress(Bitmap.CompressFormat.JPEG, 100, outstream);
outstream.close();
} catch (Exception e) {
System.err.println(e.toString());
}
Intent intent = new Intent(Intent.ACTION_ATTACH_DATA);
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.setDataAndType(uri, "image/*");
intent.putExtra("mimeType", "image/*");
this.startActivity(Intent.createChooser(intent, "Set as:"));
Now the image can be used as Wallpaper, BBM profile picture, WA display Picture, Coontact display picture, etc. Thanks
Did you try using the following code? It is use to send binary data to other apps.
Intent shareIntent = new Intent();
shareIntent.setAction(Intent.ACTION_SEND);
shareIntent.putExtra(Intent.EXTRA_STREAM, uriToImage);
shareIntent.setType("image/jpeg");
startActivity(Intent.createChooser(shareIntent, getResources().getText(R.string.send_to)));
Or if you dont have the URI with you but have the Bitmap instead, then try using the code as given here.
UPDATE:
Setting wallpaper and profile picture for BBM are totally different things and there is no common intent for them. For setting the wallpaper, you can try the following as given here.
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:"));
For BBM, the APIs are not open for changing the user image. So you cannot do that through your app.

Categories

Resources