I am working on sending my message data on my email Id.I have made a mainActivity class containing an editText (for emailId) and a Button.
Another class is BroadcastReceiver class in which I retrieve data.
Now I can't understand how to send that data to the provided email in Background.
I have googled a lot but can't get the required response.
Please share the ideas and help me in it.
I create open source library for this. Usage is very simple:
BackgroundMail bm = new BackgroundMail(context);
bm.setGmailUserName("yourgmail#gmail.com");
bm.setGmailPassword("yourgmailpassword");
bm.setMailTo("receiver#gmail.com");
bm.setFormSubject("Subject");
bm.setFormBody("Body");
bm.send();
With this permissions
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
You can download it here:
https://github.com/kristijandraca/BackgroundMailLibrary
In android, You can send Email with explicit email intent however it will show a email screen and will not allow to send data in background.
To send data in background, you can use java mail api to send the mail.
Take a look on this http://www.tutorialspoint.com/java/java_sending_email.htm
This is one way of sending emails by using explicit email intent but this will not send in background
Intent sendemai = new Intent(Intent.ACTION_SEND);
sendemai.putExtra(Intent.EXTRA_EMAIL,
new String[] { toaddress });
sendemai.putExtra(Intent.EXTRA_CC,
new String[] { emailadd });
sendemai.putExtra(Intent.EXTRA_SUBJECT, sub);
sendemai.putExtra(Intent.EXTRA_TEXT, body);
// need this to prompts email client only
sendemai.setType("message/rfc822");
startActivity(Intent.createChooser(payment_request,
"Select email application"));
If you want to send in background then you need to provide some of user secure credentials.See Here
Related
I've implemented a class that can send a mail. However, you can only write a topic and the message and when you click on "Send" you've to choose which app (Outlook or Gmail) you want to send the mail with and then write your e-mail. However, I want to make it possible for the user to send a mail directly from the my app instead of using another app. So I want to make it possible for the user to write his/her e-mail/gmail and message and then send the message to my e-mail. So in other words in the fragment I want an EditText where the user writes his/her e-mail/gmail, another EditText where the user writes the message and a button to send. How can this be implemented?
This is what I have done in my app to send a mail:
private void sendemail(String message) {
String [] reciever = new String[]{"myemail#hotmail.com"};
String subject = ("Feedback/Question");
Intent mailIntent = new Intent(Intent.ACTION_SEND);
mailIntent.putExtra(Intent.EXTRA_EMAIL, reciever);
mailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
mailIntent.putExtra(Intent.EXTRA_TEXT, message);
mailIntent.setType("message/rfc822");
startActivity(Intent.createChooser(mailIntent, "Choose an application to send your mail with"));
}
Use this library -> Send email in background. It will send an email from your app without users interaction.
Cheers!
using java mailApi,you must have to authenticate gmail app using credential.
please check this link:
Email via Java MailAPI
other link to provide custom class to send mail programatically.
https://stackoverflow.com/a/4345084/1223291
I hope its useful to you.
Use this method....
public void sendEmail()
{
Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("message/rfc822");
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"care#xyz.com"});
intent.putExtra(Intent.EXTRA_SUBJECT, "care Feedback");
intent.putExtra(Intent.EXTRA_TEXT, "");
startActivity(Intent.createChooser(intent, "Send Email"));
}
I need to be able to check if the user has sent the text I set in my code;
Intent messageIntent = new Intent(Intent.ACTION_SEND)
messageIntent.putExtra(Intent.EXTRA_TEXT, "Text I want to send");
or has changed the prefixed text (on the SMS client app, email client app, or the app that gets launched by the intent) before sending it.
I need to know this because sharing my game link will give a reward to the user, so I need to check if that link is correctly shared.
I would appreciate any answer that could help.
Thanks.
ACTION_SEND isn't documented to return a result. So starting the intent with startActivityForResult() will return the default result: RESULT_CANCELED. That is, unless the receiving app has implemented support for returning a result; which is highly unlikely because it's not part of the documented behavior.
In summary, what you want to do is not possible with any of the common Intents.
You can try this...
String message = "Your Message";
intent.putExtra("IDENTIFIER", message);
And where you are going to receive the message...
String messageReceived = getIntent().getExtras().get("IDENTIFIER").toString();
I searched for the query online and figured the intent-filter in the AndroidManifest.xml file. However, I am still unable to find how to receive the clicked email id in my application.
My problem
Suppose I receive a message on my WhatsApp chat box containing an email id (xyz#test.com).
On clicking the email id (xyz#test.com), I want my app to open. (Figured, using Intent-filter)
Upon opening my application, I want the email id (xyz#test.com) to be automatically copied into the EditText on my activity.
I have tried with the following function:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Intent intent = getIntent();
String x = intent.getExtras().getString(Intent.EXTRA_EMAIL);
Toast.makeText(MainActivity.this, x, Toast.LENGTH_SHORT).show();
}
*Toast is for checking whether string is being received or no.
However, the toast appears empty,showing that the string is not getting received.
I believe that the email intent is really designed for sending/composing an email, not for copying data from the email into your application. See here:
http://developer.android.com/guide/components/intents-common.html#Email
If you wanted to get an email address for someone, you may want to try the contacts intent instead:
http://developer.android.com/guide/components/intents-common.html#Contacts
If an app invokes your activity via an ACTION_VIEW Intent, there is no documented means for that app to give you an email address.
If an app invokes your activity via an ACTION_SENDTO Intent, the email address will be in the Uri. That Uri scheme should be mailto: (as that what your filter is restricting it to). I think you get the address via getSchemeSpecificPart() on the Uri, though I have not tried this.
Note that there is no requirement for an app to launch any third-party activity when the user clicks an email address, let alone one of the two that you that you have set up via the <intent-filter>.
How do I add an "attachment" into my SmsManager object when I'm trying tro send an sms?
My current function for sending a normal sms is:
public void send() {
SmsManager sms = SmsManager.getDefault();
sms.sendTextMessage(this.number, null, this.message, null, null);
}
I have looked a little bit at the sendDataMessage() but don't really understand it.. any help is appreciated.
Thanks.
EDIT
I don't want to use Intent for this. I have a List with Bitmap images that I want to send via an SMS/MMS. So I don't want to invoke the SMS app in my application. I want to send attachments "dynamically" depending on what's in my List.
SOLUTION
A friend of mine just posted me this link to a library: https://github.com/klinker41/android-smsmms
Message mMessage = new Message(textToSend, addressToSendTo);
mMessage.setImage(mBitmap); // not necessary for voice or sms messages
mMessage.setType(Message.TYPE_SMSMMS); // could also be Message.TYPE_VOICE
Haven't tried it yet, but it seems to be the real deal. Hope it's for good use for someone else too.
follow the code
Intent sendIntent = new Intent(Intent.ACTION_VIEW);
sendIntent.putExtra("sms_body", "default content");
sendIntent.setType("vnd.android-dir/mms-sms");
startActivity(sendIntent);
and add permission
<uses-permission android:name="android.permission.SEND_SMS" />
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?