I am having a problem with android email intent.....i need to open email app so that the user can provide feedback for my app.It doesn't open when i use this..throws an ActivityNotFoundException .....i am using my phone ,not an emulator and my phone has email and gmail apps in it.
Help me solve??
Here is my code:
Intent intent= new Intent(Intent.ACTION_SENDTO);
intent.setData(Uri.parse("mailto:"));
intent.setType("text/plain");
String[] mail={"someone#gmail.com"};
intent.putExtra(Intent.EXTRA_SUBJECT,"");
intent.putExtra(Intent.EXTRA_TEXT,"");
intent.putExtra(Intent.EXTRA_EMAIL,mail);
startActivity(intent);
Any and all comments are appreciated :)
For your case, what ActivityNotFoundException most likely means that in your phone you don't have any default email app email application installed on your device like Gmail, so when you launch the Intent you receive this error.
You can try to handle that exception like this:
try {
startActivity(Intent.createChooser(i, "Send mail"));
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(Activity.this, "no email app",Toast.LENGTH_SHORT).show();
}
From the android docs, An intent allows you to start an activity in another app by describing a simple action you'd like to perform (such as "view a map" or "take a picture") in an Intent object. This type of intent is called an implicit intent because it does not specify the app component to start, but instead specifies an action and provides some data with which to perform the action.
When you call startActivity() or startActivityForResult() and pass it an implicit intent, the system resolves the intent to an app that can handle the intent and starts its corresponding Activity. If there's more than one app that can handle the intent, the system presents the user with a dialog to pick which app to use.`
So, in your case, the system couldn't find an app to resolve the intent to as #Tamir mentioned.
For more information , look into this Stack Overflow post: Send Email Intent
it works for me :
String[] recipients;
Intent intent = new Intent(Intent.ACTION_SEND);
recipients = new String[]{"someone#gmail.com"};
intent.putExtra(Intent.EXTRA_EMAIL, recipients);
intent.setType("text/html");
intent.setPackage("com.google.android.gm");
try {
activity.startActivity(Intent.createChooser(intent, "Send"));
}
catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(Activity.this, "no email app",Toast.LENGTH_SHORT).show();
}
Related
When a user clicks a button in my app, it's supposed to launch an SMS app. To to this, I simply fired an intent.
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.fromParts("sms", "+234000000000", null));
intent.putExtra("sms_body", "Hello!"));
if (intent.resolveActivity(getActivity().getPackageManager()) != null) startActivity(intent);
This works perfectly fine! The only problem is that Facebook Messenger is among the list of apps that show up and I don't want that.
How can I filter this list and remove specific apps like Messenger?
Yes, you can restrict your app to open just android default messaging app.
Uri uri = Uri.parse("sms:+444498494984");
Intent intent = new Intent(Intent.ACTION_SENDTO, uri);
//android sms app package name
intent.setPackage("com.google.android.apps.messaging");
intent.putExtra("sms_body", "message to send");
if (intent.resolveActivity(getPackageManager()) != null)
{
startActivity(intent);
}
It is trying to give the user a choice on their favourite SMS app, Don't forget that Facebook Messenger can also manage SMS now that is why it is showing up as a choice. In my experience, Unless the user selects 'always' it can't be avoided. Imagine if the user has other apps to manage SMS we can't force them to use our preferred messaging app.
I am unable to disable mailto and subject section when the intent comes on email section, but I need this two section fixed from my programming part. For an example
Intent emailIntent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(
"mailto","abc#gmail.com", null));
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
startActivity(Intent.createChooser(emailIntent, "Send email..."));
Here I want mail will be send only "abc#gmail.com" and user will not be able to edit this thing or not to put another email id. Same case for subject also.
Is this possible? Please suggest me.
I don't think that would be possible as you are just launching a third party application which your application have no control over. If you want to implement that feature in your app then you should use an SMTP library to send an email without user intervention.
This article might help you.
Try below code to send the email via intent in android device.
String data = "EMAIL MESSAGE";
Intent intentSendMail = new Intent(Intent.ACTION_SEND);
intentSendMail.setData(Uri.parse("mailto:"));
intentSendMail.setType("message/rfc822");
intentSendMail.putExtra(Intent.EXTRA_EMAIL, new String[] { "abc#gmail.com" });
intentSendMail.putExtra(Intent.EXTRA_SUBJECT, "Subject");
intentSendMail.putExtra(Intent.EXTRA_TEXT, "");
startActivity(Intent.createChooser(intentSendMail, "Send email..."));
NOTE:
This is only worked when you have installed at-least 1 mail client LIKE "EMAIL" or "GMAIL" in your device.
This will not worked in the simulator try with real device.
public void shareMessage(){
final Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_TEXT, text);
getContext().startActivity(Intent.createChooser(intent, "Share"));
}
When I use "text/plain", Facebook comes up as an option but the text does not load up when selecting it. But the text does load for Twitter,email, SMS.
Has anyone else encountered this problem?
As mentioned in the comments , Facebook has disabled the share intent a few years back Android and Facebook share intent , it doesn't handle EXTRA_SUBJECT or EXTRA_TEXT fields,
Use the Facebook api , Instructions found here --> https://developers.facebook.com/docs/android/share#share_options
is it possible to take the user to Settings -> Location using intent, so he would be able to enable the app go get the device location?
This is the screen I want to go to:
Try this:
Intent intent= new Intent(android.provider.Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(intent);
Like if i want to redirect the user to Location service i have to use
Intent intent = new Intent(
Settings.ACTION_LOCATION_SOURCE_SETTINGS);
startActivity(intent);
Now what shoulb the ACTION_ to let the user go to the data usage settings where he can enable the Mobile Data Traffic?
Are you sure you aren't looking for:
final Intent dataUsage = new Intent(Intent.ACTION_MAIN);
dataUsage.setClassName("com.android.settings",
"com.android.settings.Settings$DataUsageSummaryActivity");
startActivity(dataUsage);
Your title suggests that's what you want, but your comment suggests you wanted the network operator settings.