Android with index
Android with index
KALYAN
CERTIFICATE
This is to certify that Mr./Ms. Exam Seat
No has satisfactorily completed the Journal on
for partial fulfillment of the 3
year Full Time Course Bachelor of Computer Science (SEM-IV) of the University of Mumbai
for the year 2022-2023.
1.
Program1.A) write a program using kotlin to
implement control structures and loops Using if-else
statement
Program 1.B) Write a program to implement object-
oriented concepts in Kotlin.
2.
Program 2.i) Create an Android application to design
screens using different layouts and UI including
Button, Edittext, Textview, Radio Button
Program 2.ii) Write an android application
demonstrating response to event/user interaction for
a. Checkbox b. Radio button c. Button d. Spinner
3.
Program 3(i)-Create an application to create Image
Flipper and Image Gallery. On click on the image
display the information about the image.
Program 3(ii)- Create an application to use Gridview
for shopping cart application
4.
Program 4(i)a-Create an Android application to
demonstrate implicit and explicit intents
Program 4(ii)-Create an application to demonstrate
shared preferences
5.
Program 5(i)-Create an Android application
to demonstrate the use of Broadcast listeners.
7.
Program 7(i)- Create a media player application in
android that plays audio. Implement play, pause, and
loop features
Program 7(ii)-Create an Android application to use a
camera and capture image/video and display them on
the screen.
8.
Program 8(i)-Create an android application to
implement Asynctask and threading concepts
Program 8(ii)- Create an Android application to
demonstrate the different types of menus. a. Pop-up
Menu b. Context Menu c. Option Menu
9.
Program 9) Create an Android application to record
the current location. Based on the current location
allow the user to use some useful
services/applications
10.
Program 10) Create a suitable Android application to
store and retrieve data in the SQLite database.
At the time of writing the latest stable Kotlin release was version 1.2.61 .
Next, we need to configure the PATH environment variable so we can run Kotlin from a command prompt.
Select the PATH variable. Click on Edit….
Click on New and type “%KOTLIN_HOME%\bin” as shown below.
Click OK .
Click OK once more to close the environment variables window.
On Windows 7 you cannot add extra values for an existing Path variable. You need to append
“;%KOTLIN_HOME%\bin” at the end of the variable value instead.
PROGRAM 1 A: write a program using kotlin to implement control structures and loops
if (number > 0) {
print("Positive number")
} else {
print("Negative number")
}
Output :
If-elseif ladder:
println("number is $result")
}
Output:
Nested if statements:
println("max = $max")
}
Output:
When statement:
}
Output:
Using readline for talking input at runtime
val a = 12
val b = 5
println("result = $result")
}
Output:
While loop:
var sum = 0
var i = 100
while (i != 0) {
sum += i // sum = sum + i;
--i
}
println("sum = $sum")
}
Output:
Do-while loop:
do {
print("Enter an integer: ")
input = readLine()!!
sum += input.toInt()
println("sum = $sum")
}
Output:
println()
println()
println()
Program 1B:
-------------------------------------------------------------------------------------------------------------
class Lamp {
// member function
fun turnOn() {
isOn = true
}
// member function
fun turnOff() {
isOn = false
}
fun displayLightStatus() {
if (isOn == true)
println("lamp is on.")
else
println("lamp is off.")
}
}
Output:
-----------------------------------------------------------------------------------------
For best results check compatibility of your android API with minimum SDK
Use android 12 with API 31 in DEVICE MANAGER While creating AVD
Use android 11 with SDK 4.2 and API 30
Program 2(i)-
Create an Android application to design screens using different layouts and UI including Button, Edittext,
Textview, Radio Button
<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" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#4CAF50"
android:paddingStart="10dp"
android:paddingEnd="10dp"
android:text="@string/btn"
android:textColor="@android:color/background_light"
android:textSize="24sp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
Now After That Add the Following Program in Main Activity File i.e Mainactivity.kt file
package com.example.sycspractical2ia
import android.os.Bundle
import android.widget.Button
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.example.sycspractical2a.R
// operations to be performed
// when user tap on the button
button?.setOnClickListener()
{
// displaying a toast message
Toast.makeText(this@MainActivity, R.string.message, Toast.LENGTH_LONG).show() }
}
}
<resources>
<string name="app_name">SYCSpractical2a</string>
<string name="btn">Button</string>
<string name="message">Hello students ,This is a Button.</string>
</resources>
Now before running the Program Add The Following Code to the AndroidManifest.xml file
Check before making changes if your androidmanisfest.xml looks like this don’t make any
unnecessary changes
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@drawable/ic_launcher_background"
android:label="@string/app_name"
android:roundIcon="@drawable/ic_launcher_background"
android:supportsRtl="true"
android:theme="@style/Theme.SYCSPractical2ia"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</manifest>
OUTPUT:-
Program 2(i)B-Program For EditText
Add the following code in Activity_main.xml file -
<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
android:hint="Input"
android:inputType="text"/>
<Button
android:id="@+id/showInput"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="show"
android:backgroundTint="@color/colorPrimary"
android:textColor="@android:color/white"
/>
</LinearLayout>
package com.example.sycspractical2ib
import android.annotation.SuppressLint
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.widget.Button
import android.widget.EditText
import android.widget.Toast
import com.example.sycspractical2aii.R
class MainActivity : AppCompatActivity() {
@SuppressLint("MissingInflatedId")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
Before Runing The Program add the following Code To AndroidManifest.xml File:-
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@drawable/ic_launcher_background"
android:label="@string/app_name"
android:roundIcon="@drawable/ic_launcher_background"
android:supportsRtl="true"
android:theme="@style/Theme.SYCSPractical2ib"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</manifest>
==============================================================
OUTPUT:-
Program 2(i)c-Program For TextView
package com.example.sycspractical2ic
import 25ndroid.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.TextView
import android.widget.Toast
<resources>
<string name=“app_name”>SYCSPractical2ic</string>
<string name=“text_view”>www.profajaypashankar.com</string>
<string name=“text_on_click”>COMPUTER SCIENCE PORTAL</string>
</resources>
Now Add The Following Code to AndroidManifest.xml File-
<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.SYCSPractical2ic”
tools:targetApi=“31”>
<activity
android:name=“.MainActivity”
android:exported=“true”>
<intent-filter>
<action android:name=“android.intent.action.MAIN” />
</manifest>
OUTPUT:-
You can run this code by adding show.button onclicklistener .
<TextView
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:text=“@string/select_your_subject”
android:textStyle=“bold”
android:layout_marginStart=“10dp”
android:textSize=“20sp”/>
<RadioButton
android:layout_width=“fill_parent”
android:layout_height=“wrap_content”
android:id=“@+id/radia_id2”
android:text=“@string/c_c_programming”
android:textSize=“20sp”/>
<RadioButton
android:layout_width=“fill_parent”
android:layout_height=“wrap_content”
android:id=“@+id/radia_id3”
android:text=“@string/data_structure”
android:textSize=“20sp”/>
<RadioButton
android:layout_width=“fill_parent”
android:layout_height=“wrap_content”
android:id=“@+id/radia_id4”
android:text=“@string/algorithms”
android:textSize=“20sp”/>
</RadioGroup>
</RelativeLayout>
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.view.View
import android.widget.Button
import android.widget.RadioButton
import android.widget.RadioGroup
import android.widget.Toast
<resources>
<string name=“app_name”>SYCSPractical2id</string>
<string name=“select_your_subject”>Select your Subject ?</string>
<string name=“dbms”>DBMS</string>
<string name=“c_c_programming”>C/C++ Programming</string>
<string name=“data_structure”>Data Structure</string>
<string name=“algorithms”>Algorithms</string>
<string name=“submit”>Submit</string>
<string name=“clear”>Clear</string>
</resources>
OUTPUT:-
Program 2(ii)-
Write an android application demonstrating response to event/user interaction for
a. Checkbox
b. Radio button
c. Button
d. Spinner
<TextView
android:id=“@+id/textView”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:fontFamily=“@font/roboto”
android:text=“@string/Heading”
android:textAlignment=“center”
android:textColor=“@android:color/holo_green_dark”
android:textSize=“36sp”
android:textStyle=“bold”
app:layout_constraintBottom_toBottomOf=“parent”
app:layout_constraintEnd_toEndOf=“parent”
app:layout_constraintStart_toStartOf=“parent”
app:layout_constraintTop_toTopOf=“parent”
app:layout_constraintVertical_bias=“0.17000002” />
<LinearLayout
android:id=“@+id/32ndroid32_container”
android:layout_width=“0dp”
android:layout_height=“wrap_content”
android:orientation=“vertical”
app:layout_constraintBottom_toBottomOf=“parent”
app:layout_constraintEnd_toEndOf=“parent”
app:layout_constraintStart_toStartOf=“parent”
app:layout_constraintTop_toBottomOf=“@+id/textView”
app:layout_constraintVertical_bias=“0.18”>
<CheckBox
android:id=“@+id/32ndroid32“
android:layout_width=“match_parent”
android:layout_height=“wrap_content”
android:fontFamily=“@font/roboto”
android:text=“@string/checkBox1_text”
android:textSize=“18sp”
android:padding=“7dp”/>
<CheckBox
android:id=“@+id/checkBox2”
android:layout_width=“match_parent”
android:layout_height=“wrap_content”
android:fontFamily=“@font/roboto”
android:text=“@string/checkBox2_text”
android:textSize=“18sp”
android:padding=“7dp”/>
<CheckBox
android:id=“@+id/checkBox3”
android:layout_width=“match_parent”
android:layout_height=“wrap_content”
android:fontFamily=“@font/roboto”
android:text=“@string/checkBox3_text”
android:textSize=“18sp”
android:padding=“7dp”/>
<CheckBox
android:id=“@+id/checkBox4”
android:layout_width=“match_parent”
android:layout_height=“wrap_content”
android:fontFamily=“@font/roboto”
android:text=“@string/checkBox4_text”
android:textSize=“18sp”
android:padding=“7dp”/>
<CheckBox
android:id=“@+id/checkBox5”
android:layout_width=“match_parent”
android:layout_height=“wrap_content”
android:fontFamily=“@font/roboto”
android:text=“@string/checkBox5_text”
android:textSize=“18sp”
android:padding=“7dp”/>
</LinearLayout>
<Button
android:id=“@+id/submitButton”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:background=“#AB4CAF50”
android:fontFamily=“@font/roboto”
android:text=“@string/submitButton”
android:textSize=“18sp”
android:textStyle=“bold”
app:layout_constraintBottom_toBottomOf=“parent”
app:layout_constraintEnd_toEndOf=“parent”
app:layout_constraintStart_toStartOf=“parent”
app:layout_constraintTop_toBottomOf=“@+id/33ndroid33_container”
app:layout_constraintVertical_bias=“0.23000002” />
</33ndroid.constraintlayout.widget.ConstraintLayout>
package com.example.sycspractical2iia
import android.os.Build.VERSION_CODES.R
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.widget.Button
import android.widget.Toast
// Actions to be performed
// when Submit button is clicked
button.setOnClickListener{
<resources>
<string name=“app_name”>SYCSPractical2iia</string>
<string name=“Heading”>Services provided by GeeksforGeeks</string>
<string name=“checkBox1”>Coding contests</string>
<string name=“checkBox2_text”>Civil Engineering Courses</string>
<string name=“checkBox1_text”>Coding Contests</string>
<string name=“checkBox3_text”>Computer Science Courses</string>
<string name=“checkBox4_text”>Company specific coding questions</string>
<string name=“checkBox5_text”>Download movies</string>
<string name=“submitButton”>SUBMIT</string>
</resources>
OUTPUT:-
Program 2(ii)b -Program For RadioButton
<TextView
android:id=“@+id/title”
android:layout_width=“match_parent”
android:layout_height=“wrap_content”
android:text=“Which is your favorite color?”
android:textStyle=“bold”
android:textSize=“20sp”/>
<RadioButton
android:id=“@+id/red”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:text=“RED”
android:onClick=“radio_button_click”/>
<RadioButton
android:id=“@+id/green”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:text=“GREEN”
android:onClick=“radio_button_click”/>
<RadioButton
android:id=“@+id/yellow”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:text=“YELLOW”
android:onClick=“radio_button_click”/>
<RadioButton
android:id=“@+id/pink”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:text=“PINK”
android:onClick=“radio_button_click”/>
</RadioGroup>
<Button
android:id=“@+id/button”
android:layout_width=“wrap_content”
android:layout_height=“wrap_content”
android:text=“Get Selected Color”/>
</LinearLayout>
Now Add The Following Program in MainActivity.kt file:-
package com.example.sycspractical2iib
import 37ndroid.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.view.View
import android.widget.*
import android.widget.RadioGroup
<resources>
<string name=“app_name”>SYCSPractical2iib</string>
<string name=“checked”>checked</string>
<string name=“unchecked”>unchecked</string>
</resources>
OUTPUT:-
Program 2(ii)c-Program For Button
</40ndroid.constraintlayout.widget.ConstraintLayout>
package com.example.sycspractical2iic
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.widget.Button
import android.widget.Toast
// operations to be performed
// when user tap on the button
button?.setOnClickListener()
{
// displaying a toast message
Toast.makeText(this@MainActivity, R.string.message, Toast.LENGTH_LONG).show() }
}
}
<resources>
<string name=“app_name”>SYCSPractical2iic</string>
<string name=“btn”>Button</string>
<string name=“message”>Hello Geeks!! This is a Button.</string>
</resources>
OUTPUT:-
Program 2(ii)d -Program For Spinner
<Spinner
android:id=“@+id/coursesspinner”
android:layout_height=“50dp”
android:layout_width=“160dp”
android:layout_marginEnd=“10dp”
android:layout_marginStart=“10dp”
android:layout_marginBottom=“10dp”
android:layout_marginTop=“10dp”
app:layout_constraintStart_toStartOf=“parent”
app:layout_constraintTop_toTopOf=“parent”/>
</android.support.constraint.ConstraintLayout>
package com.example.sycspractical2iid
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.view.View
import android.widget.AdapterView
import android.widget.AdapterView.OnItemSelectedListener
import android.widget.ArrayAdapter
import android.widget.Spinner
import android.widget.Toast
OUTPUT:-
Program 3:-
Program 3(i)-Create an application to create Image Flipper and Image Gallery. On click on the
image display the information about the image.
</RelativeLayout>
// initializing variables
// of below line with their id.
viewPager = findViewById(R.id.idViewPager)
Second Method
-------------------------------------------------------------------------------------------------------------
Firstly Add The Following Code To activity_main.xml File-
package com.example.sycspractical3i
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.provider.MediaStore
import android.support.v7.app.AppCompatActivity
import android.widget.Button
import android.widget.ImageView
OUTPUT:-
Program 3(ii)-
Create an application to use Gridview for shopping cart application
For above code addd images to res/drawable folder make sure all images are named as
refrence given in MainActivity.kt
OUTPUT:-
============================================================
Program 4:-
1)Implicit Intent
First Add The Above Code to activity_main.xml File-
<EditText
android:id="@+id/editText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/btn"
android:text="Search"
android:onClick="search"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/editText" />
</androidx.constraintlayout.widget.ConstraintLayout>
package com.example.sycspractical4i
import android.content.Intent
import android.net.Uri
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.widget.EditText
editText = findViewById(R.id.editText)
}
fun search() {
val url = editText.text.toString()
val urlIntent = Intent(Intent.ACTION_VIEW, Uri.parse(url))
startActivity(urlIntent)
}
}
OUTPUT:-
-------------------------------------------------------------------------------------------------------------
Program 4(i)b-
EXPLICIT INTENT
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Launch Second Activity"/>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
Now Create a New File named activity_main2.xml and add 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="com.example.explicitintentexample.SecondActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="This is the second activity!"
android:textSize="24sp"
android:textStyle="bold"/>
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
package com.example.explicitintentexample
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
class SecondActivity : AppCompatActivity() {
<TextView
android:id="@+id/textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="32dp"
android:text="Shared Preferences Demo"
android:textColor="@android:color/black"
android:textSize="24sp" />
<!--EditText to take the data from the user and save the data in SharedPreferences-->
<EditText
android:id="@+id/edit1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/textview"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:hint="Enter your Name"
android:padding="10dp" />
<!--EditText to take the data from the user and save the data in SharedPreferences-->
<EditText
android:id="@+id/edit2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/edit1"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="16dp"
android:hint="Enter your Age"
android:inputType="number"
android:padding="10dp" />
</RelativeLayout>
package com.example.sycspractical4ii
import android.os.Bundle
import android.widget.EditText
import androidx.appcompat.app.AppCompatActivity
// Fetch the stored data in onResume() Because this is what will be called when the app opens again
override fun onResume() {
super.onResume()
// Fetching the stored data from the SharedPreference
val sh = getSharedPreferences("MySharedPref", MODE_PRIVATE)
val s1 = sh.getString("name", "")
val a = sh.getInt("age", 0)
// write all the data entered by the user in SharedPreference and apply
myEdit.putString("name", name.text.toString())
myEdit.putInt("age", age.text.toString().toInt())
myEdit.apply()
}
}
OUTPUT:-
OUTPUT EXPLAINATION :
When user enter details and minimizes current activity tab then this edittext got reset
automatically as core concept of shared preference works.
Program 5:-
<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.support.constraint.ConstraintLayout>
package com.example.sycspractical5i
import android.content.Intent
import android.content.IntentFilter
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
receiver = AirplaneModeChangeReceiver()
After That Crate a File Named AirPlaneModeChangeReceiver.kt and Add The Following Code
to it:-
package com.example.sycspractical5i
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.widget.Toast
OUTPUT:-
activity_main.xml file-
<?xml version="1.0" encoding="utf-8"?>
<!--suppress ALL -->
<android.support.constraint.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"
android:background="#168BC34A"
tools:context=".MainActivity">
<LinearLayout
android:id="@+id/linearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:orientation="vertical"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="1.0"
tools:ignore="MissingConstraints">
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="170dp"
android:fontFamily="@font/roboto"
android:text="@string/heading"
android:textAlignment="center"
android:textAppearance="@style/TextAppearance.AppCompat.Large"
android:textColor="@android:color/holo_green_dark"
android:textSize="36sp"
android:textStyle="bold" />
<Button
android:id="@+id/startButton"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="20dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="20dp"
android:layout_marginBottom="20dp"
android:background="#4CAF50"
android:fontFamily="@font/roboto"
android:text="@string/startButtonText"
android:textAlignment="center"
android:textAppearance="@style/TextAppearance.AppCompat.Display1"
android:textColor="#FFFFFF"
android:textStyle="bold" />
<Button
android:id="@+id/stopButton"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginStart="20dp"
android:layout_marginTop="10dp"
android:layout_marginEnd="20dp"
android:layout_marginBottom="20dp"
android:background="#4CAF50"
android:fontFamily="@font/roboto"
android:text="@string/stopButtonText"
android:textAlignment="center"
android:textAppearance="@style/TextAppearance.AppCompat.Display1"
android:textColor="#FFFFFF"
android:textStyle="bold" />
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="80dp"
app:srcCompat="@drawable/banner" />
</LinearLayout>
</android.support.constraint.ConstraintLayout>
MainActivity.kt File:-
package com.example.sycspractical5ii
import android.content.Intent
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.view.View
import android.widget.Button
// assigning ID of startButton
// to the object start
start = findViewById<View>(R.id.startButton) as Button
// assigning ID of stopButton
// to the object stop
stop = findViewById<View>(R.id.stopButton) as Button
// process to be performed
// if start button is clicked
if (view === start) {
Now Create A New File named NewService.kt and Add The Code:-
package com.example.sycspractical5ii
import android.app.Service
import android.content.Intent
import android.media.MediaPlayer
import android.os.IBinder
import android.provider.Settings
Strings.xml File:-
<resources>
<string name="app_name">SYCSPractical5ii</string>
<string name="heading">Services In Android</string>
<string name="startButtonText">Start the Service</string>
<string name="stopButtonText">Stop the Service</string>
</resources>
OUTPUT:-
Program 6:-
<Button
android:id="@+id/button"
android:layout_centerInParent="true"
android:background="@color/colorPrimary"
android:textColor="#ffffff"
android:text="Let's Bounce"
android:layout_width="200dp"
android:layout_height="80dp"/>
</RelativeLayout>
MainActivity.kt File-
package com.example.sycspractical6i
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.view.animation.Animation
import android.view.animation.AnimationUtils
import android.widget.Button
<scale
android:pivotX="50%"
android:pivotY="50%"
android:fromXScale="0.5"
android:toXScale="1.0"
android:fromYScale="0.5"
android:toYScale="1.0"
android:duration="500"/>
</set>
OUTPUT:-
Program 6(ii)-Create an Android application to display canvas and allow the user to draw on
it.
activity_main.xml file -
<?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"
tools:context=".MainActivity">
<ImageView
android:id="@+id/image_view_1"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:ignore="ContentDescription"
android:background="@color/black"/>
</RelativeLayout>
MainActivity.kt File –
package com.example.sycspractical6ii
import android.annotation.SuppressLint
import android.graphics.Bitmap
import android.graphics.Canvas
import android.graphics.Color
import android.graphics.Paint
import android.os.Build
import android.os.Bundle
import android.support.annotation.RequiresApi
import android.support.v7.app.AppCompatActivity
import android.view.MotionEvent
import android.view.View
import android.widget.ImageView
@RequiresApi(Build.VERSION_CODES.R)
@SuppressLint("ClickableViewAccessibility")
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
MotionEvent.ACTION_UP -> {
upX = event.x
upY = event.y
canvas.drawLine(downX, downY, upX, upY, paint)
mImageView.invalidate()
}
}
return true
}
}
OUTPUT:-
Program 7:-
Program 7(i)-
Create a media player application in android that plays audio. Implement play, pause, and
loop features
activity_main.xml file-
<Button
android:id="@+id/pauseBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:enabled="false"
android:text="Pause"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/playBtn"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/playBtn"
android:layout_width="88dp"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text="Play"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/stopBtn"
app:layout_constraintStart_toEndOf="@+id/pauseBtn"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/stopBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginEnd="24dp"
android:layout_marginRight="24dp"
android:layout_marginTop="8dp"
android:enabled="false"
android:text="Stop"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<RelativeLayout
android:layout_width="368dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="76dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="@+id/tv_pass"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/tv_due"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true" />
<SeekBar
android:id="@+id/seek_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/tv_pass"
android:saveEnabled="false" />
</RelativeLayout>
</android.support.constraint.ConstraintLayout>
MainActivity.kt file-
package com.example.sycspractical7i
import android.media.MediaPlayer
import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.widget.Toast
import android.os.Handler
import android.widget.SeekBar
mediaPlayer = MediaPlayer.create(applicationContext,R.raw.school_bell)
mediaPlayer.start()
Toast.makeText(this,"media playing",Toast.LENGTH_SHORT).show()
}
initializeSeekBar()
playBtn.isEnabled = false
val pauseBtn = null
pauseBtn.isEnabled = true
val stopBtn = null
stopBtn.isEnabled = true
mediaPlayer.setOnCompletionListener {
playBtn.isEnabled = true
val pauseBtn = null
pauseBtn.isEnabled = false
val stopBtn = null
stopBtn.isEnabled = false
Toast.makeText(this,"end",Toast.LENGTH_SHORT).show()
}
}
// Pause the media player
val pauseBtn = null
pauseBtn.setOnClickListener {
if(mediaPlayer.isPlaying){
mediaPlayer.pause()
pause = true
playBtn.isEnabled = true
pauseBtn.isEnabled = false
val stopBtn = null
stopBtn.isEnabled = true
Toast.makeText(this,"media pause",Toast.LENGTH_SHORT).show()
}
}
// Stop the media player
val stopBtn = null
stopBtn.setOnClickListener{
if(mediaPlayer.isPlaying || pause.equals(true)){
pause = false
val seek_bar = null
seek_bar.setProgress(0)
mediaPlayer.stop()
mediaPlayer.reset()
mediaPlayer.release()
handler.removeCallbacks(runnable)
playBtn.isEnabled = true
pauseBtn.isEnabled = false
stopBtn.isEnabled = false
val tv_pass = null
tv_pass.text = ""
val tv_due = null
tv_due.text = ""
Toast.makeText(this,"media stop",Toast.LENGTH_SHORT).show()
}
}
// Seek bar change listener
val seek_bar = null
seek_bar.setOnSeekBarChangeListener(object : SeekBar.OnSeekBarChangeListener {
override fun onProgressChanged(seekBar: SeekBar, i: Int, b: Boolean) {
if (b) {
mediaPlayer.seekTo(i * 1000)
}
}
runnable = Runnable {
seek_bar.progress = mediaPlayer.currentSeconds
handler.postDelayed(runnable, 1000)
}
handler.postDelayed(runnable, 1000)
}
}
@JvmName("setProgress")
private fun Nothing?.setProgress(i: Int) {
TODO("Not yet implemented")
}
// Creating an extension property to get the media player time duration in seconds
val MediaPlayer.seconds:Int
get() {
return this.duration / 1000
}
// Creating an extension property to get media player current position in seconds
val MediaPlayer.currentSeconds:Int
get() {
return this.currentPosition/1000
}
OUTPUT:-
Program 7(ii)-Create an Android application to use a camera and capture image/video and
display them on the screen.
activity_main.xml File-
<RelativeLayout xmlns:androclass="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
androclass:layout_height="match_parent"
androclass:layout_width="match_parent"
tools:ignore="NamespaceTypo">
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="Take a Photo"
androclass:layout_height="match_parent"
androclass:layout_width="match_parent">
</Button>
<ImageView
android:id="@+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@+id/button1"
android:layout_alignParentTop="true"
android:src="@drawable/ic_launcher"
androclass:layout_height="match_parent"
androclass:layout_width="match_parent"
tools:ignore="NotSibling"
androclass:contentDescription="TODO">
</ImageView>
</RelativeLayout>
MainActivity.kt file:-
package com.example.sycspractical7ii
import android.annotation.SuppressLint
import android.app.Activity
import android.content.Intent
import android.graphics.Bitmap
import android.os.Bundle
import android.provider.MediaStore
import android.view.Menu
import android.view.View
import android.widget.Button
import android.widget.ImageView
companion object {
private const val CAMERA_REQUEST = 1888
}
}
OUTPUT:-
-------------------------------------------------------------------------------------------------------------
Program 8:-
activity_main.xml File-
MainActivity.kt file-
package com.example.myapplication
import android.app.ProgressDialog
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.net.wifi.WifiConfiguration.AuthAlgorithm.strings
import android.os.AsyncTask
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.widget.Button
import android.widget.ImageView
import java.io.IOException
import java.io.InputStream
import java.net.HttpURLConnection
import java.net.URL
OUTPUT:-
Program 8(ii)-
Create an Android application to demonstrate the different types of menus.
a. Pop-up Menu
b. Context Menu
c. Option Menu
Activity_main.xml File-
<Button
android:id="@+id/clickBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#0F9D58"
android:text="Click Me"
android:textColor="#ffffff"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
MainActivity.kt File:-
package com.example.sycspractical8iia
import android.os.Bundle
import android.widget.Button
import android.widget.PopupMenu
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
Now Crate a New Directory ‘Menu’ And Then Create a File named popup_menu.xml and add
the code:-
<item
android:id="@+id/kotlin"
android:title="Kotlin" />
<item
android:id="@+id/android"
android:title="Android" />
<item
android:id="@+id/react_native"
android:title="React Native" />
</menu>
OUTPUT:-
Program 8(ii)b-Program For ContextMenu
activity_main.xml File-
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:text="Long press me!"
android:textColor="#000"
android:textSize="20sp"
android:textStyle="bold" />
</RelativeLayout>
MainActivity.kt fille-
package com.example.sycspractical8iib
import android.graphics.Color
import android.os.Bundle
import android.view.ContextMenu
import android.view.ContextMenu.ContextMenuInfo
import android.view.MenuItem
import android.view.View
import android.widget.RelativeLayout
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
// Link those objects with their respective id's that we have given in .XML file
textView = findViewById(R.id.textView)
relativeLayout = findViewById(R.id.relLayout)
// here you have to register a view for context menu you can register any view
// like listview, image view, textview, button etc
registerForContextMenu(textView)
}
OUTPUT:-
-------------------------------------------------------------------------------------------------------------
Program 8(ii)c-Program For Option Menu
activity_main.xml file-
<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.support.constraint.ConstraintLayout>
MainActivity.kt file-
package com.example.sycspractical8iic
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.view.Menu
import android.view.MenuItem
import android.widget.Toast
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
}
override fun onCreateOptionsMenu(menu: Menu?): Boolean {
menuInflater.inflate(R.menu.menu,menu)
return super.onCreateOptionsMenu(menu)
}
override fun onOptionsItemSelected(item: MenuItem): Boolean {
when (item.itemId){
R.id.about -> Toast.makeText(this,"About Selected",Toast.LENGTH_SHORT).show()
R.id.settings -> Toast.makeText(this,"Settings Selected",Toast.LENGTH_SHORT).show()
R.id.exit -> Toast.makeText(this,"Exit Selected",Toast.LENGTH_SHORT).show()
}
return super.onOptionsItemSelected(item)
}
}
Now Create a New Directory “Menu” in res Folder and Create file Named menu.xml and Add
The Code-
OUTPUT:-
Program 9- Create an Android application to record the current location. Based on the current
location allow the user to use some useful services/applications
Activity_main.xml File-
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="30dp">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.AppCompat.Title"
android:text="Current Location:"
/>
<TextView
android:id="@+id/tvLatitude"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
android:layout_marginTop="20dp"
android:text="Latitude: -"
/>
<TextView
android:id="@+id/tvLongitude"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
android:layout_marginTop="10dp"
android:text="Longitude: -"
/>
<TextView
android:id="@+id/tvProvider"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
android:layout_marginTop="10dp"
android:text="Provider: -"
/>
<Button
android:id="@+id/btOpenMap"
android:layout_width="150dp"
android:layout_height="wrap_content"
android:background="@color/colorAccent"
android:text="Open Map"
android:textColor="@android:color/white"
android:layout_marginTop="30dp"
android:visibility="gone"
/>
</LinearLayout>
<Button
android:id="@+id/btGetLocation"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
android:layout_margin="30dp"
android:text="Get Current Location"
android:textColor="@android:color/white"
android:layout_alignParentBottom="true"
/>
</RelativeLayout>
MainActivity.kt File-
package com.example.sycspractical9
import android.Manifest
import android.content.Intent
import android.content.pm.PackageManager
import android.net.Uri
import android.os.Bundle
import android.support.v4.app.ActivityCompat
import android.support.v7.app.AppCompatActivity
import android.view.View
import android.widget.Toast
import com.google.android.gms.location.FusedLocationProviderClient
import kotlinx.android.synthetic.main.activity_main.*
locationService = LocationService(this)
requestPermissions()
}
companion object {
private const val REQUEST_LOCATION_PERMISSION = 1
}
}
androidmanifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
package="com.example.locationactivity">
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<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"
android:exported="true"
tools:ignore="MissingClass">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<service android:name=".LocationService"
tools:ignore="MissingClass" />
</application>
</manifest>
Activity_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"
tools:context=".MainActivity">
<Button
android:id="@+id/stop_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Stop Location Updates"
android:layout_centerInParent="true" />
</RelativeLayout>
Style.xml
<resources>
<!-- Base application theme. -->
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<!-- Customize your theme here. -->
<item name="colorPrimary">@color/colorPrimary</item>
<item name="colorPrimaryDark">@color/colorPrimaryDark</item>
<item name="colorAccent">@color/colorAccent</item>
</style>
</resources>
import android.Manifest
import android.app.Service
import android.content.Context
import android.content.Intent
import android.content.pm.PackageManager
import android.location.Location
import android.location.LocationListener
import android.location.LocationManager
import android.os.Bundle
import android.os.IBinder
import android.util.Log
import androidx.core.app.ActivityCompat
import java.io.File
fun startLocationUpdates() {
locationManager = context.getSystemService(Context.LOCATION_SERVICE) as LocationManager
if (ActivityCompat.checkSelfPermission(context, Manifest.permission.ACCESS_FINE_LOCATION)
== PackageManager.PERMISSION_GRANTED
&& ActivityCompat.checkSelfPermission(context,
Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
locationManager?.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0L, 0f,
this)
}
}
fun stopLocationUpdates() {
locationManager?.removeUpdates(this)
}
Activity_main.xml File-
MainActivity.kt-
package com.example.sycspractical10
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.widget.Toast
Now Create a New File Named DataBaseHandler.kt and Add The Folllowing code –
package com.example.sycspractical10
import android.annotation.SuppressLint
import android.content.ContentValues
import android.content.Context
import android.database.sqlite.SQLiteDatabase
import android.database.sqlite.SQLiteOpenHelper
import android.widget.Toast
OUTPUT-
Program 11- Create a suitable Android application to work with Firebase for storing and
manipulating data
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
</RelativeLayout>
Now Create a Class File Named “EmployeeInfo.kt” And Add The Following Code to it-
package com.example.firebaseapplication
class EmployeeInfo
{
package com.example.firebaseapplication
import android.os.Bundle
import android.support.v7.app.AppCompatActivity
import android.text.TextUtils
import android.view.View
import android.widget.Button
import android.widget.EditText
import android.widget.Toast
import com.google.firebase.database.DataSnapshot
import com.google.firebase.database.DatabaseError
import com.google.firebase.database.DatabaseReference
import com.google.firebase.database.FirebaseDatabase
import com.google.firebase.database.ValueEventListener
OUTPUT-