0% found this document useful (0 votes)
102 views74 pages

Prathamesh MAD

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

Prathamesh MAD

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

Name : Jagtap Prathamesh Bhausaheb

RollNo : 23119
Div :A

Program no 1:
Demonstrate different Layouts with different views in android Layouts-
ConstraintLayout, RelativeLayout, TableLayout Views- Button, TextView,
EditText,WebView,CheckBox,RadioButton,ToggleButton,ImageButton,Ra
tingBar,ProgressBar,SeekBar,VideoView,DatePicker,CalendarView,
Spinner.

activity_examplee.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:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Examplee">
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello, RelativeLayout"/>
<Button

1
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Press Me"
android:layout_below="@id/textView1"
android:layout_alignParentStart="true"/>
<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Type something"
android:layout_below="@id/button1"/>
</RelativeLayout>
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="100dp">
<TableRow>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name:" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Enter name"/>
</TableRow>
<TableRow>
<TextView

2
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Age:" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:hint="Enter age"/>
</TableRow>
</TableLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginTop="180dp"
android:padding="10dp">
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Check me" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Option 1" />
<ToggleButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textOn="ON"
android:textOff="OFF" />
<ImageButton

3
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@android:drawable/ic_menu_camera" />
<RatingBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:numStars="5"
android:rating="3" />
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:indeterminate="true" />
<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<SeekBar
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<CalendarView
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<application
android:allowBackup="true"

4
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.DYPMCA"
tools:ignore="ExtraText"
tools:targetApi="31">
<activity
android:name=".Examplee"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

5
Output :

6
Program No 2:
Write an android code to make phone call using Intent

phonecall.java
package com.example.dypmca;
import android.os.Bundle;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.net.Uri;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
public class phonecall extends AppCompatActivity {
EditText edittext;
Button button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_phonecall);
button = findViewById(R.id.button);
edittext = findViewById(R.id.editText);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String number= edittext.getText().toString();

Intent it=new Intent(Intent.ACTION_DIAL);


it.setData(Uri.parse("tel:"+number));

7
startActivity(it)
}
});
}
}
activity_phonecall.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".phonecall">
<EditText
android:id="@+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"/>
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="115dp"
android:padding="5dp"
android:text="Make Call "/>

8
</RelativeLayout>
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<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.DYPMCA"
tools:ignore="ExtraText"
tools:targetApi="31">
<activity
android:name=".phonecall"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

9
Output :

10
Program No 3:
Write an android code to turn ON/OFF Bluetooth

Bluetooth.java
package com.example.dypmca;
import android.os.Bundle;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import android.content.pm.PackageManager;
import android.widget.Button;
import android.widget.Toast;
import android.content.Intent;
import android.bluetooth.BluetoothAdapter;
import android.Manifest;
import android.view.View;

public class Bluetooth extends AppCompatActivity {


@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_bluetooth);
Button bton = (Button) findViewById(R.id.bton);
Button btoff = (Button) findViewById(R.id.btoff);
final BluetoothAdapter btadp = BluetoothAdapter.getDefaultAdapter();

bton.setOnClickListener(new View.OnClickListener() {

@Override

11
public void onClick(View v) {
if (btadp == null) {
Toast.makeText(getApplicationContext(), "Bluetooth Not Supported",
Toast.LENGTH_LONG).show();

} else {
if (!btadp.isEnabled())
{
if (ActivityCompat.checkSelfPermission(Bluetooth.this,
Manifest.permission.BLUETOOTH_CONNECT) !=
PackageManager.PERMISSION_GRANTED)
{
return;
}
startActivityForResult(new
Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE),1);

Toast.makeText(getApplicationContext(), "Bluetooth Turned On",


Toast.LENGTH_SHORT).show();
}
}
}
});
btoff.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View v)
{
if (ActivityCompat.checkSelfPermission(Bluetooth.this,
Manifest.permission.BLUETOOTH_CONNECT) !=
PackageManager.PERMISSION_GRANTED)
{
return;

12
}
btadp.disable();
Toast.makeText(getApplicationContext(), "Bluetooth Turned Off",
Toast.LENGTH_SHORT).show();
}
});
}
}
activity_bluetooth.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:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#DBDDDF"
android:layout_gravity="center"
tools:context=".Bluetooth">
<Button
android:id="@+id/bton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/btoff"
android:text="Turn On"
tools:ignore="MissingConstraints"
tools:layout_editor_absoluteX="157dp"
tools:layout_editor_absoluteY="241dp" />
<Button
android:id="@+id/btoff"

