MAD Practical ?vraj
MAD Practical ?vraj
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
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
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
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
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" />
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);
}
}
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;
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" />
</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 {
}
@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
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 …
@Override
public void onCreate(SQLiteDatabase db) {
@Override
public void onUpgrade(SQLiteDatabase sqLiteDatabase, int i, int i1)
{
SQLiteDatabase db = this.getWritableDatabase();
}
Enrollment Number:226240316184
SQLiteDatabase db = this.getReadableDatabase();
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;
SQLiteDatabase db = this.getWritableDatabase();
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;
TextView textView;
@Override
protected void onCreate(Bundle savedInstanceState) {
Enrollment Number:226240316184
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textView = findViewById(R.id.textView);
//To update
dbHandler.updateUser(model);
//To delete
dbHandler.delete(model);
}
}
Output:
Enrollment Number:226240316184
Practical 17
Inserting data into Firebase
AddMarksActivity.java
package com.example.firebasedbapp;
import …
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) {
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) {
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 …
/**
* 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
// 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
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'];
if($con){
if(mysqli_query($con,$query)){
echo "Success";
else
echo "Failed";
else
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'];
if($con){
if(mysqli_query($con,$query)){
echo "Success";
else
echo "Failed";
else
else
echo "Error"
?>
Fetch.php
<?php
header('Content-Type: application/json');
if(!empty($_POST['e_no'])){
Enrollment Number:226240316184
$e_no = $_POST['e_no'];
$resultArray = array();
if($con){
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 …
@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);
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";
}
}, 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 {
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";
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 {
};
queue.add(stringRequest);
}
});
Practical 22
MapsActivity.java
package com.example.googlemapsdemo;
import …
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
textView = findViewById(R.id.textView);
binding = ActivityMapsBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
}
}
Enrollment Number:226240316184
Output:
Enrollment Number:226240316184
Practical 23
MapsActivity.java
package com.example.googlemapsdemo;
import …
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
textView = findViewById(R.id.textView);
binding = ActivityMapsBinding.inflate(getLayoutInflater());
setContentView(binding.getRoot());
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
}
}
Enrollment Number:226240316184
Output:
Enrollment Number:226240316184
Practical 24
MainActivity.java
package com.example.googlesignin;
import …
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);
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
}
});
}
} 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
<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 …
@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());
}
@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());
}
@override
State<MyHomePage> createState() => _MyHomePageState();
}
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());
}
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Login',
debugShowCheckedModeBanner: false,
theme: ThemeData(
@override
State<MyHomePage> createState() => _MyHomePageState();
}
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';
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))),
),
);
}
}
Output:
Enrollment Number:226240316184
Practical: 28
Aim: Write the steps/report to publish an app on the google play store.