0% found this document useful (0 votes)
11 views73 pages

MAD Practical ?vraj

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)
11 views73 pages

MAD Practical ?vraj

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/ 73

Practical -1 Enrollment Number:226240316184

MainActivity.java

Output

Activity_main.xml
Practical -2 Enrollment Number:226240316184

MainActivity.java Output

Activity_main.xml
Practical -3 Enrollment Number: 226240316184

MainActivity.java

Activity_main.xml
Practical -3 Enrollment Number: 226240316184

Outputs

Addition

Not entering
either of the
field or both

Division by zero
Practical -4 Enrollment Number: 226240316184

MainActivity.java

Output

Activity_main.xml
Practical -5 Enrollment Number: 226240316184

MainActivity.java

Output

Activity_main.xml
Mobile Application Development (4351604)
Enrollment No. 226240316184

Practical 6
Aim: Develop an Android application that uses ScrollView to display a long list of items.

INPUT:

1. Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical">
<TextView
android:id="@+id/txt6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="216150316010"
android:gravity="right"
android:textSize="18dp"/>
<LinearLayout
android:id="@+id/linear1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="10dp">
<Button
android:id="@+id/upbtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Up"
android:backgroundTint="@color/black"
android:layout_weight="1"/>
Mobile Application Development (4351604)
Enrollment No. 226240316184

<Button
android:id="@+id/downbtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Down"
android:backgroundTint="@color/black"
android:layout_weight="1"/>
</LinearLayout>
<ScrollView
android:id="@+id/scrollview"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="@+id/linear2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="button 1"
android:backgroundTint="@color/black"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="button 2"
android:backgroundTint="@color/black"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="button 3"
android:backgroundTint="@color/black"/>
<Button
android:layout_width="match_parent"
Mobile Application Development (4351604)
Enrollment No. 226240316184

android:layout_height="wrap_content"
android:text="button 4"
android:backgroundTint="@color/black"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="button 5"
android:backgroundTint="@color/black"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="button 6"
android:backgroundTint="@color/black"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="button 7"
android:backgroundTint="@color/black"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="button 8"
android:backgroundTint="@color/black"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="button 9"
android:backgroundTint="@color/black"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="button 10"
android:backgroundTint="@color/black"/>
Mobile Application Development (4351604)
Enrollment No. 226240316184

<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="button 11"
android:backgroundTint="@color/black"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="button 12"
android:backgroundTint="@color/black"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="button 13"
android:backgroundTint="@color/black"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="button 14"
android:backgroundTint="@color/black"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="button 15"
android:backgroundTint="@color/black"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="button 16"
android:backgroundTint="@color/black"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="button 17"
Mobile Application Development (4351604)
Enrollment No. 226240316184

android:backgroundTint="@color/black"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="button 18"
android:backgroundTint="@color/black"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="button 19"
android:backgroundTint="@color/black"/>
<Button
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="button 20"
android:backgroundTint="@color/black"/>
</LinearLayout>
</ScrollView>
</LinearLayout>

2. MainActivity.java
package com.example.practical6vertical;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ScrollView;
import com.google.android.material.snackbar.Snackbar;
public class MainActivity extends AppCompatActivity {
Button btn_up;
Button btn_down;
ScrollView sc_view;
@Override
Mobile Application Development (4351604)
Enrollment No. 226240316184

protected void onCreate(Bundle savedInstanceState) {


super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn_up = findViewById(R.id.upbtn);
btn_down = findViewById(R.id.downbtn);
sc_view = findViewById(R.id.scrollview);
btn_up.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
int x = sc_view.getScrollX();
int y = sc_view.getScrollY();
Snackbar sb = Snackbar.make(view,x+","+y,Snackbar.LENGTH_LONG);
sb.show();
if(y+50>=0)
{
sc_view.scrollTo(x,y+50);
}
}
});
btn_down.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
int x = sc_view.getScrollX();
int y = sc_view.getScrollY();
int maxamount = sc_view.getMaxScrollAmount();
Snackbar sb = Snackbar.make(view,x+","+y,Snackbar.LENGTH_LONG);
sb.show();
if(y-50<=maxamount)
{
sc_view.scrollTo(x,y-50);
}
}
});
}}
Mobile Application Development (4351604)
Enrollment No. 226240316184

3. 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.Practical6vertical"
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>
Mobile Application Development (4351604)
Enrollment No. 226240316184

OUTPUT:
Mobile Application Development (4351604)
Enrollment No. 226240316184

Practical 7
Aim: Develop an Android application that uses ListView and Custom Adapter to display a
list of images with text.

INPUT:
1. Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical">
<TextView
android:id="@+id/txt6"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="216150316010"
android:gravity="right"
android:textSize="18dp"/>
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/listview1" />
</LinearLayout>