13
android:layout_width="wrap_content"
android:layout_height="wrap_content"
tools:ignore="MissingConstraints"
tools:layout_editor_absoluteX="157dp"
tools:layout_editor_absoluteY="241dp"
android:text="Turn Off"/>
</androidx.constraintlayout.widget.ConstraintLayout>

AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<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.DYPMCA"
tools:ignore="ExtraText"
tools:targetApi="31">
<activity
android:name=".Bluetooth"
android:exported="true">

14
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

Output:

15
Program No 4 :
Write an android code to turn ON /OFF the Wi-Fi

Wifi.java

package com.example.dypmca;
import android.os.Bundle;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import android.annotation.SuppressLint;
import android.widget.Button;
import android.content.Context;
import android.view.View;
import android.net.wifi.WifiManager;
public class Wifi extends AppCompatActivity {
Button b1,b2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_wifi);
b1 = (Button) findViewById(R.id.btn1);
b2 =(Button) findViewById(R.id.btn2);

b1.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view) {
WifiManager wifi = (WifiManager)
getApplicationContext().getSystemService(Context.WIFI_SERVICE);
wifi.setWifiEnabled(true);
}

16
});
b2.setOnClickListener(new View.OnClickListener()
{ @Override
public void onClick(View view) { @SuppressLint("WifiManagerLeak")
WifiManager wifi = (WifiManager)
getApplicationContext().getSystemService(Context.WIFI_SERVICE);
wifi.setWifiEnabled(false);
}
});
}
}
activity_wifi.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#91C0E6"
android:orientation="vertical"
tools:context=".Wifi">
<Button
android:id="@+id/btn1"
android:layout_width="120dp"
android:layout_height="66dp"
android:backgroundTint="#9C27B0"
android:text="on"/>
<Button
android:id="@+id/btn2"
android:layout_width="120dp"

17
android:layout_height="66dp"
android:backgroundTint="#9C27B0"
android:text="Off"/>
</LinearLayout>

AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<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.DYPMCA"
tools:ignore="ExtraText"
tools:targetApi="31">
<activity
android:name=".login"
android:exported="false" />
<activity
android:name=".Wifi"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

18
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

Output:

19
Program No 5 :
Design android application for login activity. Write android code to check
login credentials with username = "mca" and password = "android".
Display appropriate toast message to the user.

activity_login.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/login_background"
android:gravity="center"
android:padding="16dp"
tools:context=".login">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical">
<ImageView
android:layout_width="160dp"
android:layout_height="160dp"
android:src="@drawable/icon_account_circle"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="32dp"
android:hint="Username"

20
android:textColor="@color/black"
android:textColorHint="@color/black"
android:textSize="20sp"
android:background="@color/white"
android:padding="18dp"
android:inputType="text"
android:id="@+id/username_input"/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:hint="Password"
android:textColor="@color/black"
android:textColorHint="@color/black"
android:textSize="20sp"
android:background="@color/white"
android:padding="18dp"
android:inputType="textPassword"
android:id="@+id/password_input"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Login"
android:backgroundTint="@color/white"
android:textColor="#3884F1"
android:padding="18dp"
android:layout_marginTop="32dp"
android:textSize="20sp"
android:id="@+id/login_btn"/>
</LinearLayout>

21
</RelativeLayout>
login.java
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
public class login extends AppCompatActivity {
EditText usernameInput,passwordInput;
Button loginBtn;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_login);
usernameInput=findViewById(R.id.username_input);
passwordInput=findViewById(R.id.password_input);
loginBtn=findViewById(R.id.login_btn);

loginBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if(usernameInput.getText().toString().equals("mca") &&
passwordInput.getText().toString().equals("android"))
{
Toast.makeText(login.this,"Login
Successful",Toast.LENGTH_SHORT).show();
}
else {

22
Toast.makeText(login.this,"Login Failed",Toast.LENGTH_SHORT).show();
}
}
});
}
}
AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>


<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<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.DYPMCA"
tools:ignore="ExtraText"
tools:targetApi="31">
<activity
android:name=".login"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

23
</application>
</manifest>

Output :

24
Program No 6:

Create a fragment that has its own UI and enable your activities to
communicate with fragments.

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="fill_parent"
android:layout_height="fill_parent"
tools:context="example.javatpoint.com.fragmentexample.MainActivity">
<fragment
android:id="@+id/fragment1"
android:name="example.javatpoint.com.fragmentexample.Fragment1"
android:layout_width="0px"
android:layout_height="match_parent" android:layout_weight="1" />
<fragment
android:id="@+id/fragment2"
android:name="example.javatpoint.com.fragmentexample.Fragment2"
android:layout_width="0px"
android:layout_height="match_parent"
android:layout_weight="1"/>
</LinearLayout>

fragment_fragment1.xml
<FrameLayout 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"

25
android:background="#F5F5DC"
tools:context="example.javatpoint.com.fragmentexample.Fragment1">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/hello_blank_fragment" />
</FrameLayout>

fragment_fragment2.xml
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#F0FFFF"
tools:context="example.javatpoint.com.fragmentexample.Fragment2">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="@string/hello_blank_fragment" />
</FrameLayout>

MainActivity.java
package example.javatpoint.com.fragmentexample;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

26
}
}
Fragment1.java
package example.javatpoint.com.fragmentexample;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class Fragment1 extends Fragment {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_fragment1, container, false);
}
}

Fragment2.java
package example.javatpoint.com.fragmentexample;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class Fragment2 extends Fragment {

27
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState){
// Inflate the layout for this fragment
return inflater.inflate(R.layout.fragment_fragment2, container, false);
}
}

Output :

28
Program No :7
Demonstrate Array Adapter using List View to display list of fruits.
activity_adapter.xml

<?xml version="1.0" encoding="utf-8"?>


<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingTop="200dp"
tools:context=".MainActivity">

<ListView
android:id="@+id/simpleListView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="30dp"/>

</RelativeLayout>

Adapter.java
package com.example.dypmca;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class Adapter extends AppCompatActivity {
ListView simpleListView;

String fruitList[] = {"Mango", "Apple", "Banana", "Grapes", "Watermelons", "pineapples",


"papayas"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_adapter);
simpleListView = (ListView) findViewById(R.id.simpleListView);

29
ArrayAdapter<String>arrayAdapter=newArrayAdapter<String>(this,R.layout.activity_fruitli
st,R.id.itemTextView, fruitList);
simpleListView.setAdapter(arrayAdapter);
}
}

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>


<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<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.DYPMCA"
tools:ignore="ExtraText"
tools:targetApi="31">
<activity
android:name=".Adapter"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

30
</application>
</manifest>

Output :

31
Program No :8
Write an application to demonstrate Alert Dialog Box in android

activity_allertt.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/yellow"
tools:context=".Allertt">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="180dp"
android:gravity="center_horizontal"
android:text="Press Back Button."
android:textSize="30dp"
android:textStyle="bold"
android:paddingLeft="20dp"
android:textColor="@color/black"/>
</RelativeLayout>

Allertt.java
import android.os.Bundle;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import android.content.DialogInterface;

32
import androidx.appcompat.app.AlertDialog;
public class Allertt extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_allertt);
}
@Override
public void onBackPressed() {

AlertDialog.Builder builder = new AlertDialog.Builder(Allertt.this);


builder.setMessage("Do you want to exit ?"); builder.setTitle("Alert !");
builder.setCancelable(false);
builder.setPositiveButton("Yes", (DialogInterface.OnClickListener) (dialog, which) -> {
finish();
});
builder.setNegativeButton("No", (DialogInterface.OnClickListener) (dialog, which) -> {
dialog.cancel();
});
AlertDialog alertDialog = builder.create();
alertDialog.show();
}
}

AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<application

33
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.DYPMCA"
tools:ignore="ExtraText"
tools:targetApi="31">
<activity
android:name=".Allertt"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

34
Output :

35
Program No : 9
Demonstrate Options Menu, Context Menu and Popup Menu in android

activity_option_menu_bar.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/cardview_light_background"
android:orientation="vertical"
tools:context=".OptionMenuBarDemo">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="openPopUpmenuBar"
android:id="@+id/btn1"
android:layout_gravity="center"
android:layout_marginTop="150dp"
android:text="Click Me" />
<ListView
android:layout_marginTop="200dp"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/contacts_list"
android:background="@color/purple_700"/>
</LinearLayout>

36
OptionMenuBarDemo.java
package com.example.menubardemo;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.Menu;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.ListView;
import android.widget.PopupMenu;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;

public class OptionMenuBarDemo extends AppCompatActivity {


Button btn1;
ListView contacts_list;
String[] contacts={"context1","context2","context3","context4","context5"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_option_menu_bar);

btn1=findViewById(R.id.btn1);

contacts_list=findViewById(R.id.contacts_list);

ArrayAdapter<String>adapter=newArrayAdapter<>(this,android.R.layout.simple_list_item_
1,contacts);
contacts_list.setAdapter(adapter);
registerForContextMenu(contacts_list);

37
}
public void openPopUpmenuBar (View view)
{
PopupMenu popupMenu = new PopupMenu(OptionMenuBarDemo.this, btn1);
popupMenu.getMenuInflater().inflate(R.menu.popup_menus, popupMenu.getMenu());
popupMenu.show();
}
@Override
public void onCreateContextMenu(ContextMenu menu, View v,
ContextMenu.ContextMenuInfo menuInfo) {
super.onCreateContextMenu(menu, v, menuInfo);
getMenuInflater().inflate(R.menu.context_menu,menu);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.option_menubars,menu);
return true;
}
}

AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<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"

38
android:supportsRtl="true"
android:theme="@style/Theme.DYPMCA"
tools:ignore="ExtraText"
tools:targetApi="31">
<activity
android:name=".OptionMenuBarDemo"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

Output :

39
40
Program No :10
Write an application to produce Notification

Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<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"
tools:context="example.javatpoint.com.androidnotification.MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ANDROID NOTIFICATION"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.091"
android:textAppearance="@style/Base.TextAppearance.AppCompat. Medium"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/button"
android:layout_marginBottom="112dp"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:text="Notify" app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
41
app:layout_constraintStart_toStartOf="parent" />
</android.support.constraint.ConstraintLayout>

activity_notification_view.xml

<?xml version="1.0" encoding="utf-8"?>


<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"
tools:context="example.javatpoint.com.androidnotification.NotificationView">
<TextView
android:id="@+id/textView2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="your detail of notification..."
android:textAppearance="@style/Base.TextAppearance.AppCompat. Medium"/>
<TextView
android:id="@+id/textView"
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"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.096"

42
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/textView2"
app:layout_constraintVertical_bias="0.206"
android:textAppearance="@style/Base.TextAppearance.AppCompat. Medium"/>
</android.support.constraint.ConstraintLayout>

MainActivity.java
package com.example.dypmca;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.NotificationCompat;

public class MainActivity extends AppCompatActivity {


Button button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_main);
button = findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v)

43
{ addNotification();
}
});
}
private void addNotification()
{
NotificationCompat.Builder builder = new NotificationCompat.Builder(this);
builder.setSmallIcon(R.drawable.messageicon);
builder.setContentTitle("Notifications Example");
builder.setContentText("This is a notification message");
builder.setAutoCancel(true);
builder.setPriority(NotificationCompat.PRIORITY_DEFAULT);
Intent notificationIntent = new Intent(this, afternotify.class);
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
notificationIntent.putExtra("message", "This is a notification message");
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
builder.setContentIntent(pendingIntent);
NotificationManager manager =
(NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
manager.notify(0, builder.build());
}
}

