I want something like this.
NOT the UI, just the data. (The metadata of an image)
In Chrome or some other browser when I browse I get a grid or a list of pictures and when I long press on any image it shows "Share image" option. So when I click on "Share image."
I want my application (REQUIREMENTS)
to show up in the chooser dialog. (Working)
Retrieve info about the image (title, URL, thumbnail) (Not working)
I have done the opposite many times (Sharing some link from my application to another Application like Gmail, WhatsApp, etc).
My question is if it is even possible at all? I have seen many application doing that( You can see in the image ) and have no idea how do they do that.
Here is what I have done so far in terms of code.
Requirement 1 (Working)
I have an activity registered with android.intent.action.SEND intent filter in manifest. (Which makes my activity to appear in the list of Chooser dialog)
Here is the manifest
<intent-filter>
<action android:name="android.intent.action.SEND" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="*/*" />
</intent-filter>
Requirement 2 (NOT Working)
Here is the Activity code to retrieve the data.
public class MyActivity extends AppCompatActivity{
private TextView textView;
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.phot_save_layout);
textView = (TextView)findViewById(R.id.count);
takeValueFunc();
}
public void takeValueFunc()
{
Intent shareIntent = getIntent();
if(shareIntent.getAction().equals(Intent.ACTION_SEND))
{
String text = shareIntent.getStringExtra(Intent.EXTRA_TEXT);
}
}
}
I have done some digging with different browsers, and I read different values for the same image.
I have found a similar question on StackOverflow How to get params from android.intent.action.SEND
But it does not answer my question. :(
Now I want my application to... Retrieve info about the image (title, url, thumbnail)
That is not possible in general.
You are welcome to peruse through the documented extras for ACTION_SEND. You are welcome to come up with your own algorithm for deciding how to interpret those extras. However, there is no requirement that you get the information that you are seeking.
For example, EXTRA_STREAM may hold a Uri. That Uri should have a content scheme. That Uri, plus a ContentResolver, should give you the concrete MIME type (as the MIME type on the Intent may be a wildcard). If that is an image, you can use your favorite image-loading library to load the image into your thumbnail-sized visual representation.
But that's it.
Maybe EXTRA_TEXT and/or EXTRA_SUBJECT will hold other information you might use, but there is no requirement that, say, the HTTPS URL of the image be in either of those. After all, there may not be an HTTPS URL of the image, as the image may not be on the Internet. Similarly, the sending app may not have a "title", let alone send it as part of ACTION_SEND somehow.
Check this link to see how to receive data from other apps. However the example you have provided doesn't fit the scenario. WhatsApp is receiving only the link and generating preview by itself. If you want to do the same, you can use social metadata or similar service.
I'm not sure which data browser shares but you may analyze it, because it's all that you have.
To read all extras from intent:
Bundle extras = getIntent().getExtras();
for (String key : extras.keySet()) {
Log.d("Entry", String.format(Locale.US, "%s - %s", key, extras.get(key)));
}
Also there are open graph protocol to obtain web page preview so if browser shared the url then you may obtain meta info about this page(title, preview etc)
Info at provided screenshot obtained with opengraph.
http://ogp.me/ open graph site
Open graph debugger by facebook: https://developers.facebook.com/tools/debug/sharing/
NB: some social networks defined their protocols to describe page preview (eg Twitter cards)
Also I found this opengraph client for java: https://github.com/johndeverall/opengraph-java
** I think this code for working to share the detail in whatApp with Image.**
PackageManager pm = fragmentContext.getPackageManager();
try {
Intent waIntent = new Intent(Intent.ACTION_SEND);
waIntent.setType("text/plain");
if (Common.nonNull(bitmapUri))
waIntent.setType("image/*");
String text = invite.getInviteMessage();
PackageInfo info = pm.getPackageInfo("com.whatsapp", PackageManager.GET_META_DATA);
waIntent.setPackage(info.packageName);
waIntent.putExtra(Intent.EXTRA_TEXT, text);
waIntent.putExtra(Intent.EXTRA_STREAM, bitmapUri);
startActivity(Intent.createChooser(waIntent, "Share with"));
} catch (PackageManager.NameNotFoundException e) {
Toast.makeText(fragmentContext, "WhatsApp not Installed", Toast.LENGTH_SHORT)
.show();
}
The thing you want is Rich Link Preview Support. You can create your own dynamic links with rich preview support.
On the other hand, to receiving simple datas from other app to your own app can be done by adding intent filters to activity which represents that able to handle process in AndroidManifest.
Related
This is a silly and not important subject, but nothing to lose on asking.
My app has a "Share App" feature in main menu which sends a promotion email with text and a set of app screenshots, and in the end it calls the following method:
public static void shareFile(ArrayList<Uri> uris, String fileType)
{
try{
Intent share = new Intent(Intent.ACTION_SEND_MULTIPLE);
share.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
share.setType(fileType);
String strSubject = TMLocale.getStringResourceByName("mainmenu_sharethisapp_subject");
share.putExtra(Intent.EXTRA_SUBJECT, strSubject);
share.putExtra(Intent.EXTRA_TEXT, TMLocale.getStringResourceByName("mainmenu_sharethisapp_recommendtext"));
share.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
activity.get().startActivity(Intent.createChooser(share, TMLocale.getStringResourceByName("mainmenu_sharethisapp_shareapptitle")));
}
catch(Exception ex){
Toast.makeText(activity.get(), String.valueOf(ex.getMessage()),Toast.LENGTH_LONG).show();
}
}
This is working great, but what you receive -for example by mail- is an unordered set of attachments, I mean, the attachments order does not correspond to the ArrayList<Uri> order.
I'd like the attachments to be ordered as the ArrayList is, so who receives the email can see how the app works following the attachments (from Gmail -for example- and without downloading them) in a "readable"/"understandable" way, like following the same work sequence a user would follow using the app.
I have made several tests just to confirm attachments always arrive not only unordered, but in a different -maybe random- order.
Is it possible to sort the attachments?
I'd like the attachments to be ordered as the ArrayList is
Then use exactly one attachment, where you attach a document that puts your images in the desired order.
Otherwise... your code is starting an ACTION_SEND_MULTIPLE activity. There are likely thousands of these in the Play Store and elsewhere. How any of them handle your extras is up to their developers, not you or me.
I'm going to develop a simple app to list .jpg files and after a click call an Intent.ACTION_VIEW, below the code:
File imageFile = new File(filename);
Intent i = new Intent();
i.setAction(android.content.Intent.ACTION_VIEW);
i.setDataAndType(Uri.fromFile(imageFile), "image/jpeg");
startActivity(i);
The intent works properly, in fact in app I receive the message to select an app to show the selected image. But I noticed that after the choice, for example with Google Photos, not all function are enabled. For example the share function is not visible, has someone already noticed this behavior?
Some other details; if I choose Google Photos I only have the "Info" and "Guide and Feedback" options. If I choose gallery app (I have a Samsung Ace 3) I have only "Info" and "Set as wallpaper" options.
Note: if I open the same image directly from Google Photos all functions are enabled...
The ACTION_VIEW intent calls another application to view the content that you present, in your case a JPEG image. If there is more than on application that can handle that Intent, Android lets the user choose an app to display the image. Once the application receives the Intent, it is up to that application to display the content how it sees fit.
Basically, you have no control over what functions are available with Intent.ACTION_VIEW. If you want more control, you can create your own Activity in which you can view the image and provide whatever functions you would like.
The problem is I have an article that want to share to other apps, and I want to let the user to choose which app to share to. What I want to share is basically:
the title of the article
the URL of the article
the article content as HTML
the URL with some extra text (such as 'http://foo.com/article share from #FooApp')
All of these fields are optional, but I want to share at least one of them.
Such as when share via SMS or twitter, I want to set the content to part 4. when share via Facebook, I want to set 1, 2, 3 together. And when share via email, I want to set subject as 1 and message as 4.
I know (correct me if I'm wrong) every target intent receiver has it's own logic to pick up the fields it needed. So I want to provide as much information as possible and I wrote the following code:
String message = article.getURL() + " #FooApp";
Intent intent = new Intent().setData(Uri.parse(article.getURL())
.putExtra(Intent.EXTRA_SUBJECT, article.getTitle())
.putExtra(Intent.EXTRA_TEXT, message)
.putExtra(Intent.EXTRA_HTML_TEXT, article.getHTML())
.putExtra("sms_body", message)
...
.setType(HTTP.PLAIN_TEXT_TYPE);
startActivity(Intent.createChooser(intent, "Share to"));
But the problem is, it seems like a trick between setData, putExtra, setType.
For some apps appear in the chooser dialog, when I choose, the confirm share window (of that app) display nothing that I set to the intent. (for some other apps they just say failed to fetch resource)
For the putExtra part, when I add or remove some putExtra code, the target intent receivers diff a lot than I expected.
So the question is: am I doing it the wrong way? Are there some guideline for this problem?
I have an app. It's not an email app. But it has a feature similar to email, where a user may select to send an attachment along with a message. When I click to add attachment on my gmail, for example, I get the option to attach anything such as video, music, picture, file, etc. Has anyone ever build such an intent and unmarshalled the data and don't mind sharing their expertise?
edit
I am not able to get the multiple mime types in. I need the intent to be able to get video or image or music:
public void onGetAttachmentClicked(View view) {
Intent attachment = new Intent(Intent.ACTION_PICK);
attachment.setType("image/*,video/*,audio/*");
startActivityForResult(attachment, ATTACHMENT_REQUEST_CODE);
}
Right now it only launches the Photos or Gallery app. It does not load for audio, whereas the Gmail app attachment button does.
I think I got it, but I can't say 100% yet so I will reward #CommonsWare after testing
public void onGetAttachmentClicked(View view) {
Intent attachment = new Intent(Intent.ACTION_GET_CONTENT);
attachment.setType("*/*");
startActivityForResult(Intent.createChooser(attachment, "Pick Attachment"),
ATTACHMENT_REQUEST_CODE);
}
If you are trying to get content based on MIME type, use an ACTION_GET_CONTENT Intent with startActivityForResult(). The Uri delivered to your onActivityResult() method will point to the piece of content that the user chose.
I think you should simulate a html form(by assembling http header, parameters), and post your attachment to your server likes picking a file then submit the form
I'm writing an app that uses the camera. I want to lauch an intent to allow users to annotate the resulting image with lines and text, AND I would like to provide the user with a list of appropriate image editting apps they can use, but I'm coming across these problems:
1. Not all image editting apps appear in the list when I perform this code:
editIntent = new Intent();
editIntent.setAction(Intent.ACTION_EDIT);
Uri imageToEditUri = selectedPhotoLocation; // Uri of existing photo
String imageToEditMimeType = "image/*";
editIntent.setDataAndType(imageToEditUri, imageToEditMimeType);
startActivityForResult(Intent.createChooser(editIntent,"Edit Image"), IMPLICIT_EDIT_IMAGE);
Is there a way to get a list of apps that will respond to Intent.ACTION_EDIT?
2. PS Express is the only app I've found that returns the Uri of the editted image in the data.getDate() Uri returned to OnActivityResult(), with other apps the user is forced to save, remember the location, and reselect the editted image.
Is there a way to know what apps return the Uri of the image to OnActivityResult()
Not all image editting apps appear in the list when I perform this code
Just because an app implements image editing does not necessarily mean that it is set up to allow third parties to link to their image-editing activities.
Is there a way to get a list of apps that will respond to Intent.ACTION_EDIT?
If you mean that you want to do this programmatically at runtime, see Jedil's answer.
Is there a way to know what apps return the Uri of the image to OnActivityResult()
No, except for those applications that have documentation on how developers should integrate with them.
First question answer:
try queryIntentActivities
Intent editIntent = new Intent(android.content.Intent.ACTION_EDIT);
List<ResolveInfo> resInfo = getPackageManager().queryIntentActivities(editIntent, 0);