0% found this document useful (0 votes)
7 views

Android Programming

Uploaded by

Ansari Faisal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views

Android Programming

Uploaded by

Ansari Faisal
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 12

NAME- Ansari Mohd Faisal.

Dilshad
ROLL NO- 238

ASSIGNMENT-5 .

Q1-Create android application to send email with attachment.

package com.example.a5_q1;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;

import android.net.Uri;

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

import android.widget.EditText;

public class MainActivity extends AppCompatActivity {

EditText e1,e2,e3;

Button b1,b2;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

e1=findViewById(R.id.email);
e2=findViewById(R.id.subject);

e3=findViewById(R.id.message);

b1=findViewById(R.id.b1);

b2=findViewById(R.id.b2);

b1.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

Intent intent=new Intent();

intent.setType("Image/*");

intent.setAction(Intent.ACTION_GET_CONTENT);

startActivity(Intent.createChooser(intent,"Gallery"));

});

b2.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

String email=e1.getText().toString();

String subject=e2.getText().toString();

String message=e3.getText().toString();

Intent intent=new Intent(Intent.ACTION_SEND);

intent.setData(Uri.parse("mailto"));

intent.setType("text/plain");
intent.putExtra(Intent.EXTRA_EMAIL,email);

intent.putExtra(Intent.EXTRA_SUBJECT,subject);

intent.putExtra(Intent.EXTRA_TEXT,message);

startActivity(Intent.createChooser(intent,"Send Via"));

});

Q2- Create android application to send and receive message.

package com.example.message;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

import android.widget.EditText;

import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

EditText message;

Button btn;
TextView messageview;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

message=findViewById(R.id.m);

messageview=findViewById(R.id.t);

btn=findViewById(R.id.b);

btn.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

sendmessage();

});

private void sendmessage() {

String message1=message.getText().toString();

if (!message1.isEmpty())

messageview.setText("you: "+message1);
receivemessage("Friend:Hello!");

message.setText("");

private void receivemessage(String receivedmessage) {

messageview.append("\n"+receivedmessage);

Q3-Create an android application to send message after sending


message display “message .Send successfully in Toast”.

package com.example.meassgeusingtoast;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

import android.widget.EditText;

import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

EditText message;

Button btn;
@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

message=findViewById(R.id.m);

btn=findViewById(R.id.b);

btn.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

sendmessage();

});

private void sendmessage() {

String msg=message.getText().toString();

if(!msg.isEmpty())

Toast.makeText(MainActivity.this, "Message sent successfully",


Toast.LENGTH_SHORT).show();

else

{
Toast.makeText(MainActivity.this, "Please enter the message before
sending", Toast.LENGTH_SHORT).show();

Q4- Create application to design login form, validate it write and send
email with appropriate Message.

package com.example.login;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

import android.widget.EditText;

import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

EditText t1,t2;

Button b;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);
t1=findViewById(R.id.editTextTextEmailAddress);

t2=findViewById(R.id.editTextTextPassword);

b=findViewById(R.id.button);

b.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

String email=t1.getText().toString();

String password=t2.getText().toString();

if(isValidEmail(email) && isValidPassword(password)){

sendEmail();

else {

Toast.makeText(MainActivity.this, "Invalid email or password",


Toast.LENGTH_SHORT).show();

});

private void sendEmail() {

Toast.makeText(MainActivity.this, "Valid Login. Email sent Sucessfully",


Toast.LENGTH_SHORT).show();

}
private boolean isValidEmail(String email) {

return email.contains("@");

private boolean isValidPassword(String password) {

return password.length()>=6;

Q5-Create application to send message after sending message display


"Welcome to TYBCS" or else display "please enter the text before
sending message".(Using Toast).

package com.example.alertmessage;

import androidx.appcompat.app.AlertDialog;

import androidx.appcompat.app.AppCompatActivity;

import android.content.DialogInterface;

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

import android.widget.EditText;

import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

EditText msg;
Button btn;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

msg=findViewById(R.id.m);

btn=findViewById(R.id.b);

btn.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View v) {

sendmessage();

});

private void sendmessage() {

String message=msg.getText().toString();

if(!message.isEmpty())

AlertDialog.Builder a=new AlertDialog.Builder(MainActivity.this);

a.setTitle("My Alert Box");


a.setMessage("Welcome to TYBCS");

a.setNegativeButton("Okay", new DialogInterface.OnClickListener() {

@Override

public void onClick(DialogInterface dialog, int which) {

dialog.dismiss();

}).show();

else

AlertDialog.Builder b=new AlertDialog.Builder(MainActivity.this);

b.setTitle("My Alert Box");

b.setMessage("Please enter the text before sending the message");

b.setNegativeButton("Okay", new DialogInterface.OnClickListener() {

@Override

public void onClick(DialogInterface dialog, int which) {

dialog.dismiss();

}).show();

You might also like