Slip 11
Slip 11
Slip 11
Design android application for login activity. Write android code to check login credentials with
username = "mca" and password = "android". Display appropriate toast message to the user.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="16dp"
android:paddingTop="16dp"
android:paddingRight="16dp"
android:paddingBottom="16dp"
tools:context=".LoginActivity">
<EditText
android:id="@+id/usernameEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Username"/>
<EditText
android:id="@+id/passwordEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/usernameEditText"
android:layout_marginTop="8dp"
android:hint="Password"
android:inputType="textPassword"/>
<Button
android:id="@+id/loginButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/passwordEditText"
android:layout_marginTop="16dp"
android:text="Login"/>
</RelativeLayout>
// src/com/example/myapplication/LoginActivity.java
package com.example.myapplication;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
@Override
setContentView(R.layout.activity_login);
loginButton.setOnClickListener(new View.OnClickListener() {
@Override
if (enteredUsername.equals(CORRECT_USERNAME) &&
enteredPassword.equals(CORRECT_PASSWORD)) {
// Successful login
showToast("Login successful");
} else {
// Incorrect credentials
});
}
Slip 11 q1 B
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="16dp"
android:paddingTop="16dp"
android:paddingRight="16dp"
android:paddingBottom="16dp"
tools:context=".RegistrationActivity">
<EditText
android:id="@+id/nameEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Name"/>
<EditText
android:id="@+id/emailEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/nameEditText"
android:layout_marginTop="8dp"
android:hint="Email"
android:inputType="textEmailAddress"/>
<EditText
android:id="@+id/passwordEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/emailEditText"
android:layout_marginTop="8dp"
android:hint="Password"
android:inputType="textPassword"/>
<EditText
android:id="@+id/mobileEditText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/passwordEditText"
android:layout_marginTop="8dp"
android:hint="Mobile Number"
android:inputType="phone"/>
<Button
android:id="@+id/registerButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/mobileEditText"
android:layout_marginTop="16dp"
android:text="Register"/>
</RelativeLayout>
// src/com/example/myapplication/RegistrationActivity.java
package com.example.myapplication;
import android.os.Bundle;
import android.util.Patterns;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_registration);
registerButton.setOnClickListener(new View.OnClickListener() {
@Override
} else if (!Patterns.EMAIL_ADDRESS.matcher(email).matches()) {
} else {
// Registration successful
showToast("Registration successful");
});
Q2
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="16dp"
android:paddingTop="16dp"
android:paddingRight="16dp"
android:paddingBottom="16dp"
tools:context=".MainActivity">
<EditText
android:id="@+id/editTextTo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="To"/>
<EditText
android:id="@+id/editTextSubject"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/editTextTo"
android:layout_marginTop="8dp"
android:hint="Subject"/>
<EditText
android:id="@+id/editTextMessage"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/editTextSubject"
android:layout_marginTop="8dp"
android:hint="Message"/>
<Button
android:id="@+id/buttonAttach"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/editTextMessage"
android:layout_marginTop="16dp"
android:text="Attach File"/>
<Button
android:id="@+id/buttonSend"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/buttonAttach"
android:layout_marginTop="16dp"
android:text="Send Email"/>
</RelativeLayout>
package com.example.emailsender;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.Environment;
import android.provider.MediaStore;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.content.FileProvider;
import java.io.File;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editTextTo = findViewById(R.id.editTextTo);
editTextSubject = findViewById(R.id.editTextSubject);
editTextMessage = findViewById(R.id.editTextMessage);
buttonAttach = findViewById(R.id.buttonAttach);
buttonSend = findViewById(R.id.buttonSend);
buttonAttach.setOnClickListener(new View.OnClickListener() {
@Override
});
buttonSend.setOnClickListener(new View.OnClickListener() {
@Override
sendEmail();
});
if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
try {
photoFile = createImageFile();
ex.printStackTrace();
if (photoFile != null) {
"com.example.android.fileprovider",
photoFile);
takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
}
}
imageFileName, /* prefix */
".jpg", /* suffix */
storageDir /* directory */
);
currentPhotoPath = image.getAbsolutePath();
return image;
@Override
String to = editTextTo.getText().toString().trim();
String subject = editTextSubject.getText().toString().trim();
return;
emailIntent.setType("message/rfc822");
emailIntent.putExtra(Intent.EXTRA_SUBJECT, subject);
emailIntent.putExtra(Intent.EXTRA_TEXT, message);
if (currentPhotoPath != null) {
emailIntent.putExtra(Intent.EXTRA_STREAM, photoUri);
try {