2. MainActivity.java
package com.example.pr7;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ListView;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
ListView list;
String[] maintitle =
{"Riddhi","Dharang","Urvi","Anjali","Archi","Nainsi","Mansi","Neni","Jeni","Urmil
"};
String[] subtitle = {"1","2","3"," 4","5","6","7","8","9","10"};
Mobile Application Development (4351604)
Enrollment No. 226240316184

Integer[] imgid =
{R.drawable.girl1,R.drawable.boy1,R.drawable.girl2,R.drawable.girl3,R.drawable.gir
l4,R.drawable.girl5,R.drawable.girl6,R.drawable.girl7,R.drawable.girl8,R.drawable.b
oy2};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
student adapter=new student(this,maintitle,subtitle,imgid);
list=(ListView) findViewById(R.id.listview1);
list.setAdapter(adapter);
list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long
l) {
int position = 0;
if(position==0){
Toast.makeText(getApplicationContext(),"Add Student
Details",Toast.LENGTH_SHORT).show();
}
else if (position==1) {
Toast.makeText(getApplicationContext(),"Add Student Details",
Toast.LENGTH_SHORT).show();
}
else if (position==2) {
Toast.makeText(getApplicationContext(),"Add Student
Details",Toast.LENGTH_SHORT).show();
}
else if (position==3) {
Toast.makeText(getApplicationContext(),"Add Student
Details",Toast.LENGTH_SHORT).show();
}
else if (position==4) {
Toast.makeText(getApplicationContext(),"Add Student
Details",Toast.LENGTH_SHORT).show();
}
}
});
}

3. Activity_student.xml
Mobile Application Development (4351604)
Enrollment No. 226240316184

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


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".Activity_student"
android:orientation="horizontal">
<ImageView
android:layout_width="60dp"
android:layout_height="60dp"
android:id="@+id/icon"
android:padding="5dp"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:orientation="horizontal"
android:weightSum="2.7">
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="0dp"
android:text="Name" />
<TextView
android:id="@+id/subtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="90dp"
android:layout_weight="1.5"
android:padding="20dp"
android:text="Number" />
</LinearLayout>
</LinearLayout>

4. Activity_student.java
package com.example.pr7;
import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
import com.example.pr7.R;
Mobile Application Development (4351604)
Enrollment No. 226240316184

class student extends ArrayAdapter<String>{


private final Activity context;
private final String[] maintitle;
private final String[] subtitle;
private final Integer[] imgid;
public student(Activity context, String[] maintitle, String[] subtitle, Integer[]
imgid){
super(context, R.layout.activity_student,maintitle);
this.context=context;
this.maintitle=maintitle;
this.subtitle=subtitle;
this.imgid=imgid;
}
public View getView(int position,View view,ViewGroup parent){
LayoutInflater inflater=context.getLayoutInflater();
View rowView=inflater.inflate(R.layout.activity_student,null,true);
TextView titleText=(TextView) rowView.findViewById(R.id.title);
ImageView imageView=(ImageView) rowView.findViewById(R.id.icon);
TextView subtitleText=(TextView) rowView.findViewById(R.id.subtitle);
titleText.setText(maintitle[position]);
imageView.setImageResource(imgid[position]);
subtitleText.setText(subtitle[position]);
return rowView;
}
}

5. 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.Pr7"
tools:targetApi="31">
<activity
android:name=".Activity_student"
android:exported="false" />
<activity
android:name=".MainActivity"
android:exported="true">
Mobile Application Development (4351604)
Enrollment No. 226240316184

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

OUTPUT:
Practical -8 Enrollment Number:226240316184

Output
MainActivity.java

Activity_main.xml

Nav_menu.xml
Practical -9 Enrollment Number:226240316184

Output
MainActivity.java

Activity_main.xml

Nav_menu.xml
Enrollment Number:226240316184
Practical -10
Output
MainActivity.java

Activity_main.xml
Enrollment Number:226240316184
Practical -10

view_activity.xml

ViewActivity.xml
Mobile Application Development (4351604)
Enrollment no:226240316184

Practical 11
Aim: Develop an Android application that uses Services to perform background tasks.

INPUT:
1. Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<Button
android:layout_width="210dp"
android:layout_height="wrap_content"
android:text="START service"
android:id="@+id/b1"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" />
<Button
android:layout_width="210dp"
android:layout_height="wrap_content"
android:text="STOP service"
android:id="@+id/b2"
android:layout_below="@+id/b1"
android:layout_centerHorizontal="true" />
</RelativeLayout>

2. MainActivity.java
package com.example.practical11;
import …
public class MainActivity extends AppCompatActivity {
Button b1;
Button b2;
@SuppressLint("MissingInflatedId")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b1 = findViewById(R.id.b1);
b2 = findViewById(R.id.b2);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Mobile Application Development (4351604)
Enrollment no:226240316184

Intent i = new Intent(getApplicationContext(),MyService.class);


startService(i);
}
});
b2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent i=new Intent(getApplicationContext(),MyService.class);
stopService(i);
}
});
}
}

3. MyService.java
package com.example.practical11;
import …
public class MyService extends Service {
public MyService() {
}
@Override
public IBinder onBind(Intent intent) {
// TODO: Return the communication channel to the service.
throw new UnsupportedOperationException("Not yet implemented");
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Toast.makeText(this, "Service started...", Toast.LENGTH_SHORT).show();
Log.d("MyService", "Service Started");
return START_STICKY;
}
@Override
public void onDestroy() {
super.onDestroy();
Toast.makeText(this, "Service stopped...", Toast.LENGTH_SHORT).show();
}
}

4. 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"
Mobile Application Development (4351604)
Enrollment no:226240316184

android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Practical11"
tools:targetApi="31">
<service
android:name=".MyService"
android:enabled="true"
android:exported="true"></service>
<activity
android:name=".MyService"
android:exported="false" />
<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:
Mobile Application Development (4351604)
Enrollment no:226240316184

Practical 12
Aim: Develop an Android application that uses Broadcast Receivers to receive and handle system-
level broadcasts.

1. AIRPLANE MODE:
INPUT:
1.1 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>’

1.2 MainActivity.java
package com.example.practical12;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
public class MainActivity extends AppCompatActivity {
MyAirPlaneReceiver receiver;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

IntentFilter intfilter = new


IntentFilter(Intent.ACTION_AIRPLANE_MODE_CHANGED);
receiver = new MyAirPlaneReceiver();
registerReceiver(receiver,intfilter);
}
@Override
protected void onStop(){
super.onStop();
unregisterReceiver(receiver);
Mobile Application Development (4351604)
Enrollment no:226240316184

}
}

1.3 MyAirPlaneReciever.java
package com.example.practical12;
import …
public class MyAirPlaneReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// TODO: This method is called when the BroadcastReceiver is receiving
// an Intent broadcast.
if(Settings.Global.getInt(context.getContentResolver(),Settings.Global.AIRPLANE_MODE_
ON,0)!=0){
Toast.makeText(context, "AirpalneMode On", Toast.LENGTH_SHORT).show();
}
else{
Toast.makeText(context.getApplicationContext(), "AirplaneMode Off",
Toast.LENGTH_SHORT).show();
}
}
}

1.4 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.Practical12"
tools:targetApi="31">
<receiver
android:name=".MyAirPlaneReceiver"
android:enabled="true"
android:exported="true"></receiver>
<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>
Mobile Application Development (4351604)
Enrollment no:226240316184

</application>
</manifest>

OUPUT:

2. BATTERYRECEIVER:
INPUT:
2.1 Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<Button
android:id="@+id/start_btn"
android:layout_below="@id/txt1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="START"
android:textSize="30dp"
android:backgroundTint="@color/black"/>
<Button
Mobile Application Development (4351604)
Enrollment no:226240316184

