After starting an email intent how can I get confirmation that the email has sent or there has been an error back into the activity it was called from?
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setType("png/image");
String subject = "Email Subject";
String body = "Message Body";
emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
emailIntent.putExtra(Intent.EXTRA_TEXT, body);
emailIntent.putExtra(Intent.EXTRA_STREAM,
Uri.parse("file:///sdcard/" + IMAGE_FILENAME));
startActivity(Intent.createChooser(emailIntent, "Send email..."));
//Here I need to do something on a successfully sent email
Maybe start activityForResult? But what result should I expect back if any?
That really depends on the app that is launched by your Intent. It could be the Gmail app, it could be the Email app, or it could be any third-party app. Because of this, there is no 100% reliable way to determine whether the user actually pressed Send or not.
The only thing you can do is check if the Gmail and Email apps return anything relevant when called via startActivityForResult and rely on that. But beware that is not reliable because, again, there could be third party apps. Also, since these apps do not specify publicly what they return, they might change that at some point without any notice.
you cannot get any useful resultcode from an email intent. onActivityResult always return 0 as soon as sending starts or sending is canceled.
Additionaly if you attach files, onActivityResult is called BEFORE those files are read.
You can NOT do this.
ACTION_SEND does NOT have any output as a result you always get the default value which is RESULT_CANCELED.
Also you can NOT check it with Intent data coming back because it is always null either mail send or discard.
Related
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.
I have a text messaging app that I want users to be able to text another app of mine on someone else's phone that will show up within the app. Printed on screen. I have one app that will send the message and one app on the receiving device that will display the message. How would I go about doing this?
The receiving app is an opengl app that will display the message in front of a 3d model from the sending app.
If someone could help me out or get me going in the right direction, I would greatly appreciate it. Thank you for your time.
EDIT: This is what I'm doing. I'm making a live wallpaper that women can put on their phone, a seperate "regular" app will allow the husband, fiance, etc to send a message to the lwp on the significant others phone that will display at the top half of the lwp screen.
public void sendSMS(String phoneNumber, String message)
{
PendingIntent sentPI = PendingIntent.getBroadcast(this, 0,
new Intent(SENT), 0);
PendingIntent deliveredPI = PendingIntent.getBroadcast(this, 0,
new Intent(DELIVERED), 0);
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(phoneNumber, null, message, sentPI, deliveredPI);
}
You can do something like this for sending the sms.
Yes, it's possible.
Use SMSPopup as a working Android project you can use. It has the two parts you need: the sending part and the receiving part, and it's open source. Here it is on Google Play.
The only issue is that the user probably won't want those application messages intermingled with his normal SMS messages.
So you'll want to tag your application text messages with a unique keyword so that the receiving app knows it's a message for itself and no one else. And by tagging, I just mean to insert a unique keyword at the beginning of its subject line.
And your receiving app will have to register a BroadcastReceiver with a priority of 100 so that if it detects a message intended for itself, it can just delete it from the content provider and just do an AbortBroadcast so that the other text messaging apps don't beep for a message that wasn't meant for them in the first place.
In that sense, SMSPopup probably already does 90% of what you need. SMSPopup doesn't automatically delete the sms it receives, nor will it filter them on a particular keyword, but it must silently swallow them so that the normal notification system for sms doesn't get triggered (since SMSPopup provides its own notification popup interface instead).
Hi Steve we have RabbitMQServer to send messages between apps. We should configure the server and need to implement functionlities to send and receiving messages.
You may get details about RabbitMQ server at http://www.rabbitmq.com/.
Currently I have a button that when pushed calls the Intent below.
Intent sharingIntent = new Intent(Intent.ACTION_SEND_MULTIPLE);
sharingIntent.putExtra(Intent.EXTRA_EMAIL,
new String[] { toString });
sharingIntent.putExtra(Intent.EXTRA_SUBJECT,
"New Files from Safe Storage");
sharingIntent.setType("text/*");
startActivity(sharingIntent);
This intent then uses the default share activity to share the email with my attached file (which i took out for this example). When this code goes off it opens the gmail activity for me, but i still need to push the send button even though everything is filled in. Is there a way to make this instead just send automatically without showing the user the activity and having them forced to push "Send"?
Have a look on the following link, there is an answer for your question.
Sending Email in Android using JavaMail API without using the default android app(Builtin Email application)
I have an application that allows the user to send a picture. This picture can be sent via a number of different ways, like g-mail, facebook, flickr, and the one I am interested in, text messaging. When the following code is run, a dialog box pops up with a number of these options available.
Uri uri = Uri.fromFile(new File(externalDirectory + FILE_DIRECTORY + fileName));
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_STREAM, uri);
intent.setType("image/png");
startActivity(intent);
On my Droid X, the text messaging option is shown, and this code adds the picture to the MMS perfectly.
On the emulator, text messaging is chosen automatically (since there are no other options) and once again it works great.
On my Droid Incredible, there is no text messaging option. However, I can manually bring up the built-in text messaging utility, add the picture and then send it. I also downloaded an SMS/MMS app from the market, and afterward the option to use this 3rd party program to send the picture was available from the list.
So, why isn't text messaging an available option on the Droid Incredible? What do I need to do to make it an option, and how do I evaluate this problem (OR UNKNOWN PROBLEMS) with phone types I have no access to?
So, why isn't text messaging an available option on the Droid Incredible?
Because they chose not to offer it.
What do I need to do to make it an option
In the abstract, you can't.
Quoting the Android Compatibility Definition Document:
The Android upstream project defines a number of core applications, such as a phone dialer, calendar, contacts book, music player, and so on. Device
implementers MAY replace these applications with alternative versions.
However, any such alternative versions MUST honor the same Intent patterns provided by the upstream project. For example, if a device contains an
alternative music player, it must still honor the Intent pattern issued by third-party applications to pick a song.
The catch is, the Messenger app is not considered a "core application" by Google. Hence, device manufacturers are welcome to include their own SMS clients, with their own Intent filters. In the case of the HTC Incredible, apparently they did not include support for MMS via an image/png ACTION_SEND Intent.
Now, IMHO, Messenger probably should be a core application. However, your opinion and mine do not change reality as it stands today.
how do I evaluate this problem (OR UNKNOWN PROBLEMS) with phone types I have no access to
You redefine your application such that it is not a "problem". You have no guarantee that you can send an MMS that way, just as you have no guarantee that a user has a Facebook app installed.
I don't know much about MMS and am uncertain if there is a way other than ACTION_SEND to send an MMS. You might consider poking through the source code to the Messenger app to see how it does it. Then, bake the capability directly into your app. This will require a few extra permissions (SEND_SMS, and probably READ_CONTACTS) and will be annoying to write, but it will be more likely to work across devices.
I did manage to come up with a work around for this, thanks to some help from some other questions on SO.
Basically the key was determining the intent used by HTC, which appears to be the only company (currently) that's modified the android.intent.action.SEND Intent. Here is the code to add the option to the list.
Uri uri = Uri.fromFile(new File(mFile));
Intent intent = new Intent(Intent.ACTION_SEND);
intent.putExtra(Intent.EXTRA_STREAM, uri);
intent.setType("image/png");
Intent htcIntent = new Intent("android.intent.action.SEND_MSG");
htcIntent.setType("image/png");
htcIntent.putExtra(Intent.EXTRA_STREAM, uri);
Intent chooser = Intent.createChooser(intent, "Send Method");
chooser.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] { htcIntent });
startActivity(chooser);
I know that the SMS content provider is not part of the public API (at least not documented), but if I understand correctly it's still possible to use many of the SMS features as long as you know how to use the API(?).
E.g it's pretty straightforward to insert an SMS into your inbox:
ContentValues values = new ContentValues();
values.put("address", "+457014921911");
contentResolver.insert(Uri.parse("content://sms"), values);
Unfortunately this does not trigger the standard "new-SMS-in-your-inbox" notification. Is it possible to trigger this manually?
Edit: AFAIK the "standard mail application (Messaging)" in Android is listening for incoming SMSes using the android.permission.RECEIVE_SMS permission. And then, when a new SMS has arrived, a status bar notification is inserted with a "special" notification id.
So one solution to my problem (stated above) could be to find, and send the correct broadcast intent; something like "NEW SMS HAS ARRIVED"-intent.
Edit: Downloaded a third party messaging application (chompsms) from Android market. This application satisfies my needs better. When i execute the code above the chompsms notice the new sms and shows the "standard status bar notification". So I would say that the standard Android Messaging application is not detecting sms properly? Or am I wrong?
Unfortunately the code responsible for these notifications is hidden in the messaging application. The class MessagingNotification has a static method updateAllNotifications that you could call using a PathClassLoader and reflection:
PathClassLoader c = new PathClassLoader("/system/app/Mms.apk", getClassLoader());
Class.forName("com.android.mms.util.ContactInfoCache", true, c)
.getMethod("init", Context.class).invoke(null, context);
Class.forName("com.android.mms.transaction.MessagingNotification", true, c)
.getMethod("updateAllNotifications", Context.class).invoke(null, context);
This is obviously a very bad idea for several reasons but I can't think of another way to do what you described.
Could you trigger a PUSH notification after the SMS?
Thread: Does Android support near real time push notification?
Maybe you should replace
content://sms
with
content://sms/inbox