1

i have made an activityenter image description here

at subscribe button, i have to send email to some default email for which my code is: package sditm.app;

import android.R.string;
import android.app.Activity;
import android.content.ContentValues;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.text.Html;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class subscribeActivity extends Activity {
/** Called when the activity is first created. */
EditText name,age,address;
databaseforsubscribe addressBook;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.subscribe);

    Button store = (Button)findViewById(R.id.button1);


    name=(EditText)findViewById(R.id.editText1);
    age=(EditText)findViewById(R.id.editText2);
    address=(EditText)findViewById(R.id.editText3);


    addressBook = new databaseforsubscribe(this,"addressDB",null,2);

    store.setOnClickListener(new OnClickListener() {
        public void onClick(View v) {
            // TODO Auto-generated method stub
            String s=new String();
            String m=new String();
            String n=new String();
            s=name.getText().toString();
            m=age.getText().toString();
            n=address.getText().toString();
            Intent i = new Intent(Intent.ACTION_SEND);
            i.setType("text/plain");

            i.putExtra(Intent.EXTRA_EMAIL, "aman4251@gmail.com");
        //  i.putExtra(Intent.EXTRA_EMAIL  , new String[]{"aman4251@gmail.com"});
            i.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
            i.putExtra(Intent.EXTRA_TEXT   ,"NAME: "+s+" ; MOBILE: "+m+" ; EMAIL: "+n);
            try {
                startActivity(Intent.createChooser(i, "Send mail..."));
            } catch (android.content.ActivityNotFoundException ex) {
                Toast.makeText(subscribeActivity.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
            }
        }
    });
}

}

which open an intent like thisenter image description here

now either i have to set the email id to "To" textbox (and make it uneditable"), or to automatically click on that "send" button so that user dont see this intent and email is send in back ground..

Aman Talwar
  • 183
  • 1
  • 2
  • 11

3 Answers3

0

Try this code:

Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(Intent.EXTRA_EMAIL  , new String[]{"recipient@example.com"});
i.putExtra(Intent.EXTRA_SUBJECT, "subject of email");
i.putExtra(Intent.EXTRA_TEXT   , "body of email");
try {
         startActivity(Intent.createChooser(i, "Send mail..."));
    } catch (android.content.ActivityNotFoundException ex) {
    Toast.makeText(MyActivity.this, "There are no email clients installed.",Toast.LENGTH_SHORT).show();
    }
Krishna Suthar
  • 2,911
  • 6
  • 29
  • 36
  • that's my code sir. i have tried it.. please go through my code – Aman Talwar May 15 '12 at 06:10
  • 1
    Aman, check this line of your cade: i.putExtra(Intent.EXTRA_EMAIL, "aman4251@gmail.com"); You are passing string here. You need to pass string array like this : new String[]{"recipient@example.com"}... Check this in code – Krishna Suthar May 15 '12 at 06:11
  • And yeah have you added this permission in your manifest file - – Krishna Suthar May 15 '12 at 06:17
  • i have tried that sir.. see i have made that comment.. that's doesn't work too.. and i have not added that.. how to add – Aman Talwar May 15 '12 at 06:20
  • Yes I checked. I think everything is fine with your code. Give me some time. I am arranging code for you. – Krishna Suthar May 15 '12 at 06:26
  • 1
    Hi Aman. I tried this code. I've not changed anything. Its working fine. And email is sending. Also it is displaying in address 'To:..........' box – Krishna Suthar May 15 '12 at 06:50
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/11253/discussion-between-aman-talwar-and-krishna-suthar) – Aman Talwar May 15 '12 at 07:06
0

Hi try this piece of code

    Intent sendIntent = new Intent(Intent.ACTION_SEND);
    // Add attributes to the intent
    sendIntent.putExtra(Intent.EXTRA_EMAIL, "");
    sendIntent.putExtra(Intent.EXTRA_CC, "");
    sendIntent.putExtra(Intent.EXTRA_SUBJECT, "");
    sendIntent.putExtra(Intent.EXTRA_TEXT, "");
    sendIntent.setType("text/plain");

    PackageManager pm = getPackageManager();
    List<ResolveInfo> activityList = pm
            .queryIntentActivities(sendIntent, 0);
    Iterator<ResolveInfo> it = activityList.iterator();
    boolean isEmailSetUp = false;
    while (it.hasNext()) {
        ResolveInfo info = it.next();
        if ("com.android.email.activity.MessageCompose"
                .equalsIgnoreCase(info.activityInfo.name)) {
            isEmailSetUp = true;
            sendIntent.setClassName(info.activityInfo.packageName,
                    info.activityInfo.name);
        }
    }
    if (isEmailSetUp) {
        startActivity(sendIntent);
    } else {
        AlertDialog.Builder dlgAlert = new AlertDialog.Builder(this);
        dlgAlert.setMessage("No Mail Accounts");
        dlgAlert.setTitle("Please set up a Mail account in order to send email");
        dlgAlert.setPositiveButton(getResources().getString(R.string.ok),
                null);
        dlgAlert.setCancelable(true);
        dlgAlert.create().show();
    }
harish
  • 1,705
  • 5
  • 22
  • 36
0

i dono know whether it is possible to make the email id edit text uneditable

But you can send mail in background by click on button

for that refer this link

Community
  • 1
  • 1
KMI
  • 498
  • 4
  • 24