0% found this document useful (0 votes)
31 views55 pages

Mad pt2

The document contains sample code for implementing a date and time picker in an Android application. It includes XML layout files and Java code to display the date and time pickers and update text views with the selected values. The date and time pickers allow the user to select a date and time which is then displayed on the screen.

Uploaded by

Vishesh Tiwari
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)
31 views55 pages

Mad pt2

The document contains sample code for implementing a date and time picker in an Android application. It includes XML layout files and Java code to display the date and time pickers and update text views with the selected values. The date and time pickers allow the user to select a date and time which is then displayed on the screen.

Uploaded by

Vishesh Tiwari
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/ 55

Question Bank (I scheme)

Class Test II
Course: Mobile Application Development (MAD) Course Code: 22617 Program:
CO6I A-B Semester: VI
-----------------------------------------------------------------------------------------------
- Unit 4: Design User Interface with View (12 Marks)
4 Marks
1. Develop a program to implement Date and Time Picker.
Ans:

Input Code:

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">
android:layout_height="match_parent"
tools:context=".MainActivity">

<TextView
android:id="@+id/tvDate"
android:layout_width="149dp"
android:layout_height="46dp"
android:layout_marginEnd="224dp"
android:layout_marginBottom="312dp"
android:textSize="20dp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />

<Button
android:id="@+id/btnDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="96dp"
android:layout_marginBottom="312dp"
android:text="Set Date"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
tools:ignore="DuplicateClickableBoundsCheck" />

<DatePicker
android:id="@+id/dtpcker"
android:layout_width="314dp"
android:layout_height="293dp"
android:layout_marginBottom="368dp"
android:datePickerMode="spinner"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.36"
app:layout_constraintStart_toStartOf="parent" />

<TimePicker
android:id="@+id/timepcker"
android:layout_width="184dp"
android:layout_height="195dp"
android:layout_marginEnd="132dp"
android:layout_marginBottom="108dp"
android:timePickerMode="spinner"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />

<TextView
android:id="@+id/tvTime"
android:layout_width="130dp" android:layout_height="56dp"
android:layout_marginEnd="232dp"
android:layout_marginBottom="40dp"
android:textSize="20dp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />

<Button
android:id="@+id/btnTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="104dp"
android:layout_marginBottom="48dp"
android:text="Set Time"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

MainActivity.java:

package com.example.datepickereg;
import androidx.appcompat.app.AppCompatActivity;
import android.app.DatePickerDialog;
import android.app.TimePickerDialog;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.DatePicker;
import android.widget.TextView;
import android.widget.TimePicker;
import java.util.Calendar;

public class MainActivity extends AppCompatActivity {


TextView tvDate,tvTime;
DatePicker dtpcker;
TimePicker timepcker;
Button b1,b2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tvDate=findViewById(R.id.tvDate);
tvTime=findViewById(R.id.tvTime);
b1=findViewById(R.id.btnDate);
b2=findViewById(R.id.btnTime);
dtpcker=findViewById(R.id.dtpcker);
timepcker=findViewById(R.id.timepcker);
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
tvDate.setText("Date : "+dtpcker.getDayOfMonth()+"
"+dtpcker.getMonth()+"-"+dtpcker.getYear());
}
});
b2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {

tvTime.setText(timepcker.getCurrentHour()+":"+timepcker.getCurrentMinute());
}
});
}
}

OR

AndroidManifest.xml:

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


<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.exp_16_x_1">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Exp16x1">
<activity
android:name=".MainActivity2"
android:exported="false">
<meta-data
android:name="android.app.lib_name"
android:value="" />
</activity>
<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>

Activity_main.xml:

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


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

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="600dp">

<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="146dp"
android:layout_marginBottom="546dp"
android:text="@string/am_pm"
android:textColor="@color/black"
android:textSize="36sp" />

<TimePicker
android:id="@+id/timePicker"
android:layout_width="241dp"
android:layout_height="167dp"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="83dp"
android:layout_marginBottom="358dp"
android:timePickerMode="spinner" />