44
NotificationView.java
package com.example.dypmca;
import android.os.Bundle;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import android.widget.TextView;
public class NotificationView extends AppCompatActivity {
TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_notification_view);
textView = findViewById(R.id.textView);
String message=getIntent().getStringExtra("message");
textView.setText(message);
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<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"

45
android:theme="@style/Theme.DYPMCA"
tools:ignore="ExtraText"
tools:targetApi="31">
<activity
android:name=".MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

Output :

46
Program No : 11

Write an android application using SQLite to create table and perform


CRUD operations (Example. COURSE table (ID, Name, Duration,
Description), perform ADD, UPDATE, DELETE and READ operations)

MainActivity.java
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.To ast;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
private EditText courseNameEdt, courseTracksEdt, courseDurationEdt, courseDescriptionEdt;
private Button addCourseBtn; private DBHandler dbHandler;
@Override

protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState);


setContentView(R.layout.activity_main);
courseNameEdt = findViewById(R.id.idEdtCourseName); courseTracksEdt =
findViewById(R.id.idEdtCourseTracks); courseDurationEdt =
findViewById(R.id.idEdtCourseDuration); courseDescriptionEdt =
findViewById(R.id.idEdtCourseDescription);
addCourseBtn = findViewById(R.id.idBtnAddCourse);
dbHandler = new DBHandler(MainActivity.this); addCourseBtn.setOnClickListener(new
View.OnClickListener() {
@Override
public void onClick(View v) { String courseName =
courseNameEdt.getText().toString();
String courseTracks = courseTracksEdt.getText().toString();
String courseDuration = courseDurationEdt.getText().toString();
String courseDescription = courseDescriptionEdt.getText().toString();

47
if (courseName.isEmpty() && courseTracks.isEmpty() && courseDuration.isEmpty() &&
courseDescription.isEmpty()) {
Toast.makeText(MainActivity.this, "Please enter all the data..",
Toast.LENGTH_SHORT).show();
return;
}
dbHandler.addNewCourse(courseName, courseDuration, courseDescription, courseTracks);

Toast.makeText(MainActivity.this, "Course has been added.",


Toast.LENGTH_SHORT).show();
courseNameEdt.setText(""); courseDurationEdt.setText(""); courseTracksEdt.setText("");
courseDescriptionEdt.setText("");
}
});
}
javaclass_file