android:id="@+id/stop_btn"
android:layout_below="@id/start_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="STOP"
android:textSize="30dp"
android:backgroundTint="@color/black"/>
</RelativeLayout>

2.2 MainActivity.java
package com.example.pr12;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {


MyBatteryReceiver receiver;
Button start;
Button stop;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
MyBatteryReceiver receiver = new MyBatteryReceiver();
start = findViewById(R.id.start_btn);
stop = findViewById(R.id.stop_btn);
start.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
IntentFilter mIntentFilter = new
IntentFilter(Intent.ACTION_BATTERY_CHANGED);
registerReceiver(receiver,mIntentFilter);
}
});
stop.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
unregisterReceiver(receiver);
}
});
}
}

2.3 MyBatteryReciever.java
package com.example.pr12;
import android.content.BroadcastReceiver;
import android.content.Context;
Mobile Application Development (4351604)
Enrollment no:226240316184

import android.content.Intent;
import android.widget.Toast;
public class MyBatteryReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// TODO: This method is called when the BroadcastReceiver is receiving
// an Intent broadcast.
int percentage = intent.getIntExtra("level",0);
Toast.makeText(context.getApplicationContext(), "Battery is:"+percentage+"%",
Toast.LENGTH_SHORT).show();
// throw new UnsupportedOperationException("Not yet implemented");
}
}
2.4 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.Pr12"
tools:targetApi="31">
<receiver
android:name=".MyBatteryReceiver"
android:enabled="true"
android:exported="true"></receiver>
<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>
Mobile Application Development (4351604)
Enrollment no:226240316184

</manifest>

OUPUT:
Mobile Application Development (4351604)
Enrollment no:226240316184

Practical 13
Aim: Develop an Android application that uses Content Providers to share data between different
apps and components.

INPUT:
1. Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:orientation="vertical">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name"
android:layout_marginLeft="100dp"
android:textSize="25dp"
android:textStyle="bold"
android:textColor="@color/black"
android:layout_marginTop="200dp"/>
<EditText
android:id="@+id/editTxt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="100dp"
android:layout_marginTop="10dp"
android:layout_marginRight="50dp"
android:minHeight="48dp"
android:textColor="@color/black"
android:hint="@string/hintText" />
<Button
android:id="@+id/btnAdd"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="100dp"
android:text="Add User"
android:textSize="30dp"
android:backgroundTint="@color/black"
android:layout_marginTop="10dp"
android:onClick="onClickAddDetails"/>
<Button
android:id="@+id/btnShow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="100dp"
Mobile Application Development (4351604)
Enrollment no:226240316184

android:text="Show Users"
android:textSize="30dp"
android:backgroundTint="@color/black"
android:onClick="onClickShowDetails"/>
<TextView
android:id="@+id/resTxt"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text=""
android:layout_marginLeft="100dp"
android:textSize="25dp"
android:textStyle="bold"
android:textColor="@color/black"
android:layout_marginTop="10dp"/>
</LinearLayout>