<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="133dp"
android:layout_marginBottom="263dp"
android:text="@string/_24_hours"
android:textColor="@color/black"
android:textSize="36sp" />
<TimePicker
android:id="@+id/timePicker1"
android:layout_width="241dp"
android:layout_height="167dp"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="89dp"
android:layout_marginBottom="83dp"
android:timePickerMode="spinner" />
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="140dp"
android:layout_marginBottom="18dp"
android:text="TimePicker" />

</RelativeLayout>

</LinearLayout>
MainActivity.java:

package com.example.exp_16_x_1;

import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TimePicker;
public class MainActivity extends AppCompatActivity {
private Button button;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TimePicker picker = (TimePicker) findViewById(R.id.timePicker1);
picker.setIs24HourView(true);
button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
openActivity2();
}
});
}
private void openActivity2() {
Intent intent = new Intent(this, MainActivity2.class);
startActivity(intent);
}
}

Activity_main2.xml:

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


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

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="675dp">

<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/button1"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_marginStart="36dp"
android:layout_marginLeft="36dp"
android:layout_marginBottom="34dp"/>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="20dp"
android:text="Change Time" />
<TimePicker
android:id="@+id/timePicker"
android:layout_width="390dp"
android:layout_height="446dp"
android:layout_above="@+id/textView1"
android:layout_centerHorizontal="true"
android:layout_marginBottom="35dp" />

</RelativeLayout>

</LinearLayout>

MainActivity2.java:

package com.example.exp_16_x_1;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.TimePicker;

public class MainActivity2 extends AppCompatActivity {

TextView textview1;
TimePicker timepicker;
Button changetime;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
textview1=(TextView)findViewById(R.id.textView1);
timepicker=(TimePicker)findViewById(R.id.timePicker);
timepicker.setIs24HourView(true);
changetime=(Button)findViewById(R.id.button1);
textview1.setText(getCurrentTime());
changetime.setOnClickListener(new View.OnClickListener()
{
@Override
public void onClick(View view) {
textview1.setText(getCurrentTime());
}
});
}
public String getCurrentTime(){
String currentTime="Current Time:
"+timepicker.getCurrentHour()+":"+timepicker.getCurrentMinute();
return currentTime;
}
}

Output-1:
Output-2:
Output-3:
2. Develop a program to implement Progress Bar.
Ans:

Input Code:

Xml File:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"> <ProgressBar
android:id="@+id/progressBar"
style="@android:style/Widget.ProgressBar.Horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="20dp"
android:indeterminate="false"
android:max="100"
android:minHeight="50dp"
android:minWidth="200dp"
android:progress="1" />
<TextView
android:id="@+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/progressBar"
android:layout_below="@+id/progressBar"/>
</RelativeLayout>

Java file:

package in.edu.vpt.progressbar;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.widget.ProgressBar;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
private ProgressBar progressBar;
private int progressStatus = 0;
private TextView textView;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
progressBar = (ProgressBar) findViewById(R.id.progressBar);
textView = (TextView) findViewById(R.id.textView);
// Start long running operation in a background thread
new Thread(new Runnable() {
public void run() {while (progressStatus < 100) {
progressStatus += 1;
new Handler(Looper.getMainLooper()).post(new Runnable() {
public void run() {
progressBar.setProgress(progressStatus);
textView.setText(progressStatus+"/"+progressBar.getMax());
}
});
try {
// Sleep for 200 milliseconds.
Thread.sleep(200);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}).start();
}
}

OR
AndroidManifest.xml:

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


<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.exp_13_x_1">

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Exp13x1">
<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>

Activity_main.xml:

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


<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<ProgressBar
android:id="@+id/circularProgressbar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="300dp"
android:layout_height="300dp"
android:indeterminate="false"
android:max="100"
android:progress="50"
android:layout_centerInParent="true"
android:progressDrawable="@drawable/circular"
android:secondaryProgress="100" />

<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_centerInParent="true"
android:background="@drawable/whitecircle" />
<TextView
android:id="@+id/t1"
android:layout_width="250dp"
android:layout_height="250dp"
android:gravity="center"
android:text="25%"
android:layout_centerInParent="true"
android:textColor="@color/purple_700"
android:textSize="20sp" />

</RelativeLayout>

Circular.xml:

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


<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/secondaryProgress">
<shape
android:innerRadiusRatio="6"
android:shape="ring"
android:thicknessRatio="20.0"
android:useLevel="true">

<gradient
android:centerColor="#999999"
android:endColor="#999999"
android:startColor="#999999"
android:type="sweep" />
</shape>
</item>

<item android:id="@android:id/progress">
<rotate
android:fromDegrees="270"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="270">

<shape
android:innerRadiusRatio="6"
android:shape="ring"
android:thicknessRatio="20.0"
android:useLevel="true">
<rotate
android:fromDegrees="0"
android:pivotX="50%"
android:pivotY="50%"
android:toDegrees="360" />
<gradient
android:centerColor="#00FF00"
android:endColor="#00FF00"
android:startColor="#00FF00"
android:type="sweep" />
</shape>
</rotate>
</item>
</layer-list>

MainActivity.java:

package com.example.exp_13_x_1;

import androidx.appcompat.app.AppCompatActivity;

import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Handler;
import android.widget.ProgressBar;
import android.widget.TextView;

public class MainActivity extends AppCompatActivity {


private ProgressBar progressBar;
private TextView progressText;
int i = 0;

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

progressBar = findViewById(R.id.circularProgressbar);
progressText = findViewById(R.id.t1);

final Handler handler = new Handler();


handler.postDelayed(new Runnable() {
@Override
public void run() {
if (i <= 100) {
progressText.setText("" + i);
progressBar.setProgress(i);
i++;
handler.postDelayed(this, 200);
} else {
handler.removeCallbacks(this);
}
}
}, 200);
}
}

Output:
Unit 5: Activity & Multimedia with Database (20 Marks)
2 Marks

1. Write the syntax for Intent-Filter tag.


Ans:

Syntax:

<intent-filter
android:icon="drawable resource"
android:label="string resource"
android:priority ="integer"
</intent-filter>

must contain:

<action>

can contain:

<category>
<data>

2. What is Service in android? Enlist its Types.


Ans:

A service is an application component which runs without direct interaction with the
user in the background.
• Services are used for repetitive and potentially long running operations, i.e.,
Internet downloads, checking for new data, data processing, updating content
providers and the like.
• Service can either be started or bound we just need to call either startService() or
bindService() from any of our android components. Based on how our service was
started it will either be "started" or "bound".

Types of services are:

1. Foreground Services
2. Background Services
3. Bound Services
3. Enlist different ways to handle databases in android? Elaborate any one.
Ans:

Types to handle databases in android are:

1. SQLite Database
2. Shared Preferences
3. File Storage

Elaboration:

1. SQLite is an open-source SQL database that stores data in a text file on the device.
Android comes with built-in SQLite database support.
2. Supports all relational database features.
3. No need to establish external connections (like JDBC or ODBC) to access the
database.
4. To create a database, use the openOrCreateDatabase method with your desired
database name and mode.
5. Example:

SQLiteDatabase mydatabase = openOrCreateDatabase("mydb", MODE_PRIVATE,


null);

4. What is Intent? Enlist its Types.


Ans:
Intent is the message that is passed between components such as activities. Android
uses Intent for communicating between the components of an Application and also
from one application to another application.
Types:
• Explicit Intent
• Implicit Intent

5. What Is Sensor in android? Enlist its Types.


Ans:
The android platform supports three broad categories of sensors.
• Motion Sensors
These are used to measure acceleration forces and rotational forces along with three
axes.
• Environmental sensors
These are used to measure the environmental changes such as temperature,
humidity etc.
• Position sensors
These are used to measure the physical position of device.

6. What is Animation? Enlist its Types.


Ans:

Animation:

A property animation changes a property's (a field in an object) value over a


specified length of time. To animate something, you specify the object property that
you want to animate, such as an object's position on the screen, how long you want
to animate it for, and what values you want to animate between.

Types of Animation:

1. Blink Animation
2. Fade Animation
3. Move Animation

