KEMBAR78
Android Lab | PDF | Android (Operating System) | Computer File
0% found this document useful (0 votes)
14 views27 pages

Android Lab

The document outlines the system requirements and installation process for Android Studio, the official IDE for Android app development. It details the project structure of an Android application, including the various folders such as Manifests, Java, res, and Gradle Scripts, along with sample code for creating applications. Additionally, it provides step-by-step instructions for several experiments, demonstrating how to create simple Android applications using different components and intents.

Uploaded by

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

Android Lab

The document outlines the system requirements and installation process for Android Studio, the official IDE for Android app development. It details the project structure of an Android application, including the various folders such as Manifests, Java, res, and Gradle Scripts, along with sample code for creating applications. Additionally, it provides step-by-step instructions for several experiments, demonstrating how to create simple Android applications using different components and intents.

Uploaded by

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

Android Programming

Laboratory

DEPARTMENT OF
COMPUTER SCIENCE AND ENGINEERING
RAGEEV GANDHI MEMORIAL COLLEGE OF ENGINEERING &
TECHNOLOGY
System Requirements to install Android Studio

➢ The following are the system requirements for Android Studio on Windows.
o 64-bit Microsoft® Windows® 8/10/11
o x86_64 CPU architecture; 2nd generation Intel Core or newer, or AMD CPU with
support for a Windows Hypervisor
o 8 GB RAM or more
o 8 GB of available disk space minimum (IDE + Android SDK + Android Emulator)
o 1280 x 800 minimum screen resolution

Installation of Android Studio

Project Structure in Android Application:

Android Project Folder Structure

➢ JetBrains community developed Android Studio, the official IDE (Integrated Development Environment) for
Android app development and is freely distributed by Google.
➢ After the complete Android Architecture setup, we can construct an Android application in the studio. For
each sample application, we should establish a new project and learn the folder structure.
➢ After setting up an Android development environment in Android Studio, we can create an example
application, and our project folder structure will look like this.
➢ The structure of the Android project on disk can differ from the above picture. Select Project from the
Project selection instead of Android to see the Project's actual file structure.
➢ Many app modules, source code files, and resource files are included in the Android project. We'll go
through all of the Android app's directories and files.

➢ Manifests Folder
➢ Java Folder
➢ res (Resources) Folder
➢ Drawable Folder
➢ Layout Folder
➢ Mipmap Folder
➢ Values Folder
➢ Gradle Scripts
Manifests Folder
➢ This folder includes the AndroidManifest.xml, which we will use to create the Android application. This file
holds information about our programs, such as the Android versions, metadata, the states packages for
the java code, and other app components. It functions as a bridge between the Android operating system
and our application.
Let's see the manifests folder structure of the Android application shown below.

AndroidManifest.xml

XML code:
<? xml version="1.0" encoding="utf-8" ?>
< manifest xmlns:android = "http:// schemas.android.com/apk/res/android"
Package = "com.geeksforgeeks.myapplication" >

< application
android:allowBackup = "true"
android:icon = "@mipmap/ic_launcher"
android:label = "@string/app_name"
android:roundIcon = "@mipmap/ic_launcher_round"
android:supportsRtl = "true"
android:theme = "@style/AppTheme">
< activity android:name = ".MainActivity" >
< intent-filter >
< action android:name = "android.intent.action.MAIN" />

< category android:name = "android.intent.category.LAUNCHER" />


</ intent-filter >
</ activity >
</ application >
</ manifest >
Java folder
➢ The Java folder holds all of the java and Kotlin source code (.java) files created during app development, as
well as additional Test files. When we begin a fresh Java project, the class file MainActivity.java is
automatically produced under the package name "com.example.myapplication1" as seen here.

Java Code
package com.example.myapplication1;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate ( Bundle savedInstanceState )
{
super.onCreate ( savedInstanceState ) ;
setContentView ( R.layout.activity_main) ;
}
}
Kotlin Code
package com.example.myapplication1
import androidx.appcompat.app.AppCompatActivity import android.os.Bundle
class MainActivity : AppCompatActivity ( ) {
override fun onCreate ( savedInstanceState : Bundle ? )
{
super.onCreate ( savedInstanceState )
setContentView ( R.layout.activity_main )
}
}

Folder res/mipmap

➢ This section includes launcher.xml files that specify the icons on the home screen. It has several icon
densities based on the device size, such as hdpi, mdpi, and xhdpi.
Folder res/values

➢ The Values folder contains various XML files such as strings, dimensions, colors, and style definitions. The
strings.xml file, which includes the resources, is one of the most crucial.
XML Code

< resources >


