Action Intent for Gmail in android? - android

I am creating an app in which user can share "something" by clicking on a share button.
The steps to share "something" are:
On clicking the share button the contact list should open
By selecting a contact (with valid a email address) the data should be sent directly to the selected contact from the sender's default email address(Gmail) without popping up a window for selecting an email client like "Gmail", "Dropbox" etc..
I managed to get the email id of contact with the help of
http://mobile.tutsplus.com/tutorials/android/android-essentials-using-the-contact-picker/
but after selecting a contact I get a pop up for selecting an email client like "Gmail", "Dropbox" etc..
here is my code so far
if( email.length() != 0 )
{
Intent sharingIntent = new Intent(
android.content.Intent.ACTION_SEND );
sharingIntent.setType("message/rfc822");
String shareBody =
"Hey buddy listen to this station it is awesome\n"
+ mNowPlayingSong.mAudioUrl;
sharingIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
"I liked this song" );
sharingIntent.putExtra(
android.content.Intent.EXTRA_TEXT, shareBody );
String emailAddressList[] = {email};
sharingIntent.putExtra(Intent.EXTRA_EMAIL, emailAddressList );
startActivity( sharingIntent );

You cannot send email silently with the default application. You can only create an intent that will call an activity and that will fill in all the fields.
Other possibility is to embed your own email client into yours application. In this case, if a user provides credentials then you'll have a possibility to send a email silently. To implement the second options check this:
Sending Email in Android using JavaMail API without using the default/built-in app

Related

How can I create chooser Intent to choose from gmail app, yahoo mail app or browser?

I tried to search on Google but didn't find an appropriate answer.
I want to click a TextView and it will show a dialog that allows the user to choose optional email.
Any suggestion? Thanks in advance
Try this:
Intent intet = new Intent(Intent.ACTION_SEND);
intet.setType("message/rfc822");
intet.putExtra(android.content.Intent.EXTRA_TEXT, body);
startActivity(intet);
This will open up a dialog that contains a list of apps installed on the device that can send an email.
Hope this helps. :)
A better option is to use the following, it will only open the applications that provide mail facility and not all apps that can share data.
Intent emailIntent = new Intent(Intent.ACTION_VIEW);
Uri data = Uri.parse("mailto:?subject=" + "subject" + "&body=" + "body" + "&to=" + email_id);
emailIntent.setData(data);
startActivity(emailIntent);
"subject" is the subject of mail, "body" is the content of the mail, and "email_id" is the id of the receiver of the mail.
You can keep the subject , body and email_id empty if you want the user to fill in the spaces.
for open gmail app
try this code:
Intent gmail = new Intent(Intent.ACTION_VIEW);
gmail.setClassName("com.google.android.gm","com.google.android.gm.ConversationListActivity");
startActivity(gmail);

How to find out a contact is a whatsapp user or not

I'm trying to find out whether a particular contact is a whatsapp user or not.
This goes my requirement:
I have a text to share and also have a phone number of a person as well. The priority of my sharing goes as follows
If the phone number is already present in CONTACTS and :
if the contact is a whatsapp user, I should call sharing intent of SEND with package set as "com.whatsapp"
i.e:
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.setPackage("com.whatsapp");
intent.putExtra(Intent.EXTRA_TEXT, message);
startActivity(intent);
if the contact not a whatsapp user, I should call intent for default messaging app.
i.e :
Intent intent = new Intent( Intent.ACTION_VIEW, Uri.parse( "sms:" + phoneNumber ) );
intent.putExtra( "sms_body", message );
startActivity(intent);
If the phone number is not present, create a contact and do as above.
My question now is, how do I find out whether my contact is a whatsapp user or not? Is whatsapp providing any API to find out that?
Thanks in advance
PS: I do not want to show a general sharing intent which shows a list of sharing apps. I may do that only if the device does not have whatsapp application at all.

show gmail screen directly... not thru selection

I am sort of new to android.
I am trying to send a msg via gmail and this is my code.
Intent intent = new Intent(Intent.ACTION_SENDTO);
String uriText;
uriText = "mailto:test#gmail.com?subject=Subject&body=this is test.";
uriText = uriText.replace(" ", "%20");
Uri uri = Uri.parse(uriText);
intent.setData(uri);
startActivity(Intent.createChooser(intent, "Select mailer"));
It works. But, before sending the msg, it shows a selection box
and asks me to choose either gmail or email.
How can I skip the selection box ?
Any help would be so appreciated.. Thanks.
How can I skip the selection box ?
You don't. You allow the user to choose what application they wish to use to send the message. Some users do not use Gmail.

Android: Get and Open Email and remove Bluetooth

i want to choice a app to send email:only email app to send my email,i have read How to open Email program via Intents (but only an Email program) i used intent.setType("message/rfc822") ,it very well,but Bluetooth and email give me to choice,i want to remove Bluetooth,and want to Leave only email.can you tell me how to send email not to show Bluetooth to give mo choice;
edit: if i used Intent intent = new Intent(Intent.ACTION_SENDTO); the bluetooth is remove but add Text messages t0 give me choice.i also used
Intent intent = new Intent(Intent.ACTION_VIEW);
Uri data = Uri.parse("mailto:?subject=" + subject + "&body=" + body);
intent.setData(data);
startActivity(intent);
the bluetooth also remove but also add add Text messages t0 give me choice.is there i way to only email app to send email?

Android: Send email through basic email app from another application in emulator?

I have a basic handler set up to call the email application in the emulator and send an email. I've set up the email app in the emulator with my info so it's ready to go. However, when I click the button in my app to bring up a compose window I get the prompt that says:
"No applications can perform this action"
Is this just something you can't do with the emulator?
private OnClickListener submitBtn = new OnClickListener(){
public void onClick(View v){
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
String emailTo = "test#test.com";
String emailSubject = "Subject";
String emailBody = "Some HTML goes here.";
emailIntent.setType("text/html");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,emailTo);
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,emailSubject);
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, Html.fromHtml(emailBody));
startActivity(Intent.createChooser(emailIntent, "Send email in:"));
}
};
Add
intent.setType( "message/rfc822" );
or
intent.setType( "text/html" );
This will cause Android to show a chooser to the user for all applications that can send these types of messages. The html option may put up non-email apps so I use the rfc822 option.
Try a third party app such as K9Mail http://code.google.com/p/k9mail/
The code looks fine, you're hitting some emulator limitations...
I was able to make it work in the emulator by configuring the basic email app with a valid email address.

Categories

Resources