7. What is TTS feature of Android?


Ans:

1. Text to Speech converts the text written on the screen to speech like you have
written “Hello World” on the screen and when you press the button it will
speak “Hello World”. Text-to speech is commonly used as an accessibility
feature to help people who have trouble reading on-screen text, but it’s also
convenient for those who want to be read too. This feature has come out to be
a very common and useful feature for the users.

2. In android, by using TextToSpeech class we can easily convert our text into
voice and it supports different types of speaking languages. We can choose
the speaking language based on our requirements in the android application.

3. The android TextToSpeech instance can only be used to synthesize text once
it has completed its initialization so implement TextToSpeech.

4. OnInitListener to notify the completion of initialization. During the


initialization, we can set the audio pitch rate, audio speed, type of language to
speak, etc. based on our requirements.
4 Marks

1. Define content provider and explain fragments. (CO5)


Ans:

Content Providers are used to share data between two


applications. This can be implemented
in two ways:
1. When you want to implement the existing content provider in
another application.
2. When you want to create a new content provider that can
share its data with other
Applications

Fragment:
Fragment is the part of activity, it is also known as sub-activity.

2. Explain the activity life cycle. (CO5)


Ans:
Diagram:

Fig: Activity Life Cycle

Explanation:

onCreate (): Called then the activity is created. Used to initialize


the activity, for example create the user interface.

onStart (): called when activity is becoming visible to the user.


onResume (): Called if the activity get visible again and the user
starts interacting with the activity again. Used to initialize fields,
register listeners, bind to services, etc.

onPause (): Called once another activity gets into the


foreground. Always called before the activity is not visible
anymore. Used to release resources or save application data. For
example you unregister listeners, intent receivers, unbind from
services or remove system service listeners.

onStop (): Called once the activity is no longer visible. Time or


CPU intensive shutdown operations, such as writing information
to a database should be down in the onStop() method. This
method is guaranteed to be called as of API 11.

onDestroy (): called before the activity is destroyed.

3. Explain with Diagram Service Life Cycle?


Ans:

Diagram:
Fig: Service Life Cycle
Explanation:

1. onCreate():

This is the first callback which will be invoked when any


component starts the service. If the same service is called again
while it is still running this method Won’t be invoked. Ideally
one time setup and intializing should be done in this callback.
2. onStartCommand() /startSetvice()

This callback is invoked when service is started by any


component by calling startService(). It basically indicates that
the service has started and can now run indefinetly.

3. onBind()

To provide binding for a service, you must implement the


onBind() callback method. This method returns an IBinder
object that defines the programming interface that clients can
use to interact with the service.

4. onUnbind()

This is invoked when all the clients are disconnected from the
service.

5. onRebind()

This is invoked when new clients are connected to the service. It


is called after onRebind

6. onDestroy()

This is a final clean up call from the system. This is invoked just
before the service is being destroyed.

4. How to play Audio & Video in Android?


Ans:

Audio:

1. To play audio files, you can use the MediaPlayer class.

2. Can control audio playback using methods like start(), pause(), stop(),
and seekTo().

3. For more advanced features (looping, handling errors, etc.), explore the
official Android documentation
Video:

1. To play video files, you can use the VideoView widget or a


custom SurfaceView with MediaPlayer.

2. Remember to handle lifecycle events (pause, resume, stop) appropriately

5. Explain how to Create & Connect SQLite?


Ans:

6. What is Transaction? Explain with example.


Ans:

7. Develop a program to build Camera.


Ans:

Input Code:

AndroidManifest.xml:

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


<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.exp_23_x_1">
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature android:name="android.hardware.camera2"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Exp23X1">
<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>

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"
android:gravity="center"
tools:context=".MainActivity">
<Button
android:id="@+id/camera_button"
android:layout_width="100dp"
android:layout_height="50dp"
android:layout_marginLeft="125dp"
android:text="Camera" />
<ImageView
android:layout_marginTop="70dp"
android:layout_width="350dp"
android:layout_height="450dp"
android:id="@+id/click_image"
android:layout_marginBottom="10dp"/>
</RelativeLayout>