2. MainActivity.java
package com.example.practical13;
import …
public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
// public boolean onTouchEvent(MotionEvent event) {
// InputMethodManager imm =
(InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
// imm.hideSoftInputFromWindow(getCurrentFocus().getWindowToken(), 0);
// return true;
// }
public void onClickAddDetails(View view) {
ContentValues values = new ContentValues();
values.put(UserProvider.name, ((EditText)
findViewById(R.id.editTxt)).getText().toString());
getContentResolver().insert(UserProvider.CONTENT_URI, values);
Toast.makeText(getBaseContext(), "New Record Inserted",
Toast.LENGTH_LONG).show();
}
@SuppressLint("Range")
public void onClickShowDetails(View view) {
TextView resultView= (TextView) findViewById(R.id.resTxt);
Cursor cursor =
getContentResolver().query(Uri.parse("content://com.example.practical13.UserProvider/users
"), null, null, null, null);
if(cursor.moveToFirst()) {
StringBuilder strBuild=new StringBuilder();
while (!cursor.isAfterLast()) {
Mobile Application Development (4351604)
Enrollment no:226240316184

strBuild.append("\n"+cursor.getString(cursor.getColumnIndex("id"))+ "-"+
cursor.getString(cursor.getColumnIndex("name")));
cursor.moveToNext();
}
resultView.setText(strBuild);
}
else {
resultView.setText("No Records Found");
}
}
}

3. UserProvider.java
package com.example.practical13;
import …
public class UserProvider extends ContentProvider {
public UserProvider(){
}
static final String PROVIDER_NAME = "com.example.practical13.UserProvider";
static final String URL = "content://" + PROVIDER_NAME + "/users";
static final Uri CONTENT_URI = Uri.parse(URL);
static final String id = "id";
static final String name = "name";
static final int uriCode = 1;
static final UriMatcher uriMatcher;
private static HashMap<String, String> values;
static {
uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
uriMatcher.addURI(PROVIDER_NAME, "users", uriCode);
uriMatcher.addURI(PROVIDER_NAME, "users/*", uriCode);
}
@Nullable
@Override
public String getType(@NonNull Uri uri) {
switch (uriMatcher.match(uri)) {
case uriCode:
return "vnd.android.cursor.dir/users";
default:
throw new IllegalArgumentException("Unsupported URI: " + uri);
}
}
@Override
public boolean onCreate() {
Context context = getContext();
DatabaseHelper dbHelper = new DatabaseHelper(context);
db = dbHelper.getWritableDatabase();
if (db != null) {
return true;
}
return false;
Mobile Application Development (4351604)
Enrollment no:226240316184

}
@Nullable
@Override
public Cursor query(@NonNull Uri uri, @Nullable String[] projection, @Nullable String
selection, @Nullable String[] selectionArgs, @Nullable String sortOrder) {
SQLiteQueryBuilder qb = new SQLiteQueryBuilder();
qb.setTables(TABLE_NAME);
switch (uriMatcher.match(uri)) {
case uriCode:
qb.setProjectionMap(values);
break;
default:
throw new IllegalArgumentException("Unknown URI " + uri);
}
if (sortOrder == null || sortOrder == "") {
sortOrder = id;
}
Cursor c = qb.query(db, projection, selection, selectionArgs, null,
null, sortOrder);
c.setNotificationUri(getContext().getContentResolver(), uri);
return c;
}
@Nullable
@Override
public Uri insert(@NonNull Uri uri, @Nullable ContentValues values) {
long rowID = db.insert(TABLE_NAME, "", values);
if (rowID > 0) {
Uri _uri = ContentUris.withAppendedId(CONTENT_URI, rowID);
getContext().getContentResolver().notifyChange(_uri, null);
return _uri;
}
throw new SQLiteException("Failed to add a record into " + uri);
}
@Override
public int update(Uri uri, ContentValues values, String selection,
String[] selectionArgs) {
int count = 0;
switch (uriMatcher.match(uri)) {
case uriCode:
count = db.update(TABLE_NAME, values, selection, selectionArgs);
break;
default:
throw new IllegalArgumentException("Unknown URI " + uri);
}
getContext().getContentResolver().notifyChange(uri, null);
return count;
}

@Override
public int delete(Uri uri, String selection, String[] selectionArgs) {
int count = 0;
Mobile Application Development (4351604)
Enrollment no:226240316184

switch (uriMatcher.match(uri)) {
case uriCode:
count = db.delete(TABLE_NAME, selection, selectionArgs);
break;
default:
throw new IllegalArgumentException("Unknown URI " + uri);
}
getContext().getContentResolver().notifyChange(uri, null);
return count;
}
private SQLiteDatabase db;
static final String DATABASE_NAME = "Example";
static final String TABLE_NAME = "User";
static final int DATABASE_VERSION = 1;
static final String CREATE_DB_TABLE = " CREATE TABLE " + TABLE_NAME
+ " (id INTEGER PRIMARY KEY AUTOINCREMENT, "
+ " name TEXT NOT NULL);";
private static class DatabaseHelper extends SQLiteOpenHelper {
DatabaseHelper(Context context) {
super(context, DATABASE_NAME, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(CREATE_DB_TABLE);
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
// sql query to drop a table
// having similar name
db.execSQL("DROP TABLE IF EXISTS " + TABLE_NAME);
onCreate(db);
}
}
}

4. AndoridManifest.java
<?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.Practical13"
tools:targetApi="31">
<activity
Mobile Application Development (4351604)
Enrollment no:226240316184

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>
<provider
android:authorities="com.example.practical13.UserProvider"
android:name=".UserProvider"></provider>
</application>
</manifest>

OUTPUT:

1-Vraj
2-Mantavya
3-Raj
4-Rudray
5-Ved
Mobile Application Development (4351604)
Enrollment no:226240316184

Practical 14
Aim: Develop an Android application that uses Content Providers to read system-level data, such as
contacts and calendar events.

INPUT:
1. 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">
<ListView
android:id="@+id/contactListView1"
android:layout_marginTop="30dp"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</androidx.constraintlayout.widget.ConstraintLayout>

2. MainActivity.java
package com.example.practical14;
import …
public class MainActivity extends AppCompatActivity {

private ListView contactListView;


private ArrayAdapter<String> adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
contactListView = findViewById(R.id.contactListView1);
adapter = new ArrayAdapter<>(this, android.R.layout.simple_list_item_1);
contactListView.setAdapter(adapter);
if (hasReadContactPermission()){
displayContactInfo();
}else {
requestContactPermission();
}
}
private boolean hasReadContactPermission(){
return checkSelfPermission(Manifest.permission.READ_CONTACTS) ==
android.content.pm.PackageManager.PERMISSION_GRANTED;
}
private void requestContactPermission(){
requestPermissions(new String[]{android.Manifest.permission.READ_CONTACTS},
1);
Mobile Application Development (4351604)
Enrollment no:226240316184

}
@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) {
displayContactInfo();
}
}
}
private void displayContactInfo(){
ArrayList<String> contactInfoList = new ArrayList<>();
Uri contactsUri = ContactsContract.Contacts.CONTENT_URI;
String[] projection = {
ContactsContract.Contacts.DISPLAY_NAME,
ContactsContract.Contacts._ID
};
Cursor cursor = getContentResolver().query(contactsUri, projection, null,null,null);
if (cursor != null){
while (cursor.moveToNext()){
@SuppressLint("Range") String contactName =
cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
@SuppressLint("Range") String contactId =
cursor.getString(cursor.getColumnIndex(ContactsContract.Contacts._ID));
if (contactName != null && contactId != null ){
ArrayList<String> phoneNumbers = getContactPhoneNumbers(contactId);
StringBuilder contactInfo = new StringBuilder(contactName);
for (String phoneNumber : phoneNumbers){
if (phoneNumber != null){
contactInfo.append("\n").append(phoneNumber);
}
}
contactInfoList.add(contactInfo.toString());
}
}
cursor.close();

adapter.addAll(contactInfoList);
}
}
private ArrayList<String> getContactPhoneNumbers(String contactId){
ArrayList<String> phoneNumbers = new ArrayList<>();
Uri phoneNumbersuri = ContactsContract.CommonDataKinds.Phone.CONTENT_URI;
String[] projection ={
ContactsContract.CommonDataKinds.Phone.NUMBER
};
String selection = ContactsContract.CommonDataKinds.Phone.CONTACT_ID + "= ?";
String[] selectionArgs = {contactId};
Mobile Application Development (4351604)
Enrollment no:226240316184

Cursor cursor = getContentResolver().query(phoneNumbersuri,


projection,selection,selectionArgs,null);
if (cursor != null){
while (cursor.moveToNext()){
@SuppressLint("Range") String phoneNumber =
cursor.getString(cursor.getColumnIndex(ContactsContract.CommonDataKinds.Phone.NUMB
ER));
phoneNumbers.add(phoneNumber);
}
cursor.close();
}
return phoneNumbers;
}
}

3. Contact_list.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<TextView
android:id="@+id/textView3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="216150316010"
android:gravity="right"
android:textSize="18dp" />
<TextView
android:id="@+id/text1"
android:layout_marginTop="30dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Contact Name"
android:textStyle="bold"
android:textSize="25dp"></TextView>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="number"
android:textSize="20dp"></TextView>
</LinearLayout>

4. 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.READ_CONTACTS"/>
Mobile Application Development (4351604)
Enrollment no:226240316184

<uses-permission android:name="android.permission.WRITE_CONTACTS"/>
<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.Practical14"
tools:targetApi="31">
<activity
android:name=".contacts_list_item"
android:exported="false" />
<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:
Enrollment Number:226240316184