< string name = "app_name"> NameOfTheApplication </string>
< string name = "checked" > Checked </ string >
< string name = "unchecked" > Unchecked </ string >
</ resources >
Gradle Scripts directory
➢ Gradle is an automated build system that includes several files that create a build configuration.
Buildscripts are used in the build.gradle (Project), and plugins and implementations are used in the
build.gradle (Module) to make settings that may be used by all of our application modules.
EXPERIMENTS:

1 a) Create an android application to display RGMCET Text Message.

b) Create an android application to display RGMCET Message by using Button.

Experminet1: Create android application to display RGMCET Text Message

Step By Step Process:

Activity_main.xml

<?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:layout_width="match_parent"

android:layout_height="match_parent"

android:paddingBottom="16dp"

android:paddingLeft="16dp"

android:paddingRight="16dp"

android:paddingTop="16dp"

tools:context=".MainActivity">

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"

android:layout_marginTop="78dp"

android:id="@+id/tv1"

android:textSize="18sp"

android:textStyle="bold" />

</RelativeLayout>

MainActivity.java

===============

package com.rgmcet.practicle1_1;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

TextView txt1=(TextView) findViewById(R.id.tv1);

txt1.setText("Welcome to Our college of RGMCET");

}
Experminet2: Create an android application to display RGMCET Message by using Button

Step By Step Process:

Activity_main.xml:

<?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:layout_width="match_parent"

android:layout_height="match_parent"

tools:context=".MainActivity">

<TextView

android:id="@+id/textboxid"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Welcome to Android"

android:layout_alignParentTop="true"

android:layout_centerHorizontal="true"

android:layout_marginTop="61dp"

android:ems="10"

tools:layout_editor_absoluteX="84dp"

tools:layout_editor_absoluteY="53dp" />
<Button

android:id="@+id/buttonid"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_below="@id/textboxid"

android:layout_centerHorizontal="true"

android:layout_marginTop="109dp"

android:text="ClickMe"

tools:layout_editor_absoluteX="148dp"

tools:layout_editor_absoluteY="266dp" />

</RelativeLayout>

MainActivity.java

==============

package com.rgmcet.practicle2;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

import android.widget.TextView;

public class MainActivity extends AppCompatActivity {

//step1:Creating variables for textview & button


TextView mytext;

Button mybutton;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

//Step2: link Created variables with Ref.ID

mytext=(TextView) findViewById(R.id.textboxid);

mybutton=(Button) findViewById(R.id.buttonid);

//step3:create action for button click

mybutton.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View view) {

mytext.setText("Welcome to RGM College");

});

Experminet3: Create an android application to call different activities by using


Implicit and Explicit Intents.

Step By Step Process:

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:layout_width="match_parent"

android:layout_height="match_parent"

tools:context=".MainActivity"

android:gravity="center"

android:orientation="vertical"

android:padding="20dp">

<EditText

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:hint="Enter URL"

android:id="@+id/et_url"/>

<Button

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Click Me"

android:id="@+id/btn_openurl"/>
</LinearLayout>

MainActivity.java:

package com.rgmcet.practicle3;

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 et_url;

Button btn_openurl;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);
et_url=(EditText) findViewById(R.id.et_url);

btn_openurl=(Button) findViewById(R.id.btn_openurl);

btn_openurl.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View view) {

String url=et_url.getText().toString();

Intent intent=new Intent(Intent.ACTION_VIEW, Uri.parse(url));

startActivity(intent);

});

Experminet 4: Create an android application using explicit Intent

Step By Step Process:

Android_main_activityone.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:layout_height="match_parent"
tools:context=".MainActivityone"

android:gravity="center"

android:orientation="vertical"

android:padding="20dp">

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="First Activity"

android:textSize="30sp"

android:textStyle="bold"/>

<Button

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginTop="20dp"

android:text="Open Second Activity"

android:id="@+id/btn_one"/>

</LinearLayout>

Android_main_activitytwo.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:layout_height="match_parent"

tools:context=".MainActivitytwo"

android:gravity="center"

android:orientation="vertical"

android:padding="20dp">

<TextView

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Second Activity"

android:textSize="30sp"

android:textStyle="bold"/>

<Button

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:layout_marginTop="20dp"

android:text="Open First Activity"

android:id="@+id/btn_two"/>

</LinearLayout>

MainActivityone.java

package com.rgmcet.practicle3_1;

import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

public class MainActivityone extends AppCompatActivity {

Button btn_one;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main_activityone);

btn_one=(Button) findViewById(R.id.btn_one);

btn_one.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View view) {

Intent intent=new
Intent(getApplicationContext(),MainActivitytwo.class);

startActivity(intent);

});

MaintActivitytwo.java
package com.rgmcet.practicle3_1;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;