MainActivity.java:

package com.example.exp_23_x_1;

import android.content.Intent;
import android.graphics.Bitmap;
import android.provider.MediaStore;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
private static final int pic_id = 123;
Button camera_open_id;
ImageView click_image_id;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
camera_open_id = (Button)findViewById(R.id.camera_button);
click_image_id = (ImageView)findViewById(R.id.click_image);
camera_open_id.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v)
{
Intent camera_intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(camera_intent, pic_id);
}
});
}
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == pic_id) {
Bitmap photo = (Bitmap) data.getExtras().get("data");
click_image_id.setImageBitmap(photo);
}
}
}

Output:
8. Develop a program to list all sensors.
Ans:
Input Code:

AndroidManifest.xml:

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


<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.exp_22_x_2">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Exp22X2">
<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>

Activity_main.xml:

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


<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity"
android:transitionGroup="true">
<TextView
android:text="Sensor "
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/textview"
android:textSize="30dp"
android:textColor="#FF0000"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="All Sensors Supported by the Mobile Device"
android:layout_marginTop="10dp"
android:id="@+id/textView1"
android:layout_below="@+id/textview"
android:layout_centerHorizontal="true"
android:textColor="#ff7aff24"
android:textSize="20sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:id="@+id/textView2"
android:layout_below="@+id/textView1"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentStart="true" />
</RelativeLayout>

MainActivity.java:

package com.example.exp_22_x_2;

import android.app.Activity;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import java.util.List;
import android.hardware.Sensor;
public class MainActivity extends Activity {
TextView tv1=null; private SensorManager mSensorManager;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv1 = (TextView) findViewById(R.id.textView2);
tv1.setVisibility(View.GONE);
mSensorManager = (SensorManager) getSystemService(SENSOR_SERVICE);
List<Sensor> mList= mSensorManager.getSensorList(Sensor.TYPE_ALL);
for (int i = 1; i < mList.size(); i++) {
tv1.setVisibility(View.VISIBLE);
tv1.append("\n" + mList.get(i).getName() + "\n" +
mList.get(i).getVendor() + "\n" + mList.get(i).getVersion());
}
}
}

Output:
9. Develop a program for animation to zoom in only.
10. Develop a program to implement broadcast receiver.
Ans:

Input Code:

AndroidManifest.xml:

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

<manifest xmlns:android="http://schemas.android.com/apk/res/android"

package="com.example.exp_21_x_1">

<application

android:allowBackup="true"

android:icon="@mipmap/ic_launcher"

android:label="@string/app_name"

android:roundIcon="@mipmap/ic_launcher_round"

android:supportsRtl="true"

android:theme="@style/Theme.Exp21X1">

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

<receiver android:name="MyReceiver"

android:exported="true">

<intent-filter>

<action android:name="MyAction" />

</intent-filter>
</receiver>

</application>

</manifest>

Activity_main.xml:

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

<LinearLayout

xmlns:android="http://schemas.android.com/apk/res/android"

xmlns:app="http://schemas.android.com/apk/res-auto"

xmlns:tools="http://schemas.android.com/tools"

android:layout_width="match_parent"

android:layout_height="match_parent"

android:orientation="vertical"

android:gravity="center"

tools:context=".MainActivity">

<TextView

android:id="@+id/t1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:text="Example of Brodcast"

android:textStyle="bold"

android:textColor="#FF0000"

android:textAppearance="?android:textAppearanceLarge"/>

<Button
android:id="@+id/b1"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:onClick="broadcastIntent"

android:layout_marginTop="10dp"

android:text="Brodcast Intent"/>

</LinearLayout>

MainActivity.java:

package com.example.exp_21_x_1;

import androidx.appcompat.app.AppCompatActivity;

import android.content.Intent;

import android.os.Bundle;

import android.view.View;