Practical: 15 & 16

DBHandler.java
package com.example.sqliteexample;

import …

public class DBHandler extends SQLiteOpenHelper {

private static final String DB_USERS = "DBUers";

private static final String TABLE_MARKS = "Users";

private static final String KEY_ENO = "eno";


private static final String KEY_SUBNAME = "sub_name";
private static final String KEY_MARKS = "marks";

public DBHandler(Context context) {


super(context, DB_USERS, null, 1);
}

@Override
public void onCreate(SQLiteDatabase db) {

String create_table_query = "CREATE TABLE " + TABLE_MARKS +


" (" + KEY_ENO +" INTEGER PRIMARY KEY,"
+ KEY_SUBNAME + " TEXT,"
+ KEY_MARKS + " TEXT)";

@Override
public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1)
{

sqLiteDatabase.execSQL("DROP TABLE IF EXISTS" + TABLE_MARKS);


onCreate(sqLiteDatabase);

public void addUser(int i, String username, String password) {

SQLiteDatabase db = this.getWritableDatabase();

ContentValues values = new ContentValues();


values.put(KEY_ENO, i);
values.put(KEY_SUBNAME, username);
values.put(KEY_MARKS, password);
db.insert(TABLE_MARKS,null, values);

}
Enrollment Number:226240316184

public ArrayList<UserModel> readUser(){

SQLiteDatabase db = this.getReadableDatabase();

Cursor cursor = db.rawQuery("SELECT * FROM "+TABLE_MARKS,


null);

ArrayList<UserModel> arrUser = new ArrayList<>();

while(cursor.moveToNext()){
UserModel model = new UserModel();

model.enrollmentNo = cursor.getInt(0);
model.subject = cursor.getString(1);
model.marks = cursor.getString(2);
arrUser.add(model);
}
return arrUser;

public void updateUser(UserModel model){

SQLiteDatabase db = this.getWritableDatabase();

ContentValues values = new ContentValues();


values.put("ID", "123");

db.update(TABLE_MARKS,values,"uid = ? ", new


String[]{model.enrollmentNo+""});

public void delete(UserModel model){

SQLiteDatabase db = this.getWritableDatabase();
db.delete("Users","uid = ?",new
String[]{model.enrollmentNo+""});

}
}

MainActivity.java
package com.example.sqliteexample;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.TextView;

import java.util.ArrayList;

public class MainActivity extends AppCompatActivity {

TextView textView;

@Override
protected void onCreate(Bundle savedInstanceState) {
Enrollment Number:226240316184

super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView = findViewById(R.id.textView);

DBHandler dbHandler = new DBHandler(this);

dbHandler.addUser(1, "Networks", "99");


dbHandler.addUser(2, "AJava", "98");
dbHandler.addUser(3, "Android", "100");

//creating object of model class which needs to be updated/deleted.

UserModel model = new UserModel();


model.enrollmentNo = 3;
model.subject = "Android";
model.marks = "100";

//To update
dbHandler.updateUser(model);

//To delete
dbHandler.delete(model);

//To read data and displaying on textView


ArrayList<UserModel> arrayList = new ArrayList<>();
arrayList = dbHandler.readUser();

for (int i = 0; i < arrayList.size(); i++) {


textView.append("id: " + arrayList.get(i).enrollmentNo + "
username: " +
arrayList.get(i).subject + " password:" +
arrayList.get(i).marks +"\n");
}

}
}

Output:
Enrollment Number:226240316184

Practical 17
Inserting data into Firebase

AddMarksActivity.java
package com.example.firebasedbapp;

import …

public class AddMarksActivity extends AppCompatActivity {

private EditText editTextEno;


private EditText editTextSubject;
private EditText editTextMarks;
private Button btnSubmit;

private FirebaseDatabase firebaseDatabase;


private DatabaseReference myRef;
MarksModel marksModel;

private String eno, sub, marks;

protected void onCreate(Bundle savedInstanceState) {


super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_marks);

editTextEno = findViewById(R.id. editTextEno);


editTextSubject = findViewById(R.id. editTextSubject);
editTextMarks = findViewById(R.id. editTextMarks);
btnSubmit = findViewById(R.id.btnSubmit);

firebaseDatabase = FirebaseDatabase.getInstance();
myRef = firebaseDatabase.getReference().child("marks_data");

btnSubmit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {

eno = editTextEno.getText().toString();
sub = editTextSubject.getText().toString();
marks = editTextMarks.getText().toString();

myRef.addValueEventListener(new ValueEventListener() {

@Override
public void onDataChange(@NonNull DataSnapshot snapshot) {

DatabaseReference newRef = myRef.push();


String key = newRef.getKey();
marksModel = new MarksModel(eno, sub,marks,key);
newRef.setValue(marksModel);

Toast.makeText(AddMarksActivity.this, "Successful",
Toast.LENGTH_SHORT).show();
}
Enrollment Number:226240316184

@Override
public void onCancelled(@NonNull DatabaseError error) {
String er = error.getDetails();
Toast.makeText(AddMarksActivity.this, er, Toast.LENGTH_SHORT).show();
}
});

}
});

Output:
Enrollment Number:226240316184

Practical 18

MainActivity.java
import …
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_add_product);

recyclerView = findViewById(R.id.recyclerView);
recyclerView.setLayoutManager(new LinearLayoutManager(getActivity()));
list = new ArrayList<>();
ad = new MyAdapter(getActivity(), list);
recyclerView.setAdapter(ad);

ref.addChildEventListener(new ChildEventListener() {

@Override
public void onChildAdded(@NonNull DataSnapshot snapshot, @Nullable String
previousChildName) {

for (DataSnapshot productsSnapshot : snapshot.getChildren()) {

list.add(productsSnapshot.getValue(MarksModel.class));
ad.notifyDataSetChanged();

}
}

@Override
public void onChildChanged(@NonNull DataSnapshot snapshot, @Nullable
String previousChildName) {
ad.notifyDataSetChanged();
}

@Override
public void onChildRemoved(@NonNull DataSnapshot snapshot) {
ad.notifyDataSetChanged();

@Override
public void onChildMoved(@NonNull DataSnapshot snapshot, @Nullable String
previousChildName) {
ad.notifyDataSetChanged();
}

@Override
public void onCancelled(@NonNull DatabaseError error) {

}
});
}
Enrollment Number:226240316184

MyAdapter.java
package com.example.firebasedbapp;

import …

public class MyAdapter extends RecyclerView.Adapter<MyAdapter.ViewHolder> {

private ArrayList<ProductsModel> mList;


private Context context;
private String key;

/**
* Provide a reference to the type of views that you are using
* (custom ViewHolder).
*/
public static class ViewHolder extends RecyclerView.ViewHolder {
private TextView textViewSubject;
private TextView textViewMarks;
public ViewHolder(View view) {
super(view);
// Define click listener for the ViewHolder's View

textViewSubject = (TextView) view.findViewById(R.id.


textViewSubject);
textViewMarks = (TextView) view.findViewById(R.id.textViewMarks);
}

public MyAdapter(Context context, ArrayList<ProductsModel> mList) {


this.context = context;
this.mList = mList;
//this.filteredList = mList;
}
// Create new views (invoked by the layout manager)
@Override
public ViewHolder onCreateViewHolder(ViewGroup viewGroup, int viewType) {
// Create a new view, which defines the UI of the list item
View view = LayoutInflater.from(viewGroup.getContext())
.inflate(R.layout.row_item, viewGroup, false);

return new ViewHolder(view);


}

// Replace the contents of a view (invoked by the layout manager)


@Override
public void onBindViewHolder(ViewHolder viewHolder, final int position) {

// Get element from your dataset at this position and replace the
// contents of the view with that element
viewHolder.textViewSubject.setText(mList.get(position).getSubject());
viewHolder.textViewMarks.setText("Rs.
"+mList.get(position).getMarks());
Enrollment Number:226240316184

// Return the size of your dataset (invoked by the layout manager)


@Override
public int getItemCount() {
return mList.size();
}
}

Output:
Enrollment Number:226240316184

Practical 19
Start Apache and MySQL servers.

Add.php
<?php

if(!empty($_POST['e_no'])){

$e_no = $_POST['e_no'];

$subject = $_POST['subject'];

$marks = $_POST['marks'];

$con = mysqli_connect('localhost', 'root', '', 'StudentDB');

if($con){

$query = "INSERT INTO Marks (e_no, subject, marks) values


($e_no,'$subject',$marks)";

if(mysqli_query($con,$query)){

echo "Success";

else

echo "Failed";

else

echo "can not connect to the database";

else

echo "Error"

?>

Output:
Enrollment Number:226240316184

Practical 20 & 21
Add.php

<?php

if(!empty($_POST['e_no'])){

$e_no = $_POST['e_no'];

$subject = $_POST['subject'];

$marks = $_POST['marks'];

$con = mysqli_connect('localhost', 'root', '', 'StudentDB');

if($con){

$query = "INSERT INTO Marks (e_no, subject, marks) values


($e_no,'$subject',$marks)";

if(mysqli_query($con,$query)){

echo "Success";

else

echo "Failed";

else

echo "can not connect to the database";

else

echo "Error"

?>

Fetch.php
<?php

header('Content-Type: application/json');

if(!empty($_POST['e_no'])){
Enrollment Number:226240316184

$e_no = $_POST['e_no'];

$con = mysqli_connect('localhost', 'root', '', 'studentDB');

$resultArray = array();

if($con){

$query = "SELECT * FROM Marks where e_no = ".$e_no;

$result = mysqli_query($con, $query);

if(mysqli_num_rows($result)>0){

$i = 0;

while($row = mysqli_fetch_assoc($result)){

$resultArray[$i] = $row;

$i++;

echo json_encode($resultArray);

?>

Android

MainActivity.java
package com.example.androidphpexample;

import …

public class MainActivity extends AppCompatActivity {

EditText etEnrollmentNo, etSubject, etMarks;


Button button, btnSearch;
TextView textView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Enrollment Number:226240316184

etEnrollmentNo = findViewById(R.id.etEnrollmentNo);
etSubject = findViewById(R.id.etSubject);
etMarks = findViewById(R.id.etMarks);
button = findViewById(R.id.button);
btnSearch = findViewById(R.id.btnSearch);
// textView = findViewById(R.id.textView);

//To insert the data in the database

button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String eno = etEnrollmentNo.getText().toString();
String subject = etSubject.getText().toString();
String marks = etMarks.getText().toString();

RequestQueue queue =
Volley.newRequestQueue(getApplicationContext());
String url = "http://192.168.1.2/AndroidPHPExample/add.php";

StringRequest stringRequest = new


StringRequest(Request.Method.POST, url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
if (response.equals("Success")) {
Toast.makeText(MainActivity.this, "Added
Successfully", Toast.LENGTH_SHORT).show();
} else
Toast.makeText(MainActivity.this,
response, Toast.LENGTH_SHORT).show();

}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(MainActivity.this,
error.getLocalizedMessage(), Toast.LENGTH_SHORT).show();

}
}) {
@Nullable
@Override
protected Map<String, String> getParams() throws
AuthFailureError {

Map<String, String> params = new HashMap<String,


String>();
params.put("e_no", eno);
params.put("subject", subject);
params.put("marks", marks);

return params;
}
};

queue.add(stringRequest);

}
});
Enrollment Number:226240316184

btnSearch.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String eno = etEnrollmentNo.getText().toString();
String subject = etSubject.getText().toString();
String marks = etMarks.getText().toString();

RequestQueue queue =
Volley.newRequestQueue(getApplicationContext());
String url = "http://192.168.1.2/AndroidPHPExample/fetch.php";

StringRequest stringRequest = new


StringRequest(Request.Method.POST, url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONArray resultArray = new
JSONArray(response);
textView.setText("");

for(int i = 0; i<resultArray.length();
i++){
JSONObject resultObject =
resultArray.getJSONObject(i);

textView.append(resultObject.getString("subject")+" ");

textView.append(resultObject.getInt("marks")+"\n");

} catch (JSONException e) {
Toast.makeText(MainActivity.this,
e.toString(), Toast.LENGTH_SHORT).show();
throw new RuntimeException(e);
}

}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(MainActivity.this,
error.getLocalizedMessage(), Toast.LENGTH_SHORT).show();

}
}) {
@Nullable
@Override
protected Map<String, String> getParams() throws
AuthFailureError {

Map<String, String> params = new HashMap<String,


String>();
params.put("e_no", eno);
return params;
}
Enrollment Number:226240316184

};

queue.add(stringRequest);

}
});

Output: Practical-20 Practical-20


Enrollment Number:226240316184

Practical 22
MapsActivity.java

package com.example.googlemapsdemo;

import …

public class MapsActivity extends AppCompatActivity implements


OnMapReadyCallback {

private GoogleMap mMap;


private ActivityMapsBinding binding;
TextView textView;

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

textView = findViewById(R.id.textView);

binding = ActivityMapsBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());

// Obtain the SupportMapFragment and get notified when the map is


ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment)
getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}

@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;

LatLng gphlatlong = new LatLng(23.57675443302106, 72.9657496708911);


mMap.addMarker(new
MarkerOptions().position(gphlatlong).title("GPH"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(gphlatlong));
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(gphlatlong,
17.0f));

}
}
Enrollment Number:226240316184

