Как отправить письмо с Android, как "mailto:" в PHP? - PullRequest
0 голосов
/ 06 августа 2011

каждый знает, как отправить письмо с устройства Android, например mailto: в PHP ?? мне действительно нужно это для моего приложения на локскрине ... оно отправит клиенту электронное письмо (электронная почта должна быть зарегистрирована заранее), когда он / она забудет свой пароль. что я должен делать?? любая идея?? спасибо ..

package com.application.outgoingemail;

import android.app.Service;
import android.content.Intent;
import android.os.IBinder;
import android.widget.Toast;

public class EmailService extends Service { 

    @Override
    public IBinder onBind(Intent intent) {
        return null;
    }

    @Override
    public void onCreate() {
        //Toast.makeText(this, "My Service Created", Toast.LENGTH_LONG).show();

    }

    @Override
    public void onStart(Intent intent, int startid) {
        //Toast.makeText(this, "My Service Started", Toast.LENGTH_LONG).show();
        sendEmail();
    }

    @Override
    public void onDestroy() {


    }

    public void sendEmail()
    {
        Intent i = new Intent(Intent.ACTION_SEND);
        i.setType("text/plain");
        i.putExtra(Intent.EXTRA_EMAIL  , new String[]{"myEmail@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(EmailService.this,ex.getMessage(), Toast.LENGTH_SHORT).show();
            Toast.makeText(EmailService.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
        }

        /*try {
            startActivity(Intent.createChooser(i, "Send mail..."));
        } catch (Exception ex) {
            Toast.makeText(EmailService.this,ex.getMessage(), 10).show();
            //Toast.makeText(EmailService.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
        }*/
    }
}

и на главной форме:

package com.application.outgoingemail;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class main extends Activity implements OnClickListener{
    /** Called when the activity is first created. */
    Button Button1,Button2;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        Button1=(Button)findViewById(R.id.button1);
        Button1.setOnClickListener(this);
        Button2=(Button)findViewById(R.id.button2);
        Button2.setOnClickListener(this);
    }

    public void onClick(View v) {
        // TODO Auto-generated method stub
        switch (v.getId()) {
        case R.id.button1:
                startService(new Intent(main.this, EmailService.class));
            break;
        case R.id.button2:
                stopService(new Intent(main.this, EmailService.class));
            break;
        default:
            break;
        }
    }
}

1 Ответ

3 голосов
/ 06 августа 2011

вы можете сделать так ::

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();
}
...