Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.mytradebox.flashsales.activity;
- import android.os.AsyncTask;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.text.TextUtils;
- import android.view.View;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.Toast;
- import com.google.firebase.database.DatabaseReference;
- import com.google.firebase.database.FirebaseDatabase;
- import com.mytradebox.flashsales.R;
- import java.util.HashMap;
- import java.util.Properties;
- import javax.mail.Authenticator;
- import javax.mail.Message;
- import javax.mail.MessagingException;
- import javax.mail.PasswordAuthentication;
- import javax.mail.Session;
- import javax.mail.Transport;
- import javax.mail.internet.InternetAddress;
- import javax.mail.internet.MimeMessage;
- public class CashActivity extends AppCompatActivity
- {
- private EditText edtName , edtMail , edtNumber ,edtAmount ,edtIncome;
- private Button btnSubmit;
- private DatabaseReference mCashDatabase;
- String name,email,phone,income,amount;
- Session session=null;
- @Override
- protected void onCreate(Bundle savedInstanceState)
- {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_cash);
- edtName = (EditText)findViewById(R.id.cash_name);
- edtMail = (EditText)findViewById(R.id.cash_email);
- edtNumber = (EditText)findViewById(R.id.cash_phone);
- edtIncome = (EditText)findViewById(R.id.cash_income);
- edtAmount = (EditText)findViewById(R.id.cash_amount);
- btnSubmit = (Button)findViewById(R.id.cash_submit);
- // base url database
- mCashDatabase = FirebaseDatabase.getInstance().getReference();
- btnSubmit.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- //posting the query to database
- submitQuery();
- }
- });
- }
- private void submitQuery()
- {
- // getting all the inputs by the user
- name = edtName.getText().toString();
- email = edtMail.getText().toString();
- phone = edtNumber.getText().toString();
- income = edtIncome.getText().toString();
- amount = edtAmount.getText().toString();
- //using for posting the data
- DatabaseReference LoanPost = mCashDatabase.child("Loan");
- // applying validation
- if(!TextUtils.isEmpty(name) && !TextUtils.isEmpty(email) && !TextUtils.isEmpty(phone)
- && !TextUtils.isEmpty(income) && !TextUtils.isEmpty(amount)) {
- if (phone.length() != 10) {
- Toast.makeText(this, "Please Enter your phone number Correctly", Toast.LENGTH_SHORT).show();
- }
- else if (!email.contains("@")) {
- Toast.makeText(this, "Please enter a valid email", Toast.LENGTH_SHORT).show();
- }
- else {
- HashMap loanMap = new HashMap();
- loanMap.put("name", name);
- loanMap.put("email", email);
- loanMap.put("phone number", phone);
- loanMap.put("monthly income", income);
- loanMap.put("loan amount", amount);
- LoanPost.push().setValue(loanMap);
- Properties props=new Properties();
- props.put("mail.smtp.host","smtp.gmail.com");
- props.put("mail.smtp.socketFactory.port","465");
- props.put("mail.smtp.socketFactory.class","javax.net.ssl.SSLSocketFactory");
- props.put("mail.smtp.auth","true");
- props.put("mail.smtp.port","465");
- session=Session.getDefaultInstance(props, new Authenticator() {
- @Override
- protected PasswordAuthentication getPasswordAuthentication() {
- return new PasswordAuthentication("pradumn2323@gmail.com","thebetterlawyer1");
- }
- });
- RetreiveFeedTask task=new RetreiveFeedTask();
- task.execute();
- Toast.makeText(this, "Query Posted Successfully", Toast.LENGTH_SHORT).show();
- }
- }
- else
- {
- Toast.makeText(this, "Please Enter All The Details", Toast.LENGTH_LONG).show();
- }
- }
- class RetreiveFeedTask extends AsyncTask<String,Void,String>{
- @Override
- protected String doInBackground(String... strings) {
- try{
- Message message=new MimeMessage(session);
- message.setFrom(new InternetAddress("pradumn2323@gmail.com"));
- message.setRecipients(Message.RecipientType.TO,InternetAddress.parse("gargcheenu57@gmail.com"));
- message.setSubject("Need Cash");
- message.setContent(name+phone+amount+income,"text/html; charset=utf-8");
- Transport.send(message);
- }catch(MessagingException e)
- {
- e.printStackTrace();
- }catch(Exception e)
- {
- e.printStackTrace();
- }
- return null;
- }
- @Override
- protected void onPostExecute(String aVoid) {
- super.onPostExecute(aVoid);
- Toast.makeText(CashActivity.this, "Sent the message", Toast.LENGTH_SHORT).show();
- }
- }
- }
Add Comment
Please, Sign In to add comment