Output:
Enrollment Number:226240316184

Practical 23
MapsActivity.java

package com.example.googlemapsdemo;

import …

public class MapsActivity extends AppCompatActivity implements


OnMapReadyCallback {

private GoogleMap mMap;


private ActivityMapsBinding binding;
TextView textView;

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

textView = findViewById(R.id.textView);

binding = ActivityMapsBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());

// Obtain the SupportMapFragment and get notified when the map is


ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment)
getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}

@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;

LatLng gphlatlong = new LatLng(23.57675443302106, 72.9657496708911);


LatLng mcirclelatlong = new LatLng(23.582812626936697,
72.95837477393394);
mMap.addMarker(new MarkerOptions().position(gphlatlong).title("GPH"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(gphlatlong));
mMap.animateCamera(CameraUpdateFactory.newLatLngZoom(gphlatlong,
17.0f));
double distance = SphericalUtil.computeDistanceBetween(gphlatlong,
mcirclelatlong);
String distanceString = String.format("%.2f",distance/1000);

textView.setText(distanceString + " KM");

}
}
Enrollment Number:226240316184

Output:
Enrollment Number:226240316184

Practical 24

MainActivity.java
package com.example.googlesignin;

import …

public class MainActivity extends AppCompatActivity {

GoogleSignInClient mGoogleSignInClient;

SignInButton signInButton;
/* private SignInClient oneTapClient;
private BeginSignInRequest signInRequest;
private static final int REQ_ONE_TAP = 2; // Can be any integer unique to
the Activity.
private boolean showOneTapUI = true;*/

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);