import android.os.Bundle;

import android.view.View;

import android.widget.Button;

public class MainActivitytwo extends AppCompatActivity {

Button btn_two;

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main_activitytwo);

btn_two=(Button) findViewById(R.id.btn_two);

btn_two.setOnClickListener(new View.OnClickListener() {

@Override

public void onClick(View view) {

Intent intent=new
Intent(getApplicationContext(),MainActivityone.class);

startActivity(intent);

});

}
Experminet 3A: Create an android application to select item from given list by using
AutoCompleteTextView (ACTV)

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:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="16dp"
tools:context=".MainActivity">
<AutoCompleteTextView
android:id="@+id/actv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="select a country"
android:textStyle="bold"
android:completionThreshold="1"
android:dropDownAnchor="@+id/tv1"
android:completionHint="select a country"/>
<TextView
android:id="@+id/tv1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="COUNTRIES"
android:textSize="20sp"
android:paddingBottom="10dp"/>
</LinearLayout>
MainActivity.java

package com.rgmcet.autocompletetextviewexample;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.AutoCompleteTextView;
public class MainActivity extends AppCompatActivity {
private static final String[] COUNTRIES=new String[]{
"India","China","America","Argentina","Afghanistan","Algeria","sri
lanka","Pakistan"
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
AutoCompleteTextView editText=findViewById(R.id.actv);
ArrayAdapter<String> adapter=new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1,COUNTRIES);
editText.setAdapter(adapter);

}
}

Experiment 3B:- Create an android application to display dropdown menu items and
pick one item by using Spinner Component
Activity_main.xml

<?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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<Spinner
android:id="@+id/spn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"/>
</RelativeLayout>

Create one resource file for spinner content in the path of:
res==>values==>string.xml
<resources>
<string name="app_name">Spinner</string>
<string-array name="spinnerlist">
<item>Select a Language</item>
<item>C++</item>
<item>Java</item>
<item>PHP</item>
<item>Python</item>
<item>Android</item>
</string-array>
</resources>
MainActivity.java
package com.rgmcet.spinner;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
Spinner spn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
spn=findViewById(R.id.spn);

ArrayAdapter<CharSequence>adapter=ArrayAdapter.createFromResource
(this,R.array.spinnerlist, android.R.layout.simple_spinner_item);

adapter.setDropDownViewResource(android.R.layout.simple_dropdown_i
tem_1line);
spn.setAdapter(adapter);
spn.setOnItemSelectedListener(new
AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View
view, int i, long l) {
String data=adapterView.getItemAtPosition(i).toString();

Toast.makeText(getApplicationContext(),data,Toast.LENGTH_SHORT).sho
w();
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
});
}
}
Practical 5: Create an android application to display WhatsApp videos in grid view by
using Custom Adapter

Practical 6: Create an android application to display webpage by using Web view


Component

Activity_main.xml:

<?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:layout_width="match_parent"

android:layout_height="match_parent"

tools:context=".MainActivity">

<WebView

android:id="@+id/wView"

android:layout_width="match_parent"

android:layout_height="match_parent"/>

<ProgressBar

android:id="@+id/pgBar"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:visibility="gone"
android:layout_centerInParent="true"/>

</RelativeLayout>

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:supportsRtl="true"

android:theme="@style/Theme.Webview"

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>

MainActivity.java

package com.rgmcet.webview;
import androidx.appcompat.app.AppCompatActivity;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.View;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;
public class MainActivity extends AppCompatActivity {
WebView wView;
ProgressBar pgBar;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

wView=findViewById(R.id.wView);
pgBar=findViewById(R.id.pgBar);

wView.loadUrl("https://www.google.com");

wView.setWebViewClient(new WebViewClient(){
@Override
public void onPageStarted(WebView view, String url, Bitmap
favicon) {
pgBar.setVisibility(View.VISIBLE);
super.onPageStarted(view, url, favicon);
}
@Override
public void onPageFinished(WebView view, String url) {
pgBar.setVisibility(View.GONE);
super.onPageFinished(view, url);
}
});
}
@Override
public void onBackPressed() {
if(wView.canGoBack()){
wView.goBack();
}else{
super.onBackPressed();
}
}
}

Practical 7: Create an android application to display different webpages in fragments


by using Fragments Component

Practical 8: Create an android application to store the data by using Shared


Preferences

Shared Preferences:

➢ One of the way to store data in in android


➢ It saves and retrieves data in the form of key & value pair
Practical 18: Create an android application to display different Dialog Boxes.

Alert Dialogbox:

➢ They are used to help users answer questions, make selections,confirm actions,
and read warning or error messages
➢ It is a window that partially obscures the activity that launched it.

You might also like