import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;
public class DBHandler extends SQLiteOpenHelper {
private static final String DB_NAME = "coursedb";
private static final int DB_VERSION = 1;
private static final String TABLE_NAME = "mycourses";
private static final String ID_COL = "id";
private static final String NAME_COL = "name";
private static final String DURATION_COL = "duration";
private static final String DESCRIPTION_COL = "description";
private static final String TRACKS_COL ="tracks";

48
public DBHandler(Context context) { super(context, DB_NAME, null, DB_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
String query = "CREATE TABLE " + TABLE_NAME + " ("
+ ID_COL + " INTEGER PRIMARY KEY

AUTOINCREMENT, "+ NAME_COL + " TEXT,"+ DURATION_COL + " TEXT,"+


DESCRIPTION_COL + "TEXT,"+ TRACKS_COL + "TEXT)";
db.execSQL(query);
}
public void addNewCourse(String courseName, String courseDuration, String
courseDescription, String courseTracks) {
SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(NAME_COL, courseName);
values.put(DURATION_COL, courseDuration);
values.put(DESCRIPTION_COL, courseDescription);
values.put(TRACKS_COL, courseTracks);
db.insert(TABLE_NAME, null, values);
db.close();
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int
newVersion) {
db.execSQL("DROP TABLE IF EXISTS " +TABLE_NAME);
onCreate(db);
}
}

49
Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" tools:context=".MainActivity">
<EditText
android:id="@+id/idEdtCourseName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:hint="Enter course Name" />
<EditText
android:id="@+id/idEdtCourseDuration"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:hint="Enter Course Duration" />
<EditText
android:id="@+id/idEdtCourseTracks"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:hint="Enter Course Tracks" />
<EditText
android:id="@+id/idEdtCourseDescription"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"

50
android:hint="Enter Course Description" />
<Button
android:id="@+id/idBtnAddCourse"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="Add Course" android:textAllCaps="false" />
</LinearLayout>

AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<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.Calculator"
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>

51
<meta-data
android:name="android.app.lib_name" android:value="" />
</activity>
</application>
</manifest>

Output :

52
Program No :12
Create an Android app, powered by Firebase Realtime database that
supports: Adding Data to Firebase Realtime database, Retrieving Data from
Firebase and Deleting data from firebase data.

Main.xml
package com.example.myfirebasedemo;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;
import android.os.Bundle;
import com.google.android.gms.tasks.OnCanceledListener;
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.Firebase;
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;
public class MainActivity extends AppCompatActivity {
EditText input_name,input_duration,input_track,input_description;
TextView txt_name,txt_duration,txt_track,txt_description,txt_id;
Button btn_Save,btn_Update,btn_Delete;
//private DBHandler dbHandler; private String editid="";
DatabaseReference
mydb=FirebaseDatabase.getInstance().getReference().child("MyCourse");

53
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
input_name=findViewById(R.id.edit1);
input_duration=findViewById(R.id.edit2);
input_track=findViewById(R.id.edit3);
input_description=findViewById(R.id.edit4);
btn_Save=findViewById(R.id.btnsave);
btn_Update=findViewById(R.id.btnupdate);
btn_Delete=findViewById(R.id.btndelete);
txt_name=findViewById(R.id.txtname);
txt_duration=findViewById(R.id.txtduration);
txt_track=findViewById(R.id.texttrac);
txt_description=findViewById(R.id.txtdesc);
txt_id=findViewById(R.id.txtid);
}
public void saveRecord(View view) {
String name = input_name.getText().toString();
String duration = input_duration.getText().toString();
String tracks = input_track.getText().toString();
String description = input_description.getText().toString();
MyCourse myc = new MyCourse(name, duration, description, tracks);
mydb.push().setValue(myc).addOnCompleteListener(new OnCompleteListener<Void>() {
@Override
public void onComplete(@NonNull Task<Void> task) {
Toast.makeText(MainActivity.this, "Record Saved Successfully",
Toast.LENGTH_SHORT).show();
}
}).addOnCanceledListener(new OnCanceledListener() {
@Override

54
public void onCanceled() {
Toast.makeText(MainActivity.this, "Something went Wrong..",
Toast.LENGTH_SHORT).show();
}
});
}
public void showLastRecord()
{
mydb.addValueEventListener(new ValueEventListener() { @Override
public void onDataChange(@NonNull DataSnapshot snapshot) {
mydb.orderByChild("id").limitToLast(1);
for(DataSnapshot snap1:snapshot.getChildren())
{
editid= snap1.getKey();
MyCourse myc=snap1.getValue(MyCourse.class);
String name=myc.getName();
String duration=myc.getDuration();
String tracks=myc.getTracks();
String description=myc.getDescription();
txt_name.setText(name);
txt_description.setText(description);
txt_duration.setText(duration);
txt_track.setText(tracks);
}
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
}
});
}

55
public void clearinputfield()
{
input_name.setText("");
input_duration.setText("");
input_description.setText("");
input_track.setText("");
}
public void seteditrecord(View view)
{
mydb.child(editid).get().addOnCompleteListener(new
OnCompleteListener<DataSnapshot>() { @Override
public void onComplete(@NonNull Task<DataSnapshot> task)
{ MyCourse cls1=task.getResult().getValue(MyCourse.class);
input_name.setText(cls1.name);
input_description.setText(cls1.description);
input_duration.setText(cls1.duration);
input_track.setText(cls1.tracks);
clearinputfield();
}
});
}
}
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">

56
<EditText
android:id="@+id/edit1"
android:layout_width="278dp"
android:layout_height="51dp"
android:ems="10"
android:hint="Course name"
android:inputType="text"
app:layout_constraintBottom_toTopOf="@+id/edit2"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.5" />