public class MainActivity extends AppCompatActivity {

@Override

protected void onCreate(Bundle savedInstanceState) {


super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

public void broadcastIntent(View view) {


Intent i=new Intent(this,MyReceiver.class);

i.setAction("MyAction");

sendBroadcast(i);

MyReceiver.java:

package com.example.exp_21_x_1;

import android.content.BroadcastReceiver;

import android.content.Context;

import android.content.Intent;

import android.widget.Toast;

public class MyReceiver extends BroadcastReceiver {

@Override

public void onReceive(Context context, Intent intent) {

Toast.makeText(context,"Intent Detected",Toast.LENGTH_LONG).show();

Output:
Unit 6: Security & Application Deployment (20 Marks)
2 Marks

1. Name any 4 methods to get location data in android. (CO6)


Ans:

•double getAltitude()
•double getLatitude()
•float getSpeed()
•boolean hasAccuracy()
•boolean hasAltitude()
•boolean hasBearing()
•boolean hasBearing()
•boolean hasSpeed()
•void reset()
•void setAccuracy(float accuracy)
•void setAltitude(double altitude)

2. Explain Geocoding & Reverse Geocoding. (CO6)


Ans:

Geocoding:

Geocoding is the process of transforming a street address or other description of a


location into a (latitude, longitude) coordinate.

Reverse Geocoding:

Reverse geocoding is the process of transforming a (latitude, longitude) coordinate


into a (partial) address.

3. Enlist the steps to publish the Android application. (CO6)


Ans:

Application deployment steps:

Publishing is the general process that makes your Android app available to users.
When you publish an Android app on google play store, you do the following:

• Prepare the app for release.


During the preparation step, you build a release version of your app.
Release the app to users.
During the release step, you publicize, sell, and distribute the release version
of your app, which users can download and install on their Android-powered
devices.
Prepare your app for release
1)Preparing your app for release is a multistep process involving the following tasks:
Configure your app for release.
At a minimum, you need to make sure that logging is disabled and removed
and that your release variant has debuggable false for Groovy
or isDebuggable = false for Kotlin script set. You should also set your app's
version information.
Build and sign a release version of your app.
You can use the Gradle build files with the release build type to build and
sign a release version of your app. For more information, see Build and run
your app.
Test the release version of your app.
Before you distribute your app, you should thoroughly test the release version
on at least one target handset device and one target tablet device. Firebase
Test Lab is useful for testing across a variety of devices and configurations.
Update app resources for release.
Make sure that all app resources, such as multimedia files and graphics, are
updated and included with your app or staged on the proper production
servers.
Prepare remote servers and services that your app depends on.
If your app depends on external servers or services, make sure they are secure
and production ready.

2) Signing of Application
Application signing allows developers to identify the author of the
application and to update their application without creating complicated
interfaces and permissions.
Every application that is run on the Android platform must be signed by the
developer.
Applications that attempt to install without being signed will be rejected by
either Google Play or the package installer on the Android device.

APK Signing Schemes


v1 Scheme: based on JAR signing.
v2 Scheme: APK Signature Scheme v2, which was introduced in Android
7.0.
v3 Scheme: APK Signature Scheme v3, which was introduced in Android 9.

4. Write steps to deploy an android application.


Ans:

Application deployment steps:

Publishing is the general process that makes your Android app available to users.
When you publish an Android app on google play store, you do the following:

• Prepare the app for release.


During the preparation step, you build a release version of your app.
Release the app to users.
During the release step, you publicize, sell, and distribute the release version
of your app, which users can download and install on their Android-powered
devices.
Prepare your app for release
1)Preparing your app for release is a multistep process involving the following tasks:
Configure your app for release.
At a minimum, you need to make sure that logging is disabled and removed
and that your release variant has debuggable false for Groovy
or isDebuggable = false for Kotlin script set. You should also set your app's
version information.
Build and sign a release version of your app.
You can use the Gradle build files with the release build type to build and
sign a release version of your app. For more information, see Build and run
your app.
Test the release version of your app.
Before you distribute your app, you should thoroughly test the release version
on at least one target handset device and one target tablet device. Firebase
Test Lab is useful for testing across a variety of devices and configurations.
Update app resources for release.
Make sure that all app resources, such as multimedia files and graphics, are
updated and included with your app or staged on the proper production
servers.
Prepare remote servers and services that your app depends on.
If your app depends on external servers or services, make sure they are secure
and production ready.

2) Signing of Application
Application signing allows developers to identify the author of the
application and to update their application without creating complicated
interfaces and permissions.
Every application that is run on the Android platform must be signed by the
developer.
Applications that attempt to install without being signed will be rejected by
either Google Play or the package installer on the Android device.

APK Signing Schemes


v1 Scheme: based on JAR signing.
v2 Scheme: APK Signature Scheme v2, which was introduced in Android
7.0.
v3 Scheme: APK Signature Scheme v3, which was introduced in Android 9.

5. Explain Google Map with types.


6. Explain Geocoding & Reverse Geocoding.
Ans:

Geocoding:

Geocoding is the process of transforming a street address or other description of a


location into a (latitude, longitude) coordinate.

Reverse Geocoding:

Reverse geocoding is the process of transforming a (latitude, longitude) coordinate


into a (partial) address.

7. List various classes of SMS Telephony.


Ans:

Types of classes of SMS Telephony are:

1. Telephony.Sms.Conversations
2. Telephony.Sms.Draft
3. Telephony.Sms.Inbox
4. Telephony.Sms.Intents
5. Telephony.Sms.Outbox
6. Telephony.Sms.Sent

4 Marks

1. Describe types of permissions used while developing android applications. (CO6)


2. Develop an application to send and receive SMS. (Write ONLY .java and
permission tag in manifest file). (CO6)
Ans:

Input Code:

AndroidManifest.xml:

<uses-permission android:name="android.permission.RECEIVE_SMS" />


<uses-permission android:name="android.permission.SEND_SMS"/>
<uses-permission android:name="android.permission.READ_SMS"/>
<uses-permission android:name="android.permission.WRITE_SMS"/>

<receiver
android:name=".SmsReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="android.provider.Telephony.SMS_RECEIVED" />
</intent-filter>
</receiver>

MainActivity.java:

package com.example.testreceivesms;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import android.Manifest;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {


SmsReceiver sms= new SmsReceiver();
EditText et1,et2;
Button b1;
@Override
protected void onCreate (Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
et1=findViewById(R.id.etPhno);
et2=findViewById(R.id.etmsg);
b1=findViewById(R.id.btnSms);
if(ContextCompat.checkSelfPermission(MainActivity.this,Manifest.permission.SEND_
S
MS)!=
PackageManager.PERMISSION_GRANTED)
{
ActivityCompat.requestPermissions(MainActivity.this,new
String[]{Manifest.permission.SEND_SMS},100);
}
b1.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try {
String phno= et1.getText().toString();
String msg=et2.getText().toString();
SmsManager smsManager= SmsManager.getDefault();
smsManager.sendTextMessage(phno,null,msg,null,null);
Toast.makeText(MainActivity.this,"Sms sent successfully",
Toast.LENGTH_LONG).show();
}
catch(Exception e)
{
Toast.makeText(MainActivity.this,"Sms failed to send... try again",
Toast.LENGTH_LONG).show();
}
}
});
}
@Override
protected void onStart() {
super.onStart();
IntentFilter filter=new IntentFilter("android.provider.Telephony.SMS_RECEIVED");
registerReceiver(sms,filter);
}

