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.
Related
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.
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
When I am Using this code to send mms to specific user it shows me popup to send it via gmail,whatsapp,gtalk,message and etc. But in my case I just want to send that image as an mms to specific number that i will define in address field whithout showing any popup can any body tell me How to do this ? I googled for this and find lot of stuff on it.
Here is my code*strong text*
public void sendData(int num){
String fileString = "..."; //put the location of the file here
Intent mmsIntent = new Intent(Intent.ACTION_SEND);
mmsIntent.putExtra("sms_body", "text");
mmsIntent.putExtra("address", num);
mmsIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(new File(fileString)));
msIntent.setType("image/jpeg");
startActivity(Intent.createChooser(mmsIntent, "Send"));
}
Using an intent (like you did) is the preferred way because it's easy to implement and let the user choose his favorite app for the task of sending the MMS.
That being said you can still implement yourself the operation and send the MMS programmatically from your app by crafting and sending the appropriate HTTP request.
The following answer will provide you all the information you need: How to send image via MMS in Android?
I'm developing a very small application for Android 2.3.3.
I want to send an email (through the android email app) containing a jpeg image as an attachment, below the relevat code (tested only with sdk emulator):
public void sendArtwork(View aView){
EditText subj = (EditText)findViewById(R.id.edit_subj);
EditText descr = (EditText)findViewById(R.id.edit_descr);
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setType("image/jpeg"); // attachment is a jpeg
emailIntent.putExtra(Intent.EXTRA_EMAIL,new String[]{"contribute#unintentional.org"});
emailIntent.putExtra(Intent.EXTRA_SUBJECT,subj.getText().toString()); //get subject from one EditText in the UI
emailIntent.putExtra(Intent.EXTRA_TEXT,descr.getText().toString()); //get body from one EditText in the UI
emailIntent.putExtra(Intent.EXTRA_STREAM, fileURI); // add attachment
startActivityForResult(Intent.createChooser(emailIntent, "Choose Email application:"), EMAIL_CODE);
}
It works as expected: it opens a Chooser, creates an email with the correct address, subject, text and attachment and sends it.
The only thing I'm not able to accomplish is to set the correct mime type for the image: the attachment is received correctly (i can detach it to disk and open it) but without a content type, so the email client (Thunderbird) does not display a preview and is not able to provide an application to open it.
Does anybody have advice on this?
----EDIT
The image file is sent across without any errors: as said, if I save it on disk on my PC and open it using a suitable application (i.e. Picasa) it shows up correctly.
I'm using the same method for sending emails, and have tested on various versions of a few email clients.
Even gmail is inconsitent, some versions sets the mime type of the attachment, others ignore it.
I've came to the conclusion that there is no safe solution. At least not by using an ACTION_SEND Intent.