GoogleSignInOptions gso = new


GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestEmail()
.build();

mGoogleSignInClient = GoogleSignIn.getClient(this, gso);


signInButton = findViewById(R.id.signInButton);

ActivityResultLauncher<Intent> launchSomeActivity
= registerForActivityResult(
new ActivityResultContracts
.StartActivityForResult(),
result -> {
if (result.getResultCode()
== Activity.RESULT_OK) {
Intent data = result.getData();

Task<GoogleSignInAccount> task =
GoogleSignIn.getSignedInAccountFromIntent(data);
handleSignInResult(task);

}
});

signInButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent signInIntent = mGoogleSignInClient.getSignInIntent();
launchSomeActivity.launch(signInIntent);
Enrollment Number:226240316184

}
});
}

private void handleSignInResult(Task<GoogleSignInAccount> completedTask) {


try {
GoogleSignInAccount account =
completedTask.getResult(ApiException.class);

// Signed in successfully, show authenticated UI.


if(account != null){
String personName = account.getDisplayName();
String personEmail = account.getEmail();
String userId = account.getId();
Uri personPhoto = account.getPhotoUrl();
Intent i = new Intent(MainActivity.this, HomeActivity.class);
i.putExtra("Name", personName);
i.putExtra("EmailID", personEmail);
i.putExtra("UserName", userId);
// i.putExtra("ImageURI", personPhoto.toString());
startActivity(i);

Toast.makeText(MainActivity.this, "Sign in successfully",


Toast.LENGTH_SHORT).show();
}

} catch (ApiException e) {
// The ApiException status code indicates the detailed failure
reason.
// Please refer to the GoogleSignInStatusCodes class reference for
more information.
Toast.makeText(MainActivity.this, e.getLocalizedMessage(),
Toast.LENGTH_SHORT).show();
}
}

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">

<com.google.android.gms.common.SignInButton
android:id="@+id/signInButton"
android:layout_width="152dp"
android:layout_height="66dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.5"
Enrollment Number:226240316184

app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.5" />

</androidx.constraintlayout.widget.ConstraintLayout>

HomeActivity.java
package com.example.googlesignin;

import …

public class HomeActivity extends AppCompatActivity {

TextView tvName, tvEmail, tvUserName;


ImageView imageView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);

tvName = findViewById(R.id.tvName);
tvEmail = findViewById(R.id.tvEmail);
tvUserName = findViewById(R.id.tvUserName);
String name = getIntent().getStringExtra("Name");
String familyName = getIntent().getStringExtra("FamilyName");
String emailID = getIntent().getStringExtra("EmailID");
String userName = getIntent().getStringExtra("USerName");

tvName.setText(name);
tvEmail.setText(emailID);
tvUserName.setText(userName);

}
}

activity_home.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".HomeActivity"
android:orientation="vertical">

<TextView
android:id="@+id/tvName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Person Name"
Enrollment Number:226240316184

android:layout_gravity="center_horizontal"
android:layout_marginTop="50dp"
tools:layout_editor_absoluteX="174dp"
tools:layout_editor_absoluteY="74dp" />
<TextView
android:id="@+id/tvFamilyName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Family Name"
android:layout_gravity="center_horizontal"
android:layout_marginTop="40dp"
tools:layout_editor_absoluteX="174dp"
tools:layout_editor_absoluteY="74dp" />
<TextView
android:id="@+id/tvEmail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Email ID"
android:layout_gravity="center_horizontal"
android:layout_marginTop="40dp"
tools:layout_editor_absoluteX="174dp"
tools:layout_editor_absoluteY="74dp" />
<TextView
android:id="@+id/tvUserName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="User Name"
android:layout_gravity="center_horizontal"
android:layout_marginTop="40dp"
tools:layout_editor_absoluteX="174dp"
tools:layout_editor_absoluteY="74dp" />