@Override
protected void onStop() {
super.onStop();
unregisterReceiver(sms);
}
}

SmsReceiver.java:

package com.example.testreceivesms;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SmsMessage;
import android.widget.Toast;

public class SmsReceiver extends BroadcastReceiver {


SmsReceiver(){}
@Override
public void onReceive(Context context, Intent intent) {
Bundle bundle = intent.getExtras();

if (bundle != null) {
// Retrieve the SMS Messages received
Object[] sms = (Object[]) bundle.get("pdus");

// For every SMS message received


for (int i=0; i < sms.length; i++) {
// Convert Object array
SmsMessage smsMessage = SmsMessage.createFromPdu((byte[]) sms[i]);

String phone = smsMessage.getOriginatingAddress();


String message = smsMessage.getMessageBody().toString();

Toast.makeText(context, “Received from “+ phone + ": " + message,


Toast.LENGTH_SHORT).show();
}
}
}
}

3. Discuss Developer console with its purpose.


4. Develop a program to send and receive e-mail.
Ans:

Input Code for send Email:


Activity_main.xml:

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


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

<EditText
android:id="@+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_marginTop="18dp"
android:layout_marginRight="22dp" />

<EditText
android:id="@+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/editText1"
android:layout_alignLeft="@+id/editText1"
android:layout_marginTop="20dp" />

