I have a bitmap downloaded from a url and want to start android's default set as wallpaper intent/activity passing my bitmap. I have found following solution but missing value of "R.String.set_as" and "REQUEST_ID_SET_AS_WALLPAPER".
https://stackoverflow.com/a/26869604/4767525
what should be the value of this fields?
Thanks
Don't really know about REQUEST_ID_SET_AS_WALLPAPER. I think it is related to the size of the image.
R.String.set_as is just a string: "Set as:"
Use this code:
Intent intent = new Intent(Intent.ACTION_ATTACH_DATA);
intent.setDataAndType(contentUri, "image/*");
intent.putExtra("mimeType", "image/*");
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(Intent.createChooser(
intent, "Set as:"));
Related
Hi i have tried different ways to set my downloaded images from server as wallpaper using the native android intent in flutter but so far i am unable to implement it.
I have tried the intent package from pub.dev flutter but this code doesn't make my image pass through intent.
android_intent. Intent()
..setAction(android_action.Action.ATTACH_DATA)
..setData(outputFileUri)
//..putExtra(Extra.EXTRA_STREAM, outputFileUri)
..addFlag(1)
..setType('image/*')
..startActivity().catchError((e) => print(e));
Anyway to fix this would be really helpful. I am also sharing the functionality i want like in the image
t,
This should work for your situation:
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:"));
It's also independent of the image data type.
I want to access the dp (profile picture) option of whatsapp using android code I have used that code
Code
Intent intent = new Intent();
intent.setAction(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_STREAM,uri);
intent.setPackage("com.whatsapp");
intent.setType("image/*");
startActivity(intent);
but every time it open with share image option instead of change dp picture option in whatsapp i don't know where i am doing mistake I hope anyone here can help me. Thanks
guys i corrected question what actually i am asking
Finally after 1 day of exploring I came up with the Solution
Intent intent = new Intent(Intent.ACTION_ATTACH_DATA);
intent.setDataAndType(uri), "image/jpg");
intent.putExtra("mimeType", "image/jpg");
startActivityForResult(Intent.createChooser(intent, "Set image as"), 200);
With the help of this code snippet, you can set profile photo of Whatsapp as well as Contacts.
You can open Whatsapp or share image and video but can't change profile picture from your own app.
if(Build.VERSION.SDK_INT>=Build.VERSION_CODES.N)
{
uri=FileProvider.getUriForFile(getApplicationContext(),BuildConfig.APPLICATION_ID+".provider",new File(list.get(position)));
}else{
uri=Uri.parse(list.get(position));
}
Intent intent=new Intent(Intent.ACTION_ATTACH_DATA);
intent.setDataAndType(uri,"image/*");
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
intent.putExtra(Intent.EXTRA_STREAM,uri);
startActivity(intent);
I searched over the web during the last few weeks (seriously) but I can't find what I need. I just would like to start an intent corresponding to the set as action. It generally offers either Set as wallpaper or Set as contact picture. And then, if more application are installed on the device, they can be listed as well.
Here is an example of what I want :
I precise that I need to support API level 14 and higher.
I found getCropAndSetWallpaperIntent but it works only with content URI which is a problem for me, and is only availbable on API lvl 19 and higher.
I found the answer by my self :
Intent intent = new Intent(Intent.ACTION_ATTACH_DATA);
intent.setDataAndType(imageUri, "image/*");
intent.putExtra("jpg", "image/*");
startActivityForResult(Intent.createChooser(intent,
getString(R.string.set_as)), REQUEST_ID_SET_AS_WALLPAPER);
You just have to ensure that the uri is public and will be reachable by the crop application chosen by the user.
This solution worked for me with Uri:
Intent intent = new Intent(Intent.ACTION_ATTACH_DATA);
intent.setDataAndType(contentUri, "image/*");
intent.putExtra("mimeType", "image/*");
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
startActivity(Intent.createChooser(
intent, "Set as:"));
This worked for me :
Intent intent = new Intent(Intent.ACTION_ATTACH_DATA);
intent.addCategory(Intent.CATEGORY_DEFAULT);
//can't use normal URI, because it requires the Uri from file
intent.setDataAndType(Uri.fromFile(new File(uriOfImage)),"image/*");
intent.putExtra("mimeType","image/*");
startActivity(Intent.createChooser(intent,"Set Image"));
You can check that the URI that you pass, should contain the 'file://' prefix (It doesn't work without that).
The question was asked here and here but there was no real answer.
Android has a built-in "Set Wallpaper" feature, such feature is available when starting an activity intent with mime "image/jpeg" or long-tapping on images in browser.
My question is: how do I programmatically invoke the built-in "Set Wallpaper" feature using a file Uri?
Seems like there is no answer to the question however 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:"));
For me work only:
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:"));
If mime "image/jpeg" apps not found image.
If your app crashes after choosing the application you want to set wallpaper with, you need to add
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
A typical example is attachments in a email app. Access to the emails should be protected by permissions, since this is sensitive user data. However, if a URI to an image attachment is given to an image viewer, that image viewer no longer has permission to open the attachment since it has no reason to hold a permission to access all email.
The solution to this problem is per-URI permissions: when starting an activity or returning a result to an activity, the caller can set Intent.FLAG_GRANT_READ_URI_PERMISSION and/or Intent.FLAG_GRANT_WRITE_URI_PERMISSION. This grants the receiving activity permission access the specific data URI in the intent, regardless of whether it has any permission to access data in the content provider corresponding to the intent.
https://developer.android.com/guide/topics/permissions/overview
val intent = Intent(Intent.ACTION_ATTACH_DATA)
.apply {
addCategory(Intent.CATEGORY_DEFAULT)
setDataAndType(uri, "image/*")
putExtra("mimeType", "image/*")
addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
}
startActivity(Intent.createChooser(intent, "Set as:"))
And for me work only
Intent intent = new Intent();
intent.setAction(Intent.ACTION_ATTACH_DATA);
intent.addCategory(Intent.CATEGORY_DEFAULT);
intent.setDataAndType(ContactsContract.Contacts.CONTENT_URI, "image/*");
intent.putExtra("mimeType", "image/*");
startActivityForResult(Intent.createChooser(intent, "Select service:"), position);
position - it is your : getIntent().getExtras().getInt("id_test");
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