<ImageView
android:id="@+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="40dp"
android:layout_gravity="center_horizontal"
app:srcCompat="@drawable/ic_launcher_background" />

</LinearLayout>

Output:
Enrollment Number:226240316184

Practical:25

Main.dart
import 'package:flutter/material.dart';

void main() {
runApp(const MyApp());
}

class MyApp extends StatelessWidget {


const MyApp({super.key});

// This widget is the root of your application.


@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'First App',
debugShowCheckedModeBanner: false,
theme: ThemeData(

colorScheme: ColorScheme.fromSeed(seedColor: Colors.orange),


useMaterial3: true,
),
home: const MyHomePage(title: 'Flutter First App'),
);
}
}

class MyHomePage extends StatefulWidget {


const MyHomePage({super.key, required this.title});

final String title;


@override
State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text(widget.title),
),
body:
Center(
child: Text("Hello World",style: TextStyle(fontSize: 30, color:
Colors.red),),
),
// This trailing comma makes auto-formatting nicer for build methods.
); }
}
Enrollment Number:226240316184

Output:
Enrollment Number:226240316184

Practical:26

Main.dart

import 'package:flutter/material.dart';

void main() {
runApp(const MyApp());
}

class MyApp extends StatelessWidget {


const MyApp({super.key});

// This widget is the root of your application.


@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Add Number',
debugShowCheckedModeBanner: false,
theme: ThemeData(

colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),


useMaterial3: true,
),
home: const MyHomePage(title: 'Add Number'),
);
}
}

class MyHomePage extends StatefulWidget {


const MyHomePage({super.key, required this.title});

final String title;

@override
State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {

TextEditingController num1Controller = TextEditingController();


TextEditingController num2Controller = TextEditingController();
String result = "";

void addNumbers() {
int num1 = int.tryParse(num1Controller.text) ?? 0;
int num2 = int.tryParse(num2Controller.text) ?? 0;

setState(() {
result = (num1 + num2).toString();
});
}

@override
Widget build(BuildContext context) {
Enrollment Number:226240316184

return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text(widget.title),
),
body: Center(
child: Container(
width: 300,
height: 500,
child: Column(
children: [
TextField(
controller: num1Controller,
decoration: InputDecoration(
hintText: "First Number",
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: BorderSide(
color: Colors.lightBlue,
width: 5

)
)
),

),
Container(height: 20,),
TextField(
controller: num2Controller,
decoration: InputDecoration(
hintText: "Second Number",
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: BorderSide(
color: Colors.lightBlue,
width: 5

)
)
),

),
ElevatedButton(
onPressed:addNumbers,
child: Text('Add'),
),
Text(
'$result',
style:TextStyle(fontSize: 24),
),
],
),
),
)
);
}
}
Enrollment Number:226240316184

Output:
Enrollment Number:226240316184

Practical 27

Main.dart
import 'package:flutter/material.dart';
import 'package:login_flutter/home_screen.dart';

void main() {
runApp(const MyApp());
}

class MyApp extends StatelessWidget {


const MyApp({super.key});

@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Login',
debugShowCheckedModeBanner: false,
theme: ThemeData(

colorScheme: ColorScheme.fromSeed(seedColor: Color(0xFF03DAC5)),


useMaterial3: true,
),
home: const MyHomePage(title: 'Login App'),
);
}
}

class MyHomePage extends StatefulWidget {


const MyHomePage({super.key, required this.title});

final String title;

@override
State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {

String userID="gphmt";
String password="gp123";
TextEditingController userIDController = TextEditingController();
TextEditingController passwordController = TextEditingController();

@override
Widget build(BuildContext context) {

return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text(widget.title),
),
body: Center(
child: Container(
Enrollment Number:226240316184

width: 300,
height: 500,
child: Column(
children: [
Container(height: 30,),
Text("Login", style: TextStyle(fontSize: 40, color:
Color(0xFF03DAC5)),),
Container(height: 40,),
TextField(
controller: userIDController,
decoration: InputDecoration(
hintText: "User ID",
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: BorderSide(
color: Colors.lightBlue,
width: 5

)
)
),

),
Container(height: 20,),
TextField(
controller: passwordController,
decoration: InputDecoration(
hintText: "Password",
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10),
borderSide: BorderSide(
color: Colors.lightBlue,
width: 5

)
)
),

),
Container(height:80,),
ElevatedButton(
onPressed: (){
if (userIDController.text == userID &&
passwordController.text == password) {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => HomeScreen(username:
userID),
),
);
} else {
ScaffoldMessenger.of(context).showSnackBar(const
SnackBar(
content: Text("Incorrect User ID or Password"),
));
}
},
child: Text('Login'),

),
Enrollment Number:226240316184

],
),
),
)
);
}
}

home_screen.dart
import 'package:flutter/material.dart';

class HomeScreen extends StatelessWidget {


final String username;

HomeScreen({required this.username});

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.inversePrimary,
title: Text("Login App"),
),
body: Center(
child: Column(

children: [
Container(height: 200,),
Text("Welcome",style: TextStyle(fontSize: 20, color:
Color(0xFF03DAC5))),

Text('$username',style: TextStyle(fontSize: 40, color:


Color(0xFF03DAC5))),]

),
);

}
}

Output:
Enrollment Number:226240316184

Practical: 28

Aim: Write the steps/report to publish an app on the google play store.

Steps to Publish an App on the Google Play Store


1. Prepare Your App
• Test the app on various devices to ensure it functions smoothly.
• Generate a release APK or Android App Bundle (AAB).
• Sign your APK/AAB with a private key for security and authenticity.
2. Create a Google Play Developer Account
• Go to the Google Play Console.
• Register for a developer account and pay the one-time fee of $25.
3. Create a New App in Google Play Console
• In the Google Play Console, click "Create App".
• Provide details such as the app name, default language, etc.
4. Upload Your APK/AAB
• Navigate to the App Releases section.
• Upload the signed APK or AAB file of your app.
5. Provide App Information
• Fill in the Store Listing details like description, screenshots, and icons.
• Select the app's category and complete the content rating questionnaire.
6. Set Pricing and Distribution
• Choose whether the app is Free or Paid.
• Specify the countries/regions where your app will be available.
7. Submit the App for Review
• Complete any additional details in the App Content section (such as privacy policy,
ads, etc.).
• Once everything is filled out, click Submit for Review.

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