Mobile Application Development Lab
1.Creating “Hello world” Application
1. Click Start →Android Studio, a Welcome to Android Studio dialog box will appear. Click New Project, the New Project Dialog box appears.
2. Choose Empty Views Activity then click Next.
3. Specify the Name of your project, Select the Language as Java, and Select the Minimum SDK as API 16 (“Jelly Bean”, Android 4.1). Click Finish Button.
4. Create a Button resource in activity_main.xml and update the following code
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<Button
android:id="@+id/hello"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#535538"
android:text="@string/click_me"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Create a Button object, create clickListener, onClick event and update the following code in MainActivity.java
package com.example.a1stpro;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button b;
b = findViewById(R.id.hello);
b.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Remove the unnecessary 'Object Application' declaration
Toast.makeText(MainActivity.this, "Hey! We are using Android Application", Toast.LENGTH_SHORT).show();
}
});
}
2.Creating an application that displays message based on the screen orientation
1. Click Start →Android Studio, a Welcome to Android Studio dialog box will appear. Click New Project, the New Project Dialog box appears.
2. Choose Empty Views Activity then click Next.
3. Specify the Name of your project, Select the Language as Java, and Select the Minimum SDK as API 16 (“Jelly Bean”, Android 4.1). Click Finish Button.
4. Create two Button resources in activity_main.xml and update the following code.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<Button
android:id="@+id/por"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Portrait"
android:layout_centerInParent="true"/>
<Button
android:id="@+id/lan"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Landscape"
android:layout_below="@id/por"
android:layout_centerInParent="true"/>
</RelativeLayout>
Create two Button object, create clickListener, onClick event and update the following code in MainActivity.java
package com.example.a2ndpro;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.Toast;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_main);
Button l, p;
l = findViewById(R.id.lan);
p = findViewById(R.id.por);
l.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
Toast.makeText(MainActivity.this, "Hey! Blackeye Landscape orientation", Toast.LENGTH_SHORT).show();
}
});
p.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
Toast.makeText(MainActivity.this, "Hey!Blackeye Portrait orientation", Toast.LENGTH_SHORT).show();
}
});
}
3. Create an application to develop Login window using UI controls.
1. Click New Project, the New Project Dialog box appears.
2. Choose Empty Views Activity then click Next.
3. Specify the Name of your project, Select the Language as Java, and Select the Minimum SDK as API 16 (“Jelly Bean”, Android 4.1). Click Finish Button.
4. Create background resources(bg_outer.xml, bg_inner.xml)
a. To create resource file click app→res→drawable. Right click drawable→New→ Drawable Resource File. The New Resource File dialog box appears.
b. Set filename as bg_outer.xml, root element as shape and then click ok. Modify the bg_outer.xml file
a.Create two EditText box and a Button resource in activity_main.xml and update the following code.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:background="@drawable/bg_outer">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_centerInParent="true"
android:orientation="vertical"
android:background="@drawable/bg_inner"
android:padding="30dp"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="LOGIN PAGE"
android:textSize="32sp"
android:textStyle="bold"
android:fontFamily="sans-serif-condensed-medium"
android:textColor="@color/black"
android:paddingBottom="20dp"
/>
<EditText
android:id="@+id/editTextUsername"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Username"
android:textColor="#FFFFFF"
android:layout_marginBottom="16dp"/>
<EditText
android:id="@+id/editTextPassword"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Password"
android:textColor="#FFFFFF"
android:layout_below="@id/editTextUsername"
android:layout_marginBottom="16dp"
android:inputType="textPassword"/>
<Button
android:id="@+id/buttonLogin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Login"
android:layout_below="@id/editTextPassword"/>
</LinearLayout>
</RelativeLayout>
c. Likewise, create another background resource for inner layout. Set filename as bg_inner.xml, root element as shape and then click ok. Modify the bg_inner.xml file
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient
android:startColor="#000000"
android:endColor= "#DE0000"
android:angle="100"/>
<corners android:radius="20dp"/>
</shape>
enter the code mainactivity.java
package com.example.a3rdpro;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
public class MainActivity extends AppCompatActivity {
private EditText editTextUsername,editTextPassword;
private Button buttonLogin;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_main);
editTextUsername = findViewById(R.id.editTextUsername);
editTextPassword = findViewById(R.id.editTextPassword);
buttonLogin = findViewById(R.id.buttonLogin);
buttonLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String username = editTextUsername.getText().toString().trim();
String password = editTextPassword.getText().toString().trim();
if(username.equals("Blackeye001") && password.equals("blog")){
Toast.makeText(MainActivity.this, "Login successful",
Toast.LENGTH_SHORT).show();
} else {
Toast.makeText(MainActivity.this, "Invalid username or password",
Toast.LENGTH_SHORT).show();
}
}
});
}
}
4.Create an application to implement new activity using explicit intent, implicit intent and content provider.
1. Click New Project, the New Project Dialog box appears.
2. Choose Empty Views Activity then click Next.
3. Specify the Name of your project, Select the Language as Java, and Select the Minimum SDK as API 16 (“Jelly Bean”, Android 4.1). Click Finish Button.
4. To create another activity for Explicit Intent, Click File→New→Activity→ Empty Views Activity. A New Android Activity dialog box appears, Specify the Name of the activity as NewActivity then click Finish.
5. Create one TextView resource in activity_new.xml and update the following code
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".NewActivity">
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Welcome to Blackeye001"
android:textSize="28sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
6. Add two events named as onImplicitButtonClicked, onExplicitButtonClicked and update the following code in MainActivity.java
package com.example.a4pro;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_main);
}
public void onImplicitButtonClicked(View view)
{
Uri url=Uri.parse("https://blackeye001.blogspot.com/");
Intent i=new Intent(Intent.ACTION_VIEW, url);
startActivity(i);
}
public void onExplicitButtonClicked(View view )
{
Intent i=new Intent(MainActivity.this, NewActivity.class);
startActivity(i);
}
}
7.Add two Button resource in activity_main.xml and update the following code
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
tools:context=".MainActivity">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Implicit Intent"
android:onClick="onImplicitButtonClicked"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Explicit Intent"
android:onClick="onExplicitButtonClicked"/>
</LinearLayout>
5. Create an application that displays custom designed Opening Screen.
1. Click New Project, the New Project Dialog box appears.
2. Choose Empty Views Activity then click Next.
3. Specify the Name of your project, Select the Language as Java, and Select the
Minimum SDK as API 16 (“Jelly Bean”, Android 4.1). Click Finish Button.
4. To create another activity for Home Page, Right Click App→New→Activity→
Empty Views Activity. A New Android Activity dialog box appears, Specify the
Name of the activity as mainScreen then click Finish.
5. Create one TextView resource in activity_mainScreen.xml and update the following
code
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".mainScreen"
android:gravity="center"
android:background="#FF0000">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Welcome to Blackeye001"
android:textStyle="bold"
android:textSize="32sp"
android:textColor="@color/black"/>
</RelativeLayout>
6. To add an ImageView resource: Copy an image and paste it into drawable folder (Right-click Drawable→ Paste the image[img1.jpg]).
7. Set an image as src in activity_main.xml and update the following code.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:background="@color/black"
android:gravity="center">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/logo"/>
</RelativeLayout>
Update the following code in MainActivity.java
package com.example.a5thpro;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.view.WindowManager;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
public class MainActivity extends AppCompatActivity {
private static final int SPLASH_SCREEN_TIME_OUT = 2000;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_main);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
Intent i = new Intent(MainActivity.this, mainScreen.class);
startActivity(i);
finish();
}
}, SPLASH_SCREEN_TIME_OUT);
}
}
6. Create an UI with all views.
1. Click New Project, the New Project Dialog box appears.
2. Choose Empty Views Activity then click Next.
3. Specify the Name of your project, Select the Language as Java, and Select the Minimum SDK as API 16 (“Jelly Bean”, Android 4.1). Click Finish Button.
4. Create background resources(bg_outer.xml, bg_inner.xml, bg.xml)
a. To create resource file click app→res→drawable. Right click drawable→New→ Drawable Resource File. The New Resource File dialog box appears.
b. Set filename as bg_outer.xml, root element as shape and then click ok. Modify the bg_outer.xml file
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient android:startColor="#E80002"
android:endColor="#3D2022"
android:angle="120"
android:gradientRadius="5dp"/>
<corners android:radius="20dp"/>
</shape>
c. Create another background resource for inner layout. Set filename as bg_inner.xml, root element as shape and then click ok. Modify the bg_inner.xml file
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<gradient android:startColor="#3D2022"
android:endColor="#D50204"
android:angle="120"
android:gradientRadius="5dp"/>
<corners android:radius="20dp"
android:topLeftRadius="70dp"
android:bottomRightRadius="70dp"/>
</shape>
d. Likewise, create another background resource for view. Set filename as bg.xml, root element as shape and then click ok. Modify the bg..xml file
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="#FF0000"/>
<corners android:radius="30dp" />
<stroke android:color="#00BFA5"
android:width="2dp"/>
</shape>
5. Create a TextView, EditText, ToggleButton, ImageView, RadioGroup, RadioButton, spinner and a Button resource in activity_main.xml and update the following code
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:gravity="center"
android:orientation="vertical"
android:padding="30dp"
android:background="@drawable/bg_outer">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="User Information"
android:textSize="30sp"
android:textStyle="bold"
android:textColor="#26389C"/>
<ImageView
android:layout_width="73dp"
android:layout_height="77dp"
android:src="@drawable/img" />
<ToggleButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textOn="Active"
android:textOff="Inactive"/>
<View
android:layout_width="match_parent"
android:layout_height="40dp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="30dp"
android:paddingBottom="30dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:orientation="vertical"
android:background="@drawable/bg_inner">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name"
android:textSize="20sp"
android:textStyle="bold"
android:textColor="#26389C"
android:padding="15dp"/>
<EditText
android:layout_width="match_parent"
android:layout_height="60dp"
android:id="@+id/name"
android:background="@drawable/bg"
android:padding="15dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="E-mail"
android:textSize="20sp"
android:textStyle="bold"
android:textColor="#26389C"
android:padding="15dp"/>
<EditText
android:id="@+id/email"
android:layout_width="match_parent"
android:layout_height="60dp"
android:ems="10"
android:inputType="textEmailAddress"
android:background="@drawable/bg"
android:padding="15dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="40dp"
android:text="Sex"
android:textSize="20sp"
android:textStyle="bold"
android:textColor="#26389C"
android:padding="15dp"
android:paddingEnd="40dp"
/>
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/bg"
android:orientation="horizontal"
android:id="@+id/sex">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/male"
android:padding="15dp"
android:text="Male"
android:textColor="#26389C"
android:textSize="20sp"
android:textStyle="bold" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/female"
android:padding="15dp"
android:text="Female"
android:textColor="#26389C"
android:textSize="20sp"
android:textStyle="bold" />
</RadioGroup>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:padding="5dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingRight="5dp"
android:text="Country"
android:textSize="20sp"
android:textStyle="bold"
android:textColor="#26389C"
android:padding="15dp"
android:paddingEnd="5dp" />
<Spinner
android:layout_width="match_parent"
android:layout_height="60dp"
android:id="@+id/country"
android:padding="15dp"
android:background="@drawable/bg"/>
</LinearLayout>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="40dp"/>
<Button
android:layout_width="210dp"
android:layout_height="wrap_content"
android:id="@+id/submit"
android:background="@drawable/bg"
android:padding="15dp"
android:text="Submit"
android:textColor="#26389C"
android:textSize="20sp"
android:textStyle="bold" />
</LinearLayout>
6.Create two EditText and a Button object, create clickListener, onClick event for button object and update the following code in MainActivity.java
package com.example.a6thpro;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Spinner;
import android.widget.Toast;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
public class MainActivity extends AppCompatActivity {
Button sub;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_main);
Button sub=findViewById(R.id.submit);
sub.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showMessage(MainActivity.this,"User Information","WELCOME TO BLACKEYE001");
}
});
String[] item=new String[]{"India", "Pakisthan", "China", "America",
"England"};
ArrayAdapter adapter = new ArrayAdapter<>(this,
android.R.layout.simple_spinner_item, item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
Spinner spinner = findViewById(R.id.country);
spinner.setAdapter(adapter);
}
public void showMessage(Context con,String t, String msg)
{
AlertDialog.Builder builder = new AlertDialog.Builder(con);
builder.setTitle(t);
builder.setMessage(msg);
builder.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
builder.show();
}
}
7. Create menu in Application
1. Click New Project, the New Project Dialog box appears.
2. Choose Empty Views Activity then click Next.
3. Specify the Name of your project, Select the Language as Java, and Select the Minimum SDK as API 16 (“Jelly Bean”, Android 4.1). Click Finish Button.
4. To create another activity for Home Page, Right Click App→New→Activity→ Empty Views Activity. A New Android Activity dialog box appears, Specify the Name of the activity as HomeScreen then click Finish.
5. To create a Menu Resource File: Right-click on the res directory in your Android project, navigate to New > Android Resource File, and name the file menus.xml, Root element as Menu and update the following content.
file menus.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@+id/php"
android:title="Blackeye001"/>
<item android:id="@+id/java"
android:title="Blackeye0011"/>
<item android:id="@+id/csharp"
android:title="youtube.com/@blackeye0001"/>
</menu>
6. Update the following code in MainActivity.java
package com.example.a7thpro;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.widget.Toast;
import androidx.activity.EdgeToEdge;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreatePanelMenu(int featureId, @NonNull Menu menu) {
MenuInflater inflater=getMenuInflater();
inflater.inflate(R.menu.menus,menu);
return true;
}
@Override
public boolean onOptionsItemSelected(@NonNull MenuItem item) {
if(item.getItemId()==R.id.php) {
Toast.makeText(this, "Php Page", Toast.LENGTH_SHORT).show();
}
if(item.getItemId()==R.id.java) {
Toast.makeText(this, "Java Page", Toast.LENGTH_SHORT).show();
}
if(item.getItemId()==R.id.csharp) {
Toast.makeText(this, "C# Page", Toast.LENGTH_SHORT).show();
}
return super.onOptionsItemSelected(item);
}
}
7. Set the Uses-Permission in AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.INTERNET" />
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.AppCompat.Light"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
8 Read/ write the Local data.
1. Click New Project, the New Project Dialog box appears.
2. Choose Empty Views Activity then click Next.
3. Specify the Name of your project, Select the Language as Java, and Select the Minimum SDK as API 16 (“Jelly Bean”, Android 4.1). Click Finish Button.
4. To create another activity for Home Page, Right Click App→New→Activity→ Empty Views Activity. A New Android Activity dialog box appears, Specify the Name of the activity as HomeScreen then click Finish.
acitivit_main.xml
<?xml version="1.0" encoding="utf-8"?>
<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:padding="16dp"
tools:context=".MainActivity">
<EditText
android:id="@+id/editTextUsername"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter Username"
android:inputType="text" />
<EditText
android:id="@+id/editTextAge"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/editTextUsername"
android:layout_marginTop="16dp"
android:hint="Enter Age"
android:inputType="number" />
<Button
android:id="@+id/buttonSave"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/editTextAge"
android:layout_marginTop="16dp"
android:text="Save Data" />
<Button
android:id="@+id/buttonDisplay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/buttonSave"
android:layout_marginTop="16dp"
android:text="Display Data" />
</RelativeLayout>
activitymain.java
package com.example.a8thpro;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
private EditText editTextUsername, editTextAge;
private Button buttonSave, buttonDisplay;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editTextUsername = findViewById(R.id.editTextUsername);
editTextAge = findViewById(R.id.editTextAge);
buttonSave = findViewById(R.id.buttonSave);
buttonDisplay = findViewById(R.id.buttonDisplay);
buttonSave.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
saveData();
}
});
buttonDisplay.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
displayData();
}
});
}
private void saveData() {
SharedPreferences sharedPreferences = getSharedPreferences("my_preferences", Context.MODE_PRIVATE);
SharedPreferences.Editor editor = sharedPreferences.edit();
String username = editTextUsername.getText().toString().trim();
String ageStr = editTextAge.getText().toString().trim();
if (username.isEmpty() || ageStr.isEmpty()) {
Toast.makeText(this, "Please enter username and age", Toast.LENGTH_SHORT).show();
return;
}
int age = Integer.parseInt(ageStr);
editor.putString("username", username);
editor.putInt("age", age);
editor.putBoolean("is_logged_in", true);
editor.apply();
Toast.makeText(this, "Data saved successfully", Toast.LENGTH_SHORT).show();
editTextUsername.setText("");
editTextAge.setText("");
}
private void displayData() {
SharedPreferences sharedPreferences = getSharedPreferences("my_preferences", Context.MODE_PRIVATE);
String username = sharedPreferences.getString("username", "");
int age = sharedPreferences.getInt("age", 0);
boolean isLoggedIn = sharedPreferences.getBoolean("is_logged_in", false);
String displayText = "Username: " + username + "\nAge: " + age + "\nIs Logged In: " + isLoggedIn;
Toast.makeText(this, displayText, Toast.LENGTH_LONG).show();
Log.d("MainActivity", "Username: " + username);
Log.d("MainActivity", "Age: " + age);
Log.d("MainActivity", "Is Logged In: " + isLoggedIn);
}
}
Activitymainfest.xml
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
9.Create / Read / Write data with database (SQLite).
1. Click New Project, the New Project Dialog box appears.
2. Choose Empty Views Activity then click Next.
3. Specify the Name of your project, Select the Language as Java, and Select the Minimum SDK as API 16 (“Jelly Bean”, Android 4.1). Click Finish Button.
4. To create another activity for Home Page, Right Click App→New→Activity→ Empty Views Activity. A New Android Activity dialog box appears, Specify the Name of the activity as HomeScreen then click Finish.
5.create a class
right click on java and create on class and name it as DatabaseHelperClass
package com.example.sqliteexample;
import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
import java.util.ArrayList;
import java.util.List;
public class DatabaseHelperClass extends SQLiteOpenHelper {
//Database version
private static final int DATABASE_VERSION = 1;
//Database Name
private static final String DATABASE_NAME = "employee_database";
//Database Table name
private static final String TABLE_NAME = "EMPLOYEE";
//Table columns
public static final String ID = "id";
public static final String NAME = "name";
public static final String EMAIL = "email";
private SQLiteDatabase sqLiteDatabase;
//creating table query
private static final String CREATE_TABLE = "create table " + TABLE_NAME +"("+ID+
" INTEGER PRIMARY KEY AUTOINCREMENT," + NAME + " TEXT NOT NULL,"+EMAIL+" TEXT NOT NULL);";
//Constructor
public DatabaseHelperClass (Context context){
super(context,DATABASE_NAME,null,DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(CREATE_TABLE);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL(" DROP TABLE IF EXISTS " + TABLE_NAME);
onCreate(db);
}
//Add Employee Data
public void addEmployee(EmployeeModelClass employeeModelClass){
ContentValues contentValues = new ContentValues();
contentValues.put(DatabaseHelperClass.NAME, employeeModelClass.getName());
contentValues.put(DatabaseHelperClass.EMAIL, employeeModelClass.getEmail());
sqLiteDatabase = this.getWritableDatabase();
sqLiteDatabase.insert(DatabaseHelperClass.TABLE_NAME, null,contentValues);
}
public List<EmployeeModelClass> getEmployeeList(){
String sql = "select * from " + TABLE_NAME;
sqLiteDatabase = this.getReadableDatabase();
List<EmployeeModelClass> storeEmployee = new ArrayList<>();
Cursor cursor = sqLiteDatabase.rawQuery(sql,null);
if (cursor.moveToFirst()){
do {
int id = Integer.parseInt(cursor.getString(0));
String name = cursor.getString(1);
String email = cursor.getString(2);
storeEmployee.add(new EmployeeModelClass(id,name,email));
}while (cursor.moveToNext());
}
cursor.close();
return storeEmployee;
}
public void updateEmployee(EmployeeModelClass employeeModelClass){
ContentValues contentValues = new ContentValues();
contentValues.put(DatabaseHelperClass.NAME,employeeModelClass.getName());
contentValues.put(DatabaseHelperClass.EMAIL,employeeModelClass.getEmail());
sqLiteDatabase = this.getWritableDatabase();
sqLiteDatabase.update(TABLE_NAME,contentValues,ID + " = ?" , new String[]
{String.valueOf(employeeModelClass.getId())});
}
public void deleteEmployee(int id){
sqLiteDatabase = this.getWritableDatabase();
sqLiteDatabase.delete(TABLE_NAME, ID + " = ? ", new String[]
{String.valueOf(id)});
}
}
right click on java and create on class and name it as EmployeeAdapterClass
package com.example.sqliteexample;
import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
import java.util.List;
public class EmployeeAdapterClass extends RecyclerView.Adapter<EmployeeAdapterClass.ViewHolder> {
List<EmployeeModelClass> employee;
Context context;
DatabaseHelperClass databaseHelperClass;
public EmployeeAdapterClass(List<EmployeeModelClass> employee, Context context) {
this.employee = employee;
this.context = context;
databaseHelperClass = new DatabaseHelperClass(context);
}
@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext());
View view = layoutInflater.inflate(R.layout.employee_item_list,parent,false);
ViewHolder viewHolder = new ViewHolder(view);
return viewHolder;
}
@Override
public void onBindViewHolder(@NonNull final ViewHolder holder, final int position) {
final EmployeeModelClass employeeModelClass = employee.get(position);
holder.textViewID.setText(Integer.toString(employeeModelClass.getId()));
holder.editText_Name.setText(employeeModelClass.getName());
holder.editText_Email.setText(employeeModelClass.getEmail());
holder.button_Edit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String stringName = holder.editText_Name.getText().toString();
String stringEmail = holder.editText_Email.getText().toString();
databaseHelperClass.updateEmployee(new EmployeeModelClass(employeeModelClass.getId(),stringName,stringEmail));
notifyDataSetChanged();
((Activity) context).finish();
context.startActivity(((Activity) context).getIntent());
}
});
holder.button_delete.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
databaseHelperClass.deleteEmployee(employeeModelClass.getId());
employee.remove(position);
notifyDataSetChanged();
}
});
}
@Override
public int getItemCount() {
return employee.size();
}
public class ViewHolder extends RecyclerView.ViewHolder{
TextView textViewID;
EditText editText_Name;
EditText editText_Email;
Button button_Edit;
Button button_delete;
public ViewHolder(@NonNull View itemView) {
super(itemView);
textViewID = itemView.findViewById(R.id.text_id);
editText_Name = itemView.findViewById(R.id.edittext_name);
editText_Email = itemView.findViewById(R.id.edittext_email);
button_delete = itemView.findViewById(R.id.button_delete);
button_Edit = itemView.findViewById(R.id.button_edit);
}
}
}
right click on java and create on class and name it as EmployeeModelClass
package com.example.sqliteexample;
public class EmployeeModelClass {
Integer id;
String name;
String email;
public EmployeeModelClass(String name, String email) {
this.name = name;
this.email = email;
}
public EmployeeModelClass(Integer id, String name, String email) {
this.id = id;
this.name = name;
this.email = email;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
}
right click on java and create on class and name it as ViewEmployeeActivity
package com.example.sqliteexample;
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.os.Bundle;
import android.widget.Toast;
import java.util.List;
public class ViewEmployeeActivity extends AppCompatActivity {
RecyclerView recyclerView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_view_employee);
recyclerView = findViewById(R.id.recyclerView);
recyclerView.setLayoutManager(new LinearLayoutManager(this));
recyclerView.setHasFixedSize(true);
DatabaseHelperClass databaseHelperClass = new DatabaseHelperClass(this);
List<EmployeeModelClass> employeeModelClasses = databaseHelperClass.getEmployeeList();
if (employeeModelClasses.size() > 0){
EmployeeAdapterClass employeadapterclass = new EmployeeAdapterClass(employeeModelClasses,ViewEmployeeActivity.this);
recyclerView.setAdapter(employeadapterclass);
}else {
Toast.makeText(this, "There is no employee in the database", Toast.LENGTH_SHORT).show();
}
}
}
Add this is in MainActivity.java
package com.example.sqliteexample;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
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 editText_name,editText_email;
Button button_add,button_view;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editText_name = findViewById(R.id.edittext_name);
editText_email = findViewById(R.id.edittext_email);
button_add = findViewById(R.id.button_add);
button_view = findViewById(R.id.button_view);
button_add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String stringName = editText_name.getText().toString();
String stringEmail = editText_email.getText().toString();
if (stringName.length() <=0 || stringEmail.length() <=0){
Toast.makeText(MainActivity.this, "Enter All Data", Toast.LENGTH_SHORT).show();
}else {
DatabaseHelperClass databaseHelperClass = new DatabaseHelperClass(MainActivity.this);
EmployeeModelClass employeeModelClass = new EmployeeModelClass(stringName,stringEmail);
databaseHelperClass.addEmployee(employeeModelClass);
Toast.makeText(MainActivity.this, "Add Employee Successfully", Toast.LENGTH_SHORT).show();
finish();
startActivity(getIntent());
}
}
});
button_view.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this,ViewEmployeeActivity.class);
startActivity(intent);
}
});
}
}
Add this in main_activity.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:orientation="vertical"
android:gravity="center"
android:layout_height="match_parent"
tools:context=".MainActivity">
<EditText
android:id="@+id/edittext_name"
android:layout_margin="5dp"
android:hint="Enter Name"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<EditText
android:id="@+id/edittext_email"
android:layout_margin="5dp"
android:hint="Enter Email"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<Button
android:textStyle="bold"
android:layout_margin="5dp"
android:id="@+id/button_add"
android:text="Add Employee"
android:background="#388E3C"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<Button
android:textStyle="bold"
android:layout_margin="5dp"
android:id="@+id/button_view"
android:text="View Employee"
android:background="#0288D1"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
right link on layout create resource file name it as activity_view_employee.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:focusableInTouchMode="true"
android:layout_height="match_parent"
tools:context=".ViewEmployeeActivity">
<androidx.recyclerview.widget.RecyclerView
android:layout_width="match_parent"
android:id="@+id/recyclerView"
android:layout_height="match_parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>
create one more resource file name it as employee_item_list.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="wrap_content">
<TextView
android:textColor="#000"
android:id="@+id/text_id"
android:layout_margin="10dp"
android:textSize="18dp"
android:text="Id"
android:textStyle="bold"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<EditText
android:textColor="#000"
android:textStyle="bold"
android:id="@+id/edittext_name"
android:text="Name"
android:layout_margin="5dp"
android:textSize="18sp"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<EditText
android:textColor="#000"
android:textStyle="bold"
android:id="@+id/edittext_email"
android:text="Email"
android:layout_margin="5dp"
android:textSize="18sp"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<LinearLayout
android:layout_margin="5dp"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:background="#0288D1"
android:id="@+id/button_edit"
android:layout_weight="2"
android:text="Edit"
android:layout_margin="2dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<Button
android:layout_margin="2dp"
android:background="#D32F2F"
android:id="@+id/button_delete"
android:layout_weight="2"
android:text="Delete"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
<View
android:layout_margin="5dp"
android:background="#C5C5C5"
android:layout_width="match_parent"
android:layout_height="1dp"/>
</LinearLayout>
save and run the file if any error come . while building an apk or running the file check for gradle version
10.Create an application to send SMS and receive SMS
1. Click New Project, the New Project Dialog box appears.
2. Choose Empty Views Activity then click Next.
3. Specify the Name of your project, Select the Language as Java, and Select the Minimum SDK as API 16 (“Jelly Bean”, Android 4.1). Click Finish Button.
4.Update the code in AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-feature
android:name="android.hardware.telephony"
android:required="false" />
<uses-permission android:name="android.permission.SEND_SMS"/>
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Sms"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
5.Update the code in activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<EditText
android:id="@+id/number"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Phone Number"
android:inputType="phone"
android:layout_margin="8dp"/>
<EditText
android:id="@+id/message"
android:layout_width="match_parent"
android:layout_height="100dp"
android:hint="Type message "
android:inputType="textLongMessage"
android:gravity="top"
android:layout_margin="8dp"/>
<Button
android:id="@+id/send"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="send"
android:layout_gravity="center"
/>
</LinearLayout>
6.update the code in Android _main.java
package com.example.sms;
import android.content.pm.PackageManager;
import android.os.Build;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import android.Manifest;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;
public class MainActivity extends AppCompatActivity {
private EditText number,message;
private Button send;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_main);
number = findViewById(R.id.number);
message = findViewById(R.id.message);
send = findViewById(R.id.send);
send.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.M){
if(checkSelfPermission(Manifest.permission.SEND_SMS) == PackageManager.PERMISSION_GRANTED){
sendSMS();
} else {
requestPermissions(new String[] {Manifest.permission.SEND_SMS},1);
}
}
}
});
}
private void sendSMS(){
String phoneNo = number.getText().toString().trim();
String SMS = message.getText().toString().trim();
try {
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(phoneNo, null, SMS, null, null);
Toast.makeText(this, "Message is sent", Toast.LENGTH_SHORT).show();
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(this, "Faild to send message", Toast.LENGTH_SHORT).show();
}
}
}
11. Create an application to send an e-mail.
1. Click Start →Android Studio, a Welcome to Android Studio dialog box will appear. Click New Project, the New Project Dialog box appears.
2. Choose Empty Views Activity then click Next.
3. Specify the Name of your project, Select the Language as Java, and Select the Minimum SDK as API 16 (“Jelly Bean”, Android 4.1). Click Finish Button.
4. Create a Button resource in activity_main.xml and update the following code
<?xml version="1.0" encoding="utf-8"?>
<!-- Relative Layout -->
<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"
tools:context=".MainActivity">
<!-- Edit text for email id -->
<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_marginTop="18dp"
android:layout_marginRight="22dp" />
<!-- Edit text for email subject -->
<EditText
android:id="@+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/editText1"
android:layout_alignLeft="@+id/editText1"
android:layout_marginTop="20dp" />
<!-- Edit text for email body -->
<EditText
android:id="@+id/editText3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/editText2"
android:layout_alignLeft="@+id/editText2"
android:layout_marginTop="30dp" />
<!-- text Views for label -->
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/editText1"
android:layout_alignBottom="@+id/editText1"
android:layout_alignParentLeft="true"
android:text="Send To:"
android:textColor="#0F9D58" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/editText2"
android:layout_alignBottom="@+id/editText2"
android:layout_alignParentLeft="true"
android:text="Email Subject:"
android:textColor="#0F9D58" />
<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/editText3"
android:layout_alignBottom="@+id/editText3"
android:text="Email Body:"
android:textColor="#0F9D58" />
<!-- Button to send email -->
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/editText3"
android:layout_alignLeft="@+id/editText3"
android:layout_marginLeft="76dp"
android:layout_marginTop="20dp"
android:text="Send email!!" />
</RelativeLayout>
5.Update the code in Main_activit.java
package com.example.email;
import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
// define objects for edit text and button
Button button;
EditText sendto, subject, body;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Getting instance of edittext and button
sendto = findViewById(R.id.editText1);
subject = findViewById(R.id.editText2);
body = findViewById(R.id.editText3);
button = findViewById(R.id.button);
// attach setOnClickListener to button with Intent object define in it
button.setOnClickListener(view -> {
String emailsend = sendto.getText().toString();
String emailsubject = subject.getText().toString();
String emailbody = body.getText().toString();
// define Intent object with action attribute as ACTION_SEND
Intent intent = new Intent(Intent.ACTION_SEND);
// add three fields to intent using putExtra function
intent.putExtra(Intent.EXTRA_EMAIL, new String[]{emailsend});
intent.putExtra(Intent.EXTRA_SUBJECT, emailsubject);
intent.putExtra(Intent.EXTRA_TEXT, emailbody);
// set type of intent
intent.setType("message/rfc822");
// startActivity with intent with chooser as Email client using createChooser function
startActivity(Intent.createChooser(intent, "Choose an Email client :"));
});
}
}
12.Display Map based on the Current/given location.
1. Click Start →Android Studio, a Welcome to Android Studio dialog box will appear. Click New Project, the New Project Dialog box appears.
2. Choose Empty Views Activity then click Next.
3. Specify the Name of your project, Select the Language as Java, and Select the Minimum SDK as API 16 (“Jelly Bean”, Android 4.1). Click Finish Button.
4. Paste the API Key in androidmainfest.xml file. API Key Creation
Steps 1. Open a browser → type Google Cloud Console (Before doing this open your gmail account)
2. Click My Project shown in the previous screen.
3.Click New Project, It shows the project name, organization name etc. Fill the required details and click create
4.Click navigation menu(that is three lines shown in below figure) → APIs & Services → Credentials
5.Click Create Credentials→ API key.
6.The API key created dialog box appears with API Key. Copy the key and paste it into AndroidManifest.xml file
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Map"
tools:targetApi="31">
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="AIzaSyChETfLHGTIazxOUg38knvxvbQbKA9q_O8" />
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
7.Right click App→New→Google→Google Maps Views Activity. The New Android Activity dialog box appears, Tick the Launcher Activity then click Finish. Change the following code in MapsActivity.java
package com.example.map;
import androidx.fragment.app.FragmentActivity;
import android.os.Bundle;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import com.example.hhh.databinding.ActivityMapsBinding;
public class MapsActivity extends FragmentActivity implements OnMapReadyCallback
{
private GoogleMap mMap;
private ActivityMapsBinding binding;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
binding = ActivityMapsBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
// Obtain the SupportMapFragment and get notified when the map is ready to be
used.
SupportMapFragment mapFragment = (SupportMapFragment)
getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
// Add a marker in Sydney and move the camera
LatLng B = new LatLng(12, 77);
mMap.addMarker(new MarkerOptions().position(B).title("Marker in
Bangalore"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(B));
}
}
13.Create a sample application with login module(check user name and password) On successful login change Textview “Login Successful”. On login fail alert using Toast “login fail”
"SAME AS 3RD PROGRAM"
14.Learn to deploy Android applications. .
Steps to Deploy an Android Application
1. Prepare App (use Program 1 Hello world for this program)
Optimize performance and test thoroughly.
Ensure compatibility with various devices.
activity_main.xml
<?xml version="1.0" encoding="utf8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/resauto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:textSize="30sp"/>
</androidx.constraintlayout.widget.ConstraintLayout>
MainActivity.java
package com.bca.helloworld;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity
{
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
2. Generate Signed APK (Android Package Kit):
In Android Studio, navigate to Build > Generate Signed Bundle/APK.
Follow the prompts to create a new keystore or use an existing one. A keystore is a
binary file that contains a set of private keys.
Configure the build type (release) and signing configuration.
Generate the signed APK file.
3. Test Your Signed APK:
Before distributing your app, test the signed APK to ensure that the signing process
didn't introduce any issues.
Install the APK on various devices and perform thorough testing.
Release on Google Play Console:
Sign in to the Google Play Console (https://play.google.com/apps/publish).
Create a new app entry if this is your first release or select an existing app.
Complete all the required information for the app listing, including the title, description,
screenshots, and categorization.
Upload your signed APK file.
Set pricing and distribution options.
Optimize your store listing for search and conversion.
Once everything is set, click the "Publish" button to release your app to the Google Play
Store.
5. Other Distribution Channels (Optional):
Besides Google Play, you can distribute your app through other channels such as
Amazon Appstore, Samsung Galaxy Store, or thirdparty app marketplaces.
Each distribution channel may have its own requirements and submission process, so
be sure to follow their guidelines.
6. Monitor and Update:
Keep an eye on user feedback and app performance metrics through the Google Play
Console.
Regularly update your app to fix bugs, add new features, and improve user experience
based on feedback.
.
Comments
Post a Comment