<EditText
android:id="@+id/editText3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/editText2"
android:layout_alignLeft="@+id/editText2"
android:layout_marginTop="30dp" />

<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/editText1"
android:layout_alignBottom="@+id/editText1"
android:layout_alignParentLeft="true"
android:text="Send To:"
android:textColor="#0F9D58" />

<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/editText2"
android:layout_alignBottom="@+id/editText2"
android:layout_alignParentLeft="true"
android:text="Email Subject:"
android:textColor="#0F9D58" />

<TextView
android:id="@+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/editText3"
android:layout_alignBottom="@+id/editText3"
android:text="Email Body:"
android:textColor="#0F9D58" />

<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/editText3"
android:layout_alignLeft="@+id/editText3"
android:layout_marginLeft="76dp"
android:layout_marginTop="20dp"
android:text="Send email!!" />
</RelativeLayout>

MainActivity.java:

import android.content.Intent;
import android.os.Bundle;
import android.widget.Button;
import android.widget.EditText;
import androidx.appcompat.app.AppCompatActivity;
public class MainActivity extends AppCompatActivity {
// define objects for edit text and button
Button button;
EditText sendto, subject, body;

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

// Getting instance of edittext and button


sendto = findViewById(R.id.editText1);
subject = findViewById(R.id.editText2);
body = findViewById(R.id.editText3);
button = findViewById(R.id.button);
// attach setOnClickListener to button with Intent object define in it
button.setOnClickListener(view -> {
String emailsend = sendto.getText().toString();
String emailsubject = subject.getText().toString();
String emailbody = body.getText().toString();

// define Intent object with action attribute as ACTION_SEND


Intent intent = new Intent(Intent.ACTION_SEND);

// add three fields to intent using putExtra function


intent.putExtra(Intent.EXTRA_EMAIL, new String[]{emailsend});
intent.putExtra(Intent.EXTRA_SUBJECT, emailsubject);
intent.putExtra(Intent.EXTRA_TEXT, emailbody);

// set type of intent


intent.setType("message/rfc822");

// startActivity with intent with chooser as Email client using


createChooser function
startActivity(Intent.createChooser(intent, "Choose an Email client :"));
});
}
}
Input Code for receive Email:

MainActivity.java:

package com.example.myemailprog;
import androidx.appcompat.app.AppCompatActivity;
import android.content.IntentFilter;
import android.os.Bundle;

public class MainActivity extends AppCompatActivity {


GmailReceiver gml;
IntentFilter intf;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
gml = new GmailReceiver();
intf = new IntentFilter("android.intent.action.VIEW");
}

@Override
protected void onResume() {
super.onResume();
registerReceiver(gml, intf);
}

@Override
protected void onDestroy() {
super.onDestroy();
unregisterReceiver(gml);
}
}

Gmailreceiver.java:

package com.example.myemailprog;

import android.app.Notification;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.res.Resources;
import android.graphics.BitmapFactory;
import android.widget.Toast;

public class GmailReceiver extends BroadcastReceiver


{
@Override
public void onReceive(Context context, Intent intent)
{
Toast.makeText(context, "Email Received", Toast.LENGTH_LONG).show();

}
}

AndroidManifest.xml:

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


<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myemailprog">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.MyEmailProg">
<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>
<receiver android:name="GmailReceiver"
android:exported="false">
<intent-filter>
<action android:name="android.intent.action.PROVIDER_CHANGED"
android:priority="-10">
</action>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="content" android:host="gmail-ls"
android:pathPattern="/unread/.*">
</data>
</intent-filter>
</receiver>
</application>
</manifest>

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