<EditText
android:id="@+id/edit2"
android:layout_width="274dp"
android:layout_height="49dp"
android:ems="10"
android:hint="Course Duration"
android:inputType="text"
app:layout_constraintBottom_toTopOf="@+id/edit3"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/edit1"
app:layout_constraintVertical_bias="0.5" />

<EditText

57
android:id="@+id/edit3"
android:layout_width="274dp"
android:layout_height="49dp"
android:ems="10" android:hint="course track"
android:inputType="text"
app:layout_constraintBottom_toTopOf="@+id/edit4"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/edit2"
app:layout_constraintVertical_bias="0.5" />

<EditText
android:id="@+id/edit4"
android:layout_width="276dp"
android:layout_height="48dp"
android:ems="10"
android:hint="course Description"
android:inputType="text"
app:layout_constraintBottom_toTopOf="@+id/btnsave"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/edit3"
app:layout_constraintVertical_bias="0.5" />

<Button
android:id="@+id/btnsave"
android:layout_width="109dp"
android:layout_height="62dp"

58
android:onClick="saveRecord"
android:text="Save"
app:layout_constraintBottom_toTopOf="@+id/txtid"
app:layout_constraintEnd_toStartOf="@+id/btnupdate"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/edit4"
app:layout_constraintVertical_bias="0.5" />

<Button
android:id="@+id/btnupdate"
android:layout_width="113dp"
android:layout_height="62dp"
android:onClick="update_record"
android:text="Update"
app:layout_constraintBottom_toTopOf="@+id/txtid"
app:layout_constraintEnd_toStartOf="@+id/btndelete"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/btnsave"
app:layout_constraintTop_toBottomOf="@+id/edit4"
app:layout_constraintVertical_bias="0.5" />

<Button
android:id="@+id/btndelete"
android:layout_width="107dp"
android:layout_height="62dp"
android:onClick="delete_record"
android:text="Delete"
app:layout_constraintBottom_toTopOf="@+id/txtid"
app:layout_constraintEnd_toEndOf="parent"

59
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/btnupdate"
app:layout_constraintTop_toBottomOf="@+id/edit4"
app:layout_constraintVertical_bias="0.5" />
<TextView
android:id="@+id/txtid"
android:layout_width="255dp"
android:layout_height="46dp"
android:layout_marginTop="12dp"
android:onClick="setEditRecord"
app:layout_constraintBottom_toTopOf="@+id/txtname"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.482"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/btnupdate"
app:layout_constraintVertical_bias="0.5" />
<TextView
android:id="@+id/txtname"
android:layout_width="253dp"
android:layout_height="57dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toTopOf="@+id/txtduration"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.501"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/txtid"
app:layout_constraintVertical_bias="0.5" />

<TextView
android:id="@+id/txtduration"

60
android:layout_width="245dp"
android:layout_height="54dp"
android:layout_marginTop="16dp"
app:layout_constraintBottom_toTopOf="@+id/texttrac"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.501"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/txtname"
app:layout_constraintVertical_bias="0.5" />
<TextView
android:id="@+id/texttrac"
android:layout_width="235dp"
android:layout_height="54dp"
android:layout_marginTop="16dp"
app:layout_constraintBottom_toTopOf="@+id/txtdesc"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.501"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/txtduration"
app:layout_constraintVertical_bias="0.5" />
<TextView
android:id="@+id/txtdesc"
android:layout_width="221dp"
android:layout_height="52dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/texttrac"
app:layout_constraintVertical_bias="0.5" />

61
</androidx.constraintlayout.widget.ConstraintLayout>
MyCourse.java
package com.example.myfirebasedemo;
public class MyCourse
{
String name,duration,tracks,description;
public MyCourse(String courseName,String courseDuration,String courseTracks,String
courseDescription)
{
this.name=courseName;
this.duration=courseDuration;
this.tracks=courseTracks;
this.description=courseDescription;
}
public MyCourse()
{
}
public String getName()
{
return name;
}
public String getDuration()
{
return duration;
}
public String getTracks()
{
return tracks;
}
public String getDescription()
{

62
return description;
}
}

Output :

63
Program No :13
Demonstrate WebView to display the web pages in an android application.

Activity_webview.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Webbview">
<WebView
android:id="@+id/web"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="8dp" />
</RelativeLayout>

Webbview.java
package com.example.dypmca;
import android.os.Bundle;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import android.webkit.WebView;
import android.webkit.WebViewClient;

public class Webbview extends AppCompatActivity {

64
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_webbview);
WebView webView = findViewById(R.id.web);

webView.loadUrl("https://www.google.com");
webView.getSettings().setJavaScriptEnabled(true);
webView.setWebViewClient(new WebViewClient());
}
}
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.DYPMCA"
tools:ignore="ExtraText"
tools:targetApi="31">
<activity
android:name=".Webbview"

65
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

Output :

66
Program No :14
Write an android app to write JSON data into a file and read JSON data
from created file.

activity_jsoon.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Jsoon">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="75dp"
android:layout_marginTop="46dp"
android:text="TextView" />
</RelativeLayout>

Jsoon.java
package com.example.dypmca;
import android.os.Bundle;
import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import org.json.JSONArray;

67
import org.json.JSONException;
import org.json.JSONObject;
import android.widget.TextView;
public class Jsoon extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
EdgeToEdge.enable(this);
setContentView(R.layout.activity_jsoon);

TextView output = (TextView) findViewById(R.id.textView1);


String strJson="{ \"Employee\":[{\"id\":\"101\",\"name\":\"Vaishnavi
Jagtap\",\"salary\":\"50000\"},{\"id\":\"102\",\"name\":\"Kajal
Bhapkar\",\"salary\":\"60000\"}] }";
String data = "";
try {
JSONObject jo= new JSONObject(strJson);
JSONArray jsonArray = jo.optJSONArray("Employee");
for(int i=0; i < jsonArray.length(); i++){
JSONObject jsonObject = jsonArray.getJSONObject(i);
int id = Integer.parseInt(jsonObject.optString("id").toString()); String name =
jsonObject.optString("name").toString();
float salary = Float.parseFloat(jsonObject.optString("salary").toString());
data += "Node"+i+" : \n id= "+ id +" \n Name= "+ name +" \n Salary= "+ salary
+" \n ";
}
output.setText(data);
} catch (JSONException e) {e.printStackTrace();}
}
}

68
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<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.DYPMCA"
tools:ignore="ExtraText"
tools:targetApi="31">
<activity
android:name=".Jsoon"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>

69
Output :

70
Program No :15
Write an application to display a PDF as an image in React app using URL

PDFViewer.js
import React from 'react';
import { Worker, Viewer } from '@react-pdf-viewer/core';
import '@react-pdf-viewer/core/lib/styles/index.css';
import '@react-pdf-viewer/default-layout/lib/styles/index.css';
const PDFViewer = ({ pdfUrl }) => {
return (
<div>
<WorkerworkerUrl={`https://unpkg.com/pdfjs-
dist@2.9.359/build/pdf.worker.min.js`}>
<Viewer fileUrl={pdfUrl} />
</Worker>
</div>
);
};
export default PDFViewer;

App.js
import React from 'react';
import PDFViewer from './PDFViewer';
import './App.css';
const App = () => {
const pdfUrl =” https://imcc.mespune.in/wp-content/uploads/2022/12/Syllabus-MCA- 2020-
Pattern-1.pdf
”;
return (
<div className="App">
<h1>PDF Viewer</h1>

71
<PDFViewer pdfUrl={pdfUrl} />
</div>
);
};
export default App;

Output :

72
Program No :16
Develop simple flutter application to open a browser using Android SDK

Main.dart
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';
void main(){
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: HomeScreen(),
);
}
}
class HomeScreen extends StatelessWidget {
final String url = " https://developer.android.com";

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Open Browser Example'),
),
body: Center(
child: ElevatedButton(
onPressed: _launchURL,
child: Text('Open Browser'),

73
),
),
);
}
void _launchURL() async {
if (!await launch(url)) throw 'Could not launch $url';
}
}

Output :

74

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy