Mobile Application Development lab file
Mobile Application Development lab file
PRACTICAL FILE
BCAP-318
Nurturing Excellence
During the installation, the setup wizard downloads and installs additional
components and tools needed for Android app development. This may take some
time depending on your internet speed. During this time, you may see a User
Account Control dialog for Windows Command Processor. Click Yes to
accept the dialog.
9. You may also receive a Windows Security Alert about adb.exe. Click Allow
Access, if needed, to continue the installation.
Install Android Studio on your computer if you haven't done so already. Check
that your computer meets the system requirements required for running Android
Studio (located at the bottom of the download page). If you need more detailed
instructions on the setup process, refer to the Download and install Android
Studio codelab.
In this codelab, you create your first Android app with a project template
provided by Android Studio.
In this codelab, you create an Android app with the Empty Activity project
template provided by Android Studio.
To create a project in Android Studio:
1. Double click the Android Studio icon to launch Android Studio.
2. In the Welcome to Android Studio dialog, click New Project.
The New Project window opens with a list of templates provided by Android
Studio
Project structure
MainActivity.java
package com.example.myapp;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.Toast;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
}
activity_main.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: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" />
</androidx.constraintlayout.widget.ConstraintLayout>
OUTPUT
Practical-3
Create an android app to display various android lifecycle phases.
Name: Tushar Tikia Roll no: 02590302022 Sem: VI Course: BCA
Project Structure
<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.Android_Life_Cycle"
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>
activity_main.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: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" />
</androidx.constraintlayout.widget.ConstraintLayout>
MainActiviy.java
package com.example.android_life_cycle;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Log.d("Event","In the onCreate() event");
}
@Override
protected void onStart() {
super.onStart();
Log.d("Event","In the onStart() event");
}
@Override
protected void onRestart() {
super.onRestart();
Log.d("Event","In the onRestart() event");
}
@Override
protected void onResume() {
super.onResume();
Log.d("Event","In the onResume() event");
}
@Override
protected void onPause() {
super.onPause();
Log.d("Event","In the onPause() event");
}
@Override
protected void onStop() {
super.onStop();
Log.d("Event","In the onStop() event");
}
@Override
protected void onDestroy() {
super.onDestroy();
Log.d("Event","In the onDestroy() event");
}
}
OUTPUT
Practical-4
Create a calculator app that performs addition, subtraction, division and multiplication
operation on numbers
Name: Tushar Tikia Roll no: 02590302022 Sem: VI Course: BCA
Project Structure
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"
tools:context=".MainActivity">
<EditText
android:id="@+id/editTextText"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_margin="10sp"
android:textSize="30sp"
android:textStyle="bold"
android:gravity="center"
android:inputType="text"
android:text="Enter num1 " />
<EditText
android:id="@+id/editTextText2"
android:layout_width="match_parent"
android:layout_height="103dp"
android:layout_margin="10sp"
android:inputType="text"
android:gravity="center"
android:textStyle="bold"
android:textSize="30sp"
android:text="Enter num2" />
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="82dp"
android:textSize="30sp"
android:textStyle="bold"
android:gravity="center"
android:layout_margin="10sp"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="378dp">
<Button
android:id="@+id/button6"
android:layout_width="175dp"
android:layout_height="79dp"
android:onClick="onClick"
android:layout_marginLeft="10dp"
android:text="+" />
<Button
android:id="@+id/button7"
android:layout_width="186dp"
android:layout_height="81dp"
android:layout_alignRight="@id/button6"
android:layout_marginEnd="-223dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="-192dp"
android:layout_marginStart="-223dp"
android:onClick="onClick"
android:text="-" />
<Button
android:id="@+id/button8"
android:layout_width="175dp"
android:layout_height="75dp"
android:onClick="onClick"
android:layout_marginLeft="10dp"
android:layout_alignBottom="@id/button6"
android:layout_marginBottom="-88dp"
android:text="*" />
<Button
android:id="@+id/button9"
android:layout_width="192dp"
android:layout_height="73dp"
android:onClick="onClick"
android:layout_alignBottom="@id/button8"
android:layout_alignRight="@id/button8"
android:layout_marginRight="-225dp"
android:text="/" />
</RelativeLayout>
</LinearLayout>
MainActivity.Java
package com.example.calculatorapp;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
String s1=num1.getText().toString().trim();
String s2=num2.getText().toString().trim();
int n1=Integer.parseInt(s1);
int n2=Integer.parseInt(s2);
if (v.getId()==R.id.button6)
{
result.setText(String.valueOf(n1+n2));
}
else if (v.getId()==R.id.button7)
{
result.setText(String.valueOf(n1-n2));
}
else if (v.getId()==R.id.button8)
{
result.setText(String.valueOf(n1*n2));
}else
{
result.setText(String.valueOf(n1/n2));
}
}
}
OUTPUT
ADDITION SUBTRACTION
MULTIPLICATION DIVISION
Practical-5
Write an Android application to convert into different currencies for example, Rupees
to dollar
Name: Tushar Tikia Roll no: 02590302022 Sem: VI Course: BCA
Project Structure
activity_main.xml
package com.example.currencyapp;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
import android.widget.Toast;
import java.util.HashMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
editTextAmount = findViewById(R.id.editTextAmount);
spinnerCurrency = findViewById(R.id.spinnerCurrency);
textViewResult = findViewById(R.id.textViewResult);
Button btnConvert = findViewById(R.id.btnConvert);
initializeCurrencyRates();
// Set up Spinner with currency options
ArrayAdapter<String> adapter = new ArrayAdapter<>(this,
android.R.layout.simple_spinner_item, currencyRates.keySet().toArray(new
String[0]));
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item
);
spinnerCurrency.setAdapter(adapter);
btnConvert.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
convertCurrency();
}
});
}
private void initializeCurrencyRates() {
// Example rates: 1 USD to other currencies
currencyRates = new HashMap<>();
currencyRates.put("USD", 1.0); // Base currency
currencyRates.put("EUR", 0.85); // Euro
currencyRates.put("INR", 74.50); // Indian Rupee
currencyRates.put("GBP", 0.75); // British Pound
currencyRates.put("JPY", 110.0); // Japanese Yen
}
private void convertCurrency() {
String amountText = editTextAmount.getText().toString().trim();
if (amountText.isEmpty()) {
Toast.makeText(this, "Please enter an amount",
Toast.LENGTH_SHORT).show();
return;
}
Project Structure
activity_main.xml
MainActivity.Java
package com.example.graphicsprimitives;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.widget.ImageView;
import androidx.appcompat.app.AppCompatActivity;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Bitmap bg=Bitmap.createBitmap(720,1280,Bitmap.Config.ARGB_8888);
ImageView img=findViewById(R.id.imageView);
img.setBackgroundDrawable(new BitmapDrawable(bg));
canvas.drawText("Rectangle",420,150,paint);
canvas.drawRect(400,200,650,700,paint);
canvas.drawText("Circle",120,150,paintC);
canvas.drawCircle(200,350,150,paintC);
canvas.drawText("Square",120,800,paintS);
canvas.drawRect(50,850,350,1150,paintS);
canvas.drawText("Line",480,800,paintL);
canvas.drawLine(520,850,520,1150,paintL);
}
}
OUTPUT
Practical-7
Write an application to record video and audio on topic “Intent” and play
the audio and video.
Name: Tushar Tikia Roll no: 02590302022 Sem: VI Course: BCA
Project Structure
AndroidManifest.xml
</manifest>
activity_main.xml
<Button
android:id="@+id/btnRecordAudio"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Record Audio" />
<Button
android:id="@+id/btnPlayAudio"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Play Audio" />
<Button
android:id="@+id/btnStopAudio"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Stop Audio" />
<Button
android:id="@+id/btnRecordVideo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Record Video" />
<Button
android:id="@+id/btnPlayVideo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Play Video" />
<VideoView
android:id="@+id/videoView"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
dialog_audio_player.xml
<TextView
android:id="@+id/tvAudioTitle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Playing Audio"
android:textColor="@color/design_default_color_primary"
android:textSize="38sp"
android:textStyle="bold"
android:gravity="center"
android:paddingBottom="10dp" />
</LinearLayout>
MainActivity.java
package com.example.multimediaapp;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import android.app.Dialog;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.media.MediaPlayer;
import android.media.MediaRecorder;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.widget.Button;
import android.widget.MediaController;
import android.widget.Toast;
import android.widget.VideoView;
import java.io.IOException;
if(checkCameraPermission()) {
recordVideo();
}
}
});
btnPlayVideo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
playVideo();
}
});
}
private void startAudioRecording() {
try {
file=getExternalFilesDir(null).getAbsolutePath()+"/"+AUDIO_FILE_NAME;
mediaRecorder = new MediaRecorder();
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mediaRecorder.setOutputFile(file);
mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
mediaRecorder.prepare();
mediaRecorder.start();
Toast.makeText(this, "Recording started", Toast.LENGTH_LONG).show();
findViewById(R.id.btnRecordAudio).setEnabled(false);
findViewById(R.id.btnPlayAudio).setEnabled(false);
} catch (IOException e) {
Toast.makeText(this, "Error starting recording",
Toast.LENGTH_SHORT).show();
}
}
private boolean checkAudioPermission() {
if (ContextCompat.checkSelfPermission(getApplicationContext(),
android.Manifest.permission.RECORD_AUDIO) !=
PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(MainActivity.this, new
String[]{android.Manifest.permission.RECORD_AUDIO},
REQUEST_AUDIO_PERMISSION);
return false;
}
return true;
}
private boolean checkCameraPermission() {
if (ContextCompat.checkSelfPermission(this,
android.Manifest.permission.CAMERA) !=
PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this, new
String[]{android.Manifest.permission.CAMERA},
REQUEST_CAMERA_PERMISSION);
return false;
}
return true;
}
@Override
public void onRequestPermissionsResult(int requestCode, String[] permissions,int[]
grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == REQUEST_AUDIO_PERMISSION) {
if (grantResults.length > 0 && grantResults[0] ==
PackageManager.PERMISSION_GRANTED) {
startAudioRecording();
} else {
Toast.makeText(this, "Audio recording permission denied",
Toast.LENGTH_SHORT).show();
}
} else if (requestCode == REQUEST_CAMERA_PERMISSION) {
if (grantResults.length > 0 && grantResults[0] ==
PackageManager.PERMISSION_GRANTED) {
recordVideo();
} else {
Toast.makeText(this, "Camera permission denied",
Toast.LENGTH_SHORT).show();
}
}
}
private void stopAudioRecording() {
mediaRecorder.stop();
mediaRecorder.release();
mediaRecorder = null;
Toast.makeText(this, "Audio recorded successfully!",
Toast.LENGTH_SHORT).show();
findViewById(R.id.btnRecordAudio).setEnabled(true);
findViewById(R.id.btnPlayAudio).setEnabled(true);
}
private void playAudio() {
MediaPlayer mediaPlayer = new MediaPlayer();
try {
Dialog dialog = new Dialog(this);
dialog.setContentView(R.layout.dialog_audio_player);
dialog.setCancelable(true);
mediaPlayer.setDataSource(file);
mediaPlayer.prepare();
mediaPlayer.start();
dialog.show();
//Toast.makeText(this, "Playing audio...", Toast.LENGTH_SHORT).show();
} catch (IOException e) {
e.printStackTrace();
}
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK) {
if (requestCode == REQUEST_VIDEO_CAPTURE && data != null) {
videoUri = data.getData();
Toast.makeText(this, "Video saved: " + videoUri,
Toast.LENGTH_LONG).show();
}
} else {
Toast.makeText(this, "Recording cancelled", Toast.LENGTH_SHORT).show();
}
}
}
OUTPUT
Practical-8
Write an android application to Get data from Restful API and show
into Recycler View.
Name: Tushar Tikia Roll no: 02590302022 Sem: VI Course: BCA
Project Structure
API
Api_url="https://script.googleusercontent.com/macros/echo?user_content_key=-
YemyYERKU2NntsOnxEsMbq-
k wTp8QGIl8k12DLppJ6fHGXwm3vbMlhQ_oRh6qEOZZ8cHzbgl8mkaVu_t5-
Hdn3ulv3CqYm5_BxDlH2jW0nuo2oDemN9CCS2h10ox_1xSncGQajx_ryfhECjZEnC
uc_Pn9Cxnt48ZBoIFC7D9gRL1wVLOPg4YxskhimYX1vggPmB9aX5rGFjdxHh8RnC
HFsvQxoarvNaNLlLwb7d4YEF7r07ETew&lib=M1mjq6zUNrplWb13hM0gtWzcFR0
BbGMzm"
{
"data": [
"Books_link":
"https://drive.google.com/file/d/1MXFGPkpOZCu9zhh1SrpHkjawYXBebKBE/view?u
sp=drivesdk",
"Books_Images":
"https://drive.google.com/uc?id=15NrgaImBvs4B1sYpKs_uMx9QxWvlcdRX"
},
"Books_link":
"https://drive.google.com/file/d/0B1V9nCjFdTUybGx1N3NaVXhFTlpzREJ0WDh4NE
ZkNnVrcUpZ/view?usp=drivesdk",
"Books_Images":
"https://drive.google.com/uc?id=15V3xbfvGWVXz53NfOE7VLUohW_cUAt9g"
},
"Books_link":
"https://drive.google.com/file/d/1VmA2UebcZXANctUFipyPF55_vXcdoCGz/view?usp
=drivesdk",
"Books_Images":
"https://drive.google.com/uc?id=15UvN5enfWGpdMirWB3Ol2gMzzLqZatQC"
},
"Books_Images":
"https://drive.google.com/uc?id=16DKkLExlzf5Jj6sF_9Wc2y8xB6A29nAK"
},
"Books_link":
"https://drive.google.com/file/d/102QYfPjqsW17MzXdc545c6WQrmztZTH3/view?usp
=drivesdk",
"Books_Images": "https://drive.google.com/uc?id=15R0S_MziOiVmnY-
xSTulSzGkEcqGEhi0"
},
"Books_link":
"https://drive.google.com/file/d/1vnn3doDAklqSsV4SKBJzrCU341QfMb5S/view?usp=
drivesdk",
"Books_Images":
"https://drive.google.com/file/d/16Nzt2V5_8zqOaqFyPwjh33ayG3X-
wwyC/view?usp=drivesdk"
},
"Books_link":
"https://drive.google.com/file/d/11v58nCKrDwYQlZtl3FF1IXnHAFTo0ia3/view?usp=d
rivesdk",
"Books_Images": "https://drive.google.com/file/d/16a9aMmYQyQ3vezab-
QgV16Jd4GanYyy0/view?usp=drivesdk"
},
{
"Books_Title": "Artificial intelligence a modern approach",
"Books_link": "https://drive.google.com/file/d/1TfBUIH-
rkFyaFhVmbV_jU6XKOfzNPa9e/view?usp=drivesdk",
"Books_Images":
"https://drive.google.com/file/d/16cOHsGWlcGTwwu1FL9mnnOc71yIGX-
bs/view?usp=drivesdk"
},
"Books_link":
"https://drive.google.com/file/d/1WuHGOZf8IadhhYhIgVJEGAQnoHaeouog/view?us
p=drivesdk",
"Books_Images":
"https://drive.google.com/file/d/16jlCbrJIwIJTCFG8avWttYtVr8h1Id4J/view?usp=dri
vesdk"
},
"Books_link":
"https://drive.google.com/file/d/19f8nEWp8goK2oJ0K9MSB479Otb5RyPl1/view?usp=
drivesdk",
"Books_Images":
"https://drive.google.com/file/d/16f4N7yVavCrSZKQeQutp40xaZh9VLTAW/view?usp
=drivesdk"
},
"Books_link":
"https://drive.google.com/file/d/1hNCYEBzS0IM_gltTpTx4y4vJYwl2kNnH/view?usp=
drivesdk",
"Books_Images": "https://drive.google.com/file/d/16jy50KET_My_x-
1SHkRLDpBgDJ3l2N_D/view?usp=drivesdk"
},
"Books_link": "https://drive.google.com/file/d/1v6EE4XNaHzH2-
Gy3oPbRxWu228seZPHq/view?usp=drivesdk",
"Books_Images": "https://drive.google.com/file/d/16uFwnCbfD-
dljY57M42UngomOgapoNHk/view?usp=drivesdk"
},
"Books_link":
"https://drive.google.com/file/d/1mc5hKCDqqZgDNPG_T62h6CrDgTPuyd1M/view?us
p=drivesdk",
"Books_Images": "https://drive.google.com/file/d/16kv-
krQGzxVV2q7QTrPbbtSxmchB5UHN/view?usp=drivesdk"
},
"Books_link": "https://drive.google.com/file/d/1rd3gETlyCk3-
jjqEfCxp5kQ1F1ae9auB/view?usp=drivesdk",
"Books_Images": "https://drive.google.com/file/d/17-lcjA9aWEpMnQo-
npsNQJnBudcKKTMu/view?usp=drivesdk"
},
"Books_link": "https://drive.google.com/file/d/1aAk-
lSi_3sZfyLaepolIuTqq9CWocxuZ/view?usp=drivesdk",
"Books_Images": "https://drive.google.com/file/d/170tXLhFvtP1E_EVKmQ-
Z3gLiC1ng4sEX/view?usp=drivesdk"
},
{
"Books_link":
"https://drive.google.com/file/d/1FW38D_GQKAcbxWL1Qb1kn4DFKzHy2yGw/view?
usp=drivesdk",
"Books_Images":
"https://drive.google.com/file/d/1766PJ_HHdtqITz8sMykPmF7ZNfXR6JBE/view?usp
=drivesdk"
},
"Books_link": "https://drive.google.com/file/d/1WtYGOX6w2gw-
SEas3OjvsMK2Lgeek4xy/view?usp=drivesdk",
"Books_Images":
"https://drive.google.com/file/d/176g9t8XsCjVHLWRapAS7SnsBBADogns4/view?usp=
drivesdk"
},
"Books_link":
"https://drive.google.com/file/d/1dJBuon5J7WdMXKLY3Ryk624dZq9v5HQl/view?us
p=drivesdk",
"Books_Images": "https://drive.google.com/file/d/17BcJMm-
O4dEV20xvsqvkY7UvaLaWh_Yp/view?usp=drivesdk"
},
"Books_link": "https://drive.google.com/file/d/1Wp-
DtX3G6Y0bucfGxHJPeSu3vbwqqfMK/view?usp=drivesdk",
"Books_Images": "https://drive.google.com/file/d/17ByLlMc5Aj_hhNLNeFnHB-
BB55ICRkLI/view?usp=drivesdk"
},
"Books_link": "https://drive.google.com/file/d/1d6wH7XyD-
_bdgSOm6S4owmo0u3Xp8azi/view?usp=drivesdk",
"Books_Images": "https://drive.google.com/file/d/17MofJ1lmCtub2dTodyTY2R-
KQq_IStZ4/view?usp=drivesdk"
},
"Books_link": "https://drive.google.com/file/d/1Bc95NNlmdg-
EcvkVSbhowuWMJCRe5Cqd/view?usp=drivesdk",
"Books_Images":
"https://drive.google.com/file/d/17I2e7c59N8kAAQl3k5iFBscQGvZXAEPd/view?usp=
drivesdk"
},
"Books_link":
"https://drive.google.com/file/d/1lPt5kPOAtPEzmrst1ZhI1BuS4ptZlnw7/view?usp=dri
vesdk",
"Books_Images":
"https://drive.google.com/file/d/17MeE25IdGiRRETDvo1kYhvwQiic3CWsi/view?usp=
drivesdk"
},
"Books_link": "https://drive.google.com/file/d/1Jwn-
LOlFASBD40_wldqFfpsos6fDX31F/view?usp=drivesdk",
"Books_Images":
"https://drive.google.com/file/d/17JCtZxEMewuW3LdbUulMjQrcL4nQSBJV/view?us
p=drivesdk"
},
"Books_link": "https://drive.google.com/file/d/1d9iyg_r-HrXgaCK2-3F3waPLmZ6-
Jhce/view?usp=drivesdk",
"Books_Images": "https://drive.google.com/file/d/17Sns5d-LzUmqh_y1KQ-
OcEUkA28No6RC/view?usp=drivesdk"
},
"Books_link":
"https://drive.google.com/file/d/17A9LSvfGhX1Sr1NWyN4JQFDjR_VPAfuq/view?usp
=drivesdk",
"Books_Images": "https://drive.google.com/file/d/17W8-TX6eGNR0ZH7PWEq2-
XhJDecmu3Ev/view?usp=drivesdk"
},
"Books_link":
"https://drive.google.com/file/d/1gVuzlxJoBy1GvzQGbPsKWXEe5AYAipjM/view?usp
=drivesdk",
"Books_Images": "https://drive.google.com/file/d/17X-
aTDeWhLDb8aRQXdbNBeMrOAMle8VX/view?usp=drivesdk"
},
"Books_Images":
"https://drive.google.com/file/d/17_vfCMHnK24b6K8ZVHu5d10tborsGFU9/view?usp
=drivesdk"
},
"Books_link":
"https://drive.google.com/file/d/13gHYz89kFkO9uoFWklh8qmcY_Qqp_lXi/view?usp=
drivesdk",
"Books_Images":
"https://drive.google.com/file/d/17gaXvuuDLkwARomL5SZsiEe8cf_bMyjW/view?usp
=drivesdk"
},
"Books_link": "https://drive.google.com/file/d/1c5Nph8wBgCyTjWlrKjfxiz-
j6zpZqknY/view?usp=drivesdk",
"Books_Images":
"https://drive.google.com/file/d/18bxiVw80bAtT2bA_UKyGX_ekm64939Qn/view?usp=
drivesdk"
},
"Books_link":
"https://drive.google.com/file/d/1pnXIumxEwFjQnmyd8v5T0LYmjxbKgHmO/view?us
p=drivesdk",
"Books_Images":
"https://drive.google.com/file/d/18dtnTtr_Gu4j1hMFjHGs5sCks7VC1e2E/view?usp=d
rivesdk"
},
"Books_link": "https://drive.google.com/file/d/1Dx4KyirAE_6JE-
IgP9rnRMPtYFauj9yY/view?usp=drivesdk",
"Books_Images":
"https://drive.google.com/file/d/18eh7FJu5dfNv02LgrTsTqka2rhuM0NKq/view?usp=d
rivesdk"
},
"Books_link":
"https://drive.google.com/file/d/13puvU1gHhc0pmvowzqgY27sMI4XoJ5xq/view?usp=d
rivesdk",
"Books_Images":
"https://drive.google.com/file/d/18v4UASpwCn0YwMIF11Gx_tvKoTT4qRNw/view?us
p=drivesdk"
},
"Books_link": "https://drive.google.com/file/d/1940Oo97_PbNhHfQ29xwAQ_-
IND39re1f/view?usp=drivesdk",
"Books_Images":
"https://drive.google.com/file/d/197mZsPG1GFmxFGP03ur51Ab3haJRdtsu/view?usp=
drivesdk"
}
AndroidManifest.xml
</manifest>
build.gradle.kts(Module:app)
plugins {
id("com.android.application")
}
android {
namespace = "com.example.volleyjsonparsing"
compileSdk = 34
defaultConfig {
applicationId = "com.example.volleyjsonparsing"
minSdk = 21
targetSdk = 34
versionCode = 1
versionName = "1.0"
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {
release {
isMinifyEnabled = false
proguardFiles(getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro")
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
}
dependencies {
implementation("androidx.appcompat:appcompat:1.6.1")
implementation("com.google.android.material:material:1.11.0")
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
implementation("com.android.volley:volley:1.2.1")
implementation("androidx.recyclerview:recyclerview:1.3.2")
// For control over item selection of both touch and mouse driven selection
implementation("androidx.recyclerview:recyclerview-selection:1.1.0")
implementation("androidx.cardview:cardview:1.0.0")
implementation ("com.github.bumptech.glide:glide:4.12.0")
implementation ("com.squareup.picasso:picasso:2.8")
// Glide v4 uses this new annotation processor -- see
https://bumptech.github.io/glide/doc/generatedapi.html
annotationProcessor ("com.github.bumptech.glide:compiler:4.12.0")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
}
activity_main.xml
<ToggleButton
android:id="@+id/tButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textOff="OFF"
android:textOn="ON" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/recycler_View"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
</LinearLayout>
item_list.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.cardview.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_margin="5dp"
app:cardBackgroundColor="@color/design_default_color_primary"
tools:ignore="MissingDefaultResource">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/bookTitle"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:textColor="@color/white"
android:textSize="25sp"
android:textStyle="bold" />
</LinearLayout>
</androidx.cardview.widget.CardView>
Book_Adapter.java
package com.example.volleyjsonparsing;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import java.util.List;
import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;
@NonNull
@Override
public BookHolder onCreateViewHolder(@NonNull ViewGroup parent, int
viewType) {
View view= LayoutInflater.from(context).inflate(R.layout.item_list,parent,false);
return new BookHolder(view);
}
@Override
public void onBindViewHolder(@NonNull BookHolder holder, int position) {
BooK_Model k_model=booKModelList.get(position);
holder.book_title.setText(k_model.getBook_name());
}
@Override
public int getItemCount() {
return booKModelList.size();
}
import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.os.Bundle;
import android.widget.CompoundButton;
import android.widget.ToggleButton;
import com.android.volley.Request;
import com.android.volley.RequestQueue;
import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.android.volley.toolbox.JsonObjectRequest;
import com.android.volley.toolbox.Volley;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.List;
public String
url="https://script.googleusercontent.com/macros/echo?user_content_key=-
YemyYERKU2NntsOnxEsMbq-
k wTp8QGIl8k12DLppJ6fHGXwm3vbMlhQ_oRh6qEOZZ8cHzbgl8mkaVu_t5-
Hdn3ulv3CqYm5_BxDlH2jW0nuo2oDemN9CCS2h10ox_1xSncGQajx_ryfhECjZEnC
uc_Pn9Cxnt48ZBoIFC7D9gRL1wVLOPg4YxskhimYX1vggPmB9aX5rGFjdxHh8RnC
HFsvQxoarvNaNLlLwb7d4YEF7r07ETew&lib=M1mjq6zUNrplWb13hM0gtWzcFR0
BbGMzm";
public RequestQueue requestQueue;
public List<BooK_Model> booKModelList;
public RecyclerView recyclerView;
public Book_Adapter bookAdapter;
public ToggleButton toggleButton;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
requestQueue= Volley.newRequestQueue(this);
booKModelList=new ArrayList<BooK_Model>();
recyclerView=findViewById(R.id.recycler_View);
toggleButton=findViewById(R.id.tButton);
toggleButton.setOnCheckedChangeListener(new
CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean
isChecked) {
if (isChecked) {
recyclerView.setLayoutManager(new
LinearLayoutManager(MainActivity.this));
}else{
recyclerView.setLayoutManager(new
GridLayoutManager(MainActivity.this,2));
}
}
});
getJson(url);
}
public void getJson(String url)
{
JsonObjectRequest jsonObjectRequest=new
JsonObjectRequest(Request.Method.GET, url, null, new
Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
JSONArray jsonArray=response.getJSONArray("data");
for (int i=0;i<jsonArray.length();i++)
{
JSONObject object=jsonArray.getJSONObject(i);
String title=object.getString("Books_Title");
booKModelList.add(new BooK_Model(title));
}
bookAdapter=new Book_Adapter(MainActivity.this,booKModelList);
recyclerView.setAdapter(bookAdapter);
} catch (JSONException e) {
throw new RuntimeException(e);
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
});
requestQueue.add(jsonObjectRequest);
}
}
OUTPUT
Practical-9
Create a login application to verify username and password. On successful
login, redirect to another activity that has a textview to display "welcome
user" with logout button. On click of logout button, adialog should appear
with ok and cancel buttons. On click of oK button, go back to the login
activity and on click of cancel button, stay on the same activity.
Name: Tushar Tikia Roll no: 02590302022 Sem: VI Course: BCA
Project Structure
activity_main.xml
<EditText
android:id="@+id/username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:textAlignment="center"
android:textSize="35sp" />
<EditText
android:id="@+id/userpass"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="numberPassword"
android:textAlignment="center"
android:textSize="35sp" />
<Button
android:id="@+id/login"
android:layout_width="match_parent"
android:layout_height="71dp"
android:text="Login"
android:textSize="35sp" />
</LinearLayout>
</LinearLayout>
MainActivity.java
package com.example.loginlogoutapp;
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;
activity_main2.xml
<TextView
android:id="@+id/welcomsg"
android:layout_width="match_parent"
android:layout_height="51dp"
android:gravity="center"
android:textStyle="bold"
android:text="WELCOME"
android:textSize="35sp" />
<Button
android:id="@+id/logout"
android:layout_width="match_parent"
android:layout_height="71dp"
android:text="Logout"
android:textSize="35sp" />
</LinearLayout>
</LinearLayout>
MainActivity2.java
package com.example.loginlogoutapp;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
Project Structure
Manifest.xml
<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.TravelApp"
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>
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="AIzaSyCvxA-i89A875DQaYtYw-ITaVeAOo68Pzk"/>
</application>
</manifest>
activity_main.xml
MainActivity.java
package com.example.travelapp;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.fragment.app.FragmentActivity;
import android.Manifest;
import android.content.pm.PackageManager;
import android.graphics.Color;
import android.location.Location;
import android.os.Bundle;
import android.os.Looper;
import android.widget.Toast;
import com.google.android.gms.location.FusedLocationProviderClient;
import com.google.android.gms.location.LocationCallback;
import com.google.android.gms.location.LocationRequest;
import com.google.android.gms.location.LocationResult;
import com.google.android.gms.location.LocationServices;
import com.google.android.gms.location.Priority;
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.google.android.gms.maps.model.Polyline;
import com.google.android.gms.maps.model.PolylineOptions;
import java.util.ArrayList;
import java.util.List;
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(routePoints.get(routePo
ints.size() - 1), 15));
for(int i=0;i<routePoints.size()-1;i++){
LatLng src=routePoints.get(i);
LatLng dest=routePoints.get(i+1);
mMap.addPolyline(
new PolylineOptions().add(
new LatLng(src.latitude,src.longitude),
new LatLng(dest.latitude,dest.longitude)
).width(2).color(Color.BLUE).geodesic(true)
);
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[]
permissions,
@NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == 1) {
if (grantResults.length > 0 && grantResults[0] ==
PackageManager.PERMISSION_GRANTED) {
setupLocationTracking();
} else {
Toast.makeText(this, "Permission denied", Toast.LENGTH_SHORT).show();
}
}
}
@Override
protected void onDestroy() {
super.onDestroy();
if (fusedLocationClient != null && locationCallback != null) {
fusedLocationClient.removeLocationUpdates(locationCallback);
}
}
}
OUTPUT
Practical-11
Create an application to pick up any image from the native application
gallery and display it on the screen
Name: Tushar Tikia Roll no: 02590302022 Sem: VI Course: BCA
Project Structure
AndroidManifest.xml
</manifest>
Activity_main.xml
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="16dp"
app:srcCompat="@drawable/ic_launcher_background"
tools:layout_editor_absoluteX="6dp"
tools:layout_editor_absoluteY="7dp" />
<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_below="@id/imageView"
android:text="Select_Image" />
</RelativeLayout>
MainActivity.java
package com.example.gallaryapp;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;
import androidx.activity.result.ActivityResult;
import androidx.activity.result.ActivityResultCallback;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.appcompat.app.AppCompatActivity;
import java.io.IOException;
ActivityResultLauncher<Intent>activityResultLauncher=registerForActivityResult(ne
w ActivityResultContracts.StartActivityForResult(), new
ActivityResultCallback<ActivityResult>() {
@Override
public void onActivityResult(ActivityResult activityResult) {
if (activityResult.getResultCode()== Activity.RESULT_OK) {
Intent intent = activityResult.getData();
Uri uri = intent.getData();
try {
s_img.setImageBitmap(MediaStore.Images.Media.getBitmap(getContentResolver(),
uri));
} catch (IOException e) {
throw new RuntimeException(e);
}
} else {
Toast.makeText(MainActivity.this,"Error",Toast.LENGTH_LONG).show();
}
}
});
}
OUTPUT
Practical-12
Create an application to perform the operations of create, insert, delete, view and
update, using sqlite database.
Name: Tushar Tikia Roll no: 02590302022 Sem: VI Course: BCA
Project Struture
activity_main.xml
<TextView
android:id="@+id/textView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:textStyle="bold"
android:textSize="30sp"
android:text="Student Details" />
<EditText
android:id="@+id/editTextText"
android:layout_width="match_parent"
android:layout_height="62dp"
android:ems="10"
android:inputType="text"
android:hint="Roll No" />
<EditText
android:id="@+id/editTextText2"
android:layout_width="match_parent"
android:layout_height="64dp"
android:ems="10"
android:inputType="text"
android:hint="Student Name" />
<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="INSERT" />
<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="View" />
<Button
android:id="@+id/button3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="UPDATE" />
<Button
android:id="@+id/button4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="DELETE" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:textSize="20sp"
android:padding="5dp"
android:gravity="center"
android:textStyle="bold"
android:id="@+id/data_inserted"/>
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:stretchColumns="1">
<TableRow>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="Roll No"
android:background="@color/design_default_color_primary"
android:textColor="@color/white"
android:padding="5dp"
android:gravity="center"
android:textStyle="bold"
android:id="@+id/roll_txt"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:text="Name"
android:background="@color/design_default_color_primary"
android:textColor="@color/white"
android:padding="5dp"
android:gravity="center"
android:textStyle="bold"
android:id="@+id/name_txt"/>
</TableRow>
<TableRow>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:padding="5dp"
android:gravity="center"
android:textStyle="bold"
android:id="@+id/roll_s1"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:padding="5dp"
android:gravity="center"
android:textStyle="bold"
android:id="@+id/name_s1"/>
</TableRow>
<TableRow>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:padding="5dp"
android:gravity="center"
android:textStyle="bold"
android:id="@+id/roll_s2"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:padding="5dp"
android:gravity="center"
android:textStyle="bold"
android:id="@+id/name_s2"/>
</TableRow>
<TableRow>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:padding="5dp"
android:gravity="center"
android:textStyle="bold"
android:id="@+id/roll_s3"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:padding="5dp"
android:gravity="center"
android:textStyle="bold"
android:id="@+id/name_s3"/>
</TableRow>
<TableRow>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:padding="5dp"
android:gravity="center"
android:textStyle="bold"
android:id="@+id/roll_s4"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:padding="5dp"
android:gravity="center"
android:textStyle="bold"
android:id="@+id/name_s4"/>
</TableRow>
<TableRow>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:padding="5dp"
android:gravity="center"
android:textStyle="bold"
android:id="@+id/roll_s5"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="20sp"
android:padding="5dp"
android:gravity="center"
android:textStyle="bold"
android:id="@+id/name_s5"/>
</TableRow>
</TableLayout>
</LinearLayout>
Student_Model.java
package com.example.sqlitedemo;
public Student_Model() {
}
package com.example.sqlitedemo;
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;
import androidx.annotation.Nullable;
@Override
public void onCreate(SQLiteDatabase db) {
String CREATE_STUDENTS_TABLE = "CREATE TABLE " +
TABLE_CONTACTS + "("
+ Roll_NO + " INTEGER PRIMARY KEY," + Student_NAME + "
TEXT"+")";
db.execSQL(CREATE_STUDENTS_TABLE);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// Drop older table if existed
db.execSQL("DROP TABLE IF EXISTS " + TABLE_CONTACTS);
return studentModel;
}
public List<Student_Model> fetchAllstudent()
{
List<Student_Model> modelList = new ArrayList<Student_Model>();
// Select All Query
String selectQuery = "SELECT * FROM " + TABLE_CONTACTS;
SQLiteDatabase db = this.getWritableDatabase();
Cursor cursor = db.rawQuery(selectQuery, null);
// updating row
return db.update(TABLE_CONTACTS, values, Roll_NO + " = ?",
new String[] { model.getRoll_no() });
}
public int deleteStudent(Student_Model model) {
SQLiteDatabase db = this.getWritableDatabase();
int r=db.delete(TABLE_CONTACTS, Roll_NO + " = ?",
new String[] { model.getRoll_no()});
db.close();
return r;
}
}
MainActivity.java
package com.example.sqlitedemo;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.GridView;
import android.widget.TextView;
import android.widget.Toast;
import java.util.List;
public class MainActivity extends AppCompatActivity {
StudentDataHalper sD;
EditText roll;
EditText name;
Button insert_btn,view_btn,update_btn,delete_btn;
TextView
inserted,S_roll_no,S_name,roll_s1,roll_s2,roll_s3,roll_s4,roll_s5,name_s1,name_s2,nam
e_s3,name_s4,name_s5;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
roll=findViewById(R.id.editTextText);
name=findViewById(R.id.editTextText2);
insert_btn=findViewById(R.id.button);
view_btn=findViewById(R.id.button2);
update_btn=findViewById(R.id.button3);
delete_btn=findViewById(R.id.button4);
inserted=findViewById(R.id.data_inserted);
S_roll_no=findViewById(R.id.roll_txt);
S_name=findViewById(R.id.name_txt);
roll_s1=findViewById(R.id.roll_s1);
name_s1=findViewById(R.id.name_s1);
roll_s2=findViewById(R.id.roll_s2);
name_s2=findViewById(R.id.name_s2);
roll_s3=findViewById(R.id.roll_s3);
name_s3=findViewById(R.id.name_s3);
roll_s4=findViewById(R.id.roll_s4);
name_s4=findViewById(R.id.name_s4);
roll_s5=findViewById(R.id.roll_s5);
name_s5=findViewById(R.id.name_s5);
sD=new StudentDataHalper(this);
insert_btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String rll=roll.getText().toString();
String nm=name.getText().toString();
long l=sD.insertStudent(new Student_Model(rll,nm));
inserted.setText("");
if(l!=0){
inserted.setText("Inserted");
}
else {
inserted.setText("Not Inserted");
}
}
});
view_btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//String rll=roll.getText().toString();
// Student_Model model=sD.fetchStudent(rll);
//String student_roll=model.getRoll_no();
//String student_name=model.getName();
List<Student_Model> modelAll=sD.fetchAllstudent();
roll_s1.setText(modelAll.get(0).getRoll_no());
name_s1.setText(modelAll.get(0).getName());
roll_s2.setText(modelAll.get(1).getRoll_no());
name_s2.setText(modelAll.get(1).getName());
roll_s3.setText(modelAll.get(2).getRoll_no());
name_s3.setText(modelAll.get(2).getName());
roll_s4.setText(modelAll.get(3).getRoll_no());
name_s4.setText(modelAll.get(3).getName());
roll_s5.setText(modelAll.get(4).getRoll_no());
name_s5.setText(modelAll.get(4).getName());
}
});
update_btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String rll=roll.getText().toString();
String nm=name.getText().toString();
int l=sD.updateStudent(new Student_Model(rll,nm));
inserted.setText("");
if(l!=0){
inserted.setText("Updated");
}
else {
inserted.setText("Not Updated");
}
}
});
delete_btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String rll=roll.getText().toString();
String nm=name.getText().toString();
int r =sD.deleteStudent(new Student_Model(rll,nm));
inserted.setText("");
if(r!=0){
inserted.setText("Deleted");
}
else {
inserted.setText("Not Deleted");
}
}
});
}
}
OUTPUT
CREATE TABLE INSERT DATA
Project Structure
Manifest.xml
</manifest>
activity_main.xml
MainActivity.java
package com.example.wirelessdebugging;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import android.content.ContentResolver;
import android.content.pm.PackageManager;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import java.util.ArrayList;
Project Structure
activity_main.xml
Item_row.xml
<CheckBox
android:id="@+id/check_box"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:id="@+id/tv_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>
Verson.java
package com.example.shoppinglist;
public Versons() {
}
package com.example.shoppinglist;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.List;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
@NonNull
@Override
public View getView(int position, @Nullable View convertView, @NonNull
ViewGroup parent) {
if (convertView == null){
holder.checkBox = convertView.findViewById(R.id.check_box);
holder.textView = convertView.findViewById(R.id.tv_name);
holder.checkBox.setOnCheckedChangeListener((MainActivity)context);
convertView.setTag(holder);
}else{
holder = (VersonHolder) convertView.getTag();
}
return convertView;
}
public static class VersonHolder{
public CheckBox checkBox;
public TextView textView;
}
}
MainActivity.java
package com.example.shoppinglist;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.CompoundButton;
import android.widget.ListView;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.List;
ListView listView;
ListView Select_listView;
List<Versons> list;
List<String> Select_list;
TextView select_item;
VersonsAdapter versonsAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listView = findViewById(R.id.item_list);
Select_listView = findViewById(R.id.select_item_list);
select_item=findViewById(R.id.item_textview);
list = new ArrayList<>();
Select_list = new ArrayList<>();
list.add(new Versons("Mirch"));
list.add(new Versons("Moog Daal"));
list.add(new Versons("Sugar"));
list.add(new Versons("Salt"));
list.add(new Versons("Eclair"));
list.add(new Versons("Honey"));
list.add(new Versons("GingerBread"));
list.add(new Versons("Kachori"));
list.add(new Versons("IceCream"));
list.add(new Versons("Jelly"));
list.add(new Versons("Kitkat"));
list.add(new Versons("Lolipop"));
list.add(new Versons("Milk"));
list.add(new Versons("Tea"));
list.add(new Versons("Oreo"));
versonsAdapter = new VersonsAdapter(MainActivity.this,R.layout.item_row,list);
listView.setAdapter(versonsAdapter);
}
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
int position = listView.getPositionForView(buttonView);
if (position != ListView.INVALID_POSITION){
Versons versions = list.get(position);
versions.setSelected(isChecked);
String items=versions.getVersion();
Select_list.add(items);
}
ArrayAdapter<String> slect=new ArrayAdapter(MainActivity.this,
androidx.appcompat.R.layout.support_simple_spinner_dropdown_item,Select_list);
Select_listView.setAdapter(slect);
}
}
OUTPUT
Practical-15
Create an application to take picture using native application.
Name: Tushar Tikia Roll no: 02590302022 Sem: VI Course: BCA
Project Structure
AndroidManifest.xml
</manifest>
activity_main.xml
MainActivity.java
package com.example.nativapplication;
import androidx.activity.result.ActivityResult;
import androidx.activity.result.ActivityResultCallback;
import androidx.activity.result.ActivityResultLauncher;
import androidx.activity.result.contract.ActivityResultContracts;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import android.app.Activity;
import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;
Button IMAGE;
ImageView view;
ActivityResultLauncher<Intent> mStartForResult = registerForActivityResult(new
ActivityResultContracts.StartActivityForResult(),
new ActivityResultCallback<ActivityResult>() {
@Override
public void onActivityResult(ActivityResult result) {
Toast.makeText(getApplicationContext(),result.toString(),Toast.LENGTH_LONG).sho
w();
if (result.getResultCode() == Activity.RESULT_OK) {
Intent intent = result.getData();
Bundle data=intent.getExtras();
Bitmap bitmap= (Bitmap) data.get("data");
view.setImageBitmap(bitmap);
}
}
});
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
IMAGE=findViewById(R.id.btn);
view=findViewById(R.id.imageview);
IMAGE.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent=new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
mStartForResult.launch(intent);
}
});
}
}
OUTPUT
MYAPP NATIVEAPP