gpt4 book ai didi

android - 如何在android中创建忘记密码?

转载 作者:行者123 更新时间:2023-11-29 21:09:25 25 4
gpt4 key购买 nike

我想要一个使用“忘记密码”的应用程序。我有一个名为忘记密码的 TextView。当我点击它时,它会显示一个带有编辑文本的弹出窗口,我可以在其中写入电子邮件地址,当我点击“确定”按钮时,它会在我的邮件 ID 上发送新密码。我将 JSSEProvider 类用于协议(protocol)。

public final class JSSEProvider extends Provider {

public JSSEProvider() {
super("HarmonyJSSE", 1.0, "Harmony JSSE Provider");
AccessController.doPrivileged(new java.security.PrivilegedAction<Void>() {
public Void run() {
put("SSLContext.TLS",
"org.apache.harmony.xnet.provider.jsse.SSLContextImpl");
put("Alg.Alias.SSLContext.TLSv1", "TLS");
put("KeyManagerFactory.X509",
"org.apache.harmony.xnet.provider.jsse.KeyManagerFactoryImpl");
put("TrustManagerFactory.X509",
"org.apache.harmony.xnet.provider.jsse.TrustManagerFactoryImpl");
return null;
}
});
}
}

public class GMailSender extends javax.mail.Authenticator {   
private String mailhost = "smtp.gmail.com";
private String user;
private String password;
private Session session;

String subject = null;
String recipients = null;
String sender = null;
String body = null;

static {
Security.addProvider(new JSSEProvider());
}

public GMailSender(String user, String password) {
this.user = user;
this.password = password;

Properties props = new Properties();
props.setProperty("mail.transport.protocol", "smtp");
props.setProperty("mail.smtp.host", mailhost);
props.put("mail.smtp.auth", "true");
props.put("mail.smtp.port", "465");
props.put("mail.smtp.socketFactory.port", "465");
props.put("mail.smtp.socketFactory.class",
"javax.net.ssl.SSLSocketFactory");
props.put("mail.smtp.socketFactory.fallback", "false");
props.setProperty("mail.smtp.quitwait", "false");

session = Session.getDefaultInstance(props, this);
}

protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(user, password);
}

public synchronized void sendMail(String subject, String body, String sender, String recipients) throws Exception {
try{
Log.e(""," recipients "+recipients);

this.subject = subject;
this.recipients = recipients;
this.sender =sender;
this.body = body;

// Send this email in Async task, otherwise NetworkOnMainThread Exception will be thrown
new MobiSnifferAsync().execute();

}catch(Exception e){
e.printStackTrace();
}
}

class MobiSnifferAsync extends AsyncTask<Void, Void, Void>{

@Override
protected Void doInBackground(Void... params) {
try{
Log.e("AsyncTask"," subject "+subject);
Log.e("AsyncTask"," body "+body);
Log.e("AsyncTask"," sender "+sender);
Log.e("AsyncTask"," password "+password);
Log.e("AsyncTask"," recipients "+recipients);

Properties m_properties = new Properties();
m_properties.put("mail.smtp.host", "smtp.gmail.com");
m_properties.put("mail.smtp.socketFactory.port", "465");
m_properties.put("mail.smtp.socketFactory.class","javax.net.ssl.SSLSocketFactory");
m_properties.put("mail.smtp.auth", "true");
m_properties.put("mail.smtp.port", "465");


Session m_Session = Session.getInstance(m_properties, new Authenticator() {

protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(sender, password); // username and the password
}
});


InternetAddress m_fromAddress = new InternetAddress( sender);
InternetAddress m_toAddress = new InternetAddress( recipients);

MimeMessage m_simpleMessage = new MimeMessage(m_Session);
m_simpleMessage.setFrom(m_fromAddress);
m_simpleMessage.setRecipient(RecipientType.TO, m_toAddress);
m_simpleMessage.setSubject( subject);
m_simpleMessage.setContent( body, "text/plain");

Transport.send(m_simpleMessage);
}catch(Exception e){
e.printStackTrace();
}
return null;
}
}


public class ByteArrayDataSource implements DataSource {
private byte[] data;
private String type;

public ByteArrayDataSource(byte[] data, String type) {
super();
this.data = data;
this.type = type;
}

public ByteArrayDataSource(byte[] data) {
super();
this.data = data;
}

public void setType(String type) {
this.type = type;
}

public String getContentType() {
if (type == null)
return "application/octet-stream";
else
return type;
}

public InputStream getInputStream() throws IOException {
return new ByteArrayInputStream(data);
}

public String getName() {
return "ByteArrayDataSource";
}

public OutputStream getOutputStream() throws IOException {
throw new IOException("Not Supported");
}
}
}

但不知道如何在电子邮件 ID 上发送密码。谁能告诉我,我该怎么做。

最佳答案

试试这个非常简单的函数..

    protected void sendEmail() {
Log.i("Send email", "");

String[] TO = {"amrood.admin@gmail.com"};
String[] CC = {"mcmohd@gmail.com"};
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.setData(Uri.parse("mailto:"));
emailIntent.setType("text/plain");


emailIntent.putExtra(Intent.EXTRA_EMAIL, TO);
emailIntent.putExtra(Intent.EXTRA_CC, CC);
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Your subject");
emailIntent.putExtra(Intent.EXTRA_TEXT, "Email message goes here");

try {
startActivity(Intent.createChooser(emailIntent, "Send mail..."));
finish();
Log.i("Finished sending email...", "");
} catch (android.content.ActivityNotFoundException ex) {
Toast.makeText(MainActivity.this,
"There is no email client installed.", Toast.LENGTH_SHORT).show();
}
}

将您的密码和其他文本添加为​​ Intent.EXTRA_TEXT 的值..

关于android - 如何在android中创建忘记密码?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23440435/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com