2 Marks Questions:: A) List Features of Android Operating System
2 Marks Questions:: A) List Features of Android Operating System
on the types of device we want to test for. Below are the steps to create an AVD
from AVD manager graphical interface
c) Write the directory path where images are stored while developing Android
application.
Answer: In Android Operating system, generally there are a lot of files inside the
directory structure. For example these are manifest file, java file, activity file and the
most important file is resource file. This is also shows as res file sometimes.
syntax:
<intent-filter android:icon=”drawable resource”
android:label=”string resource” android:priority=”integer” >
...
</intent-filter>
There can be two forms of a service. The lifecycle of service can follow two different
paths: started or bound.
1. Started
2. Bound
1) Started Service
A service is started when component (like activity) calls startService() method, now
it runs in the background indefinitely. It is stopped by stopService() method. The
service can stop itself by calling the stopSelf() method.
2) Bound Service
A service is bound when another component (e.g. client)
calls bindService() method. The client can unbind the service by calling
the unbindService() method.
4 marks Questions :
a) Describe the Android architecture in detail.
Linux kernel
At the bottom of the layers is Linux – Linux 3.6 with approximately 115 patches. This
provides a level of abstraction between the device hardware and it contains all the
essential hardware drivers like camera, keypad, display etc. Also, the kernel handles
all the things that Linux is really good at such as networking and a vast array of
device drivers, which take the pain out of interfacing to peripheral hardware.
Libraries
On top of Linux kernel there is a set of libraries including open-source Web browser
engine WebKit, well known library libc, SQLite database which is a useful repository
for storage and sharing of application data, libraries to play and record audio and
video, SSL libraries responsible for Internet security etc.
Android Runtime
This is the third section of the architecture and available on the second layer from
the bottom. This section provides a key component called Dalvik Virtual
Machine which is a kind of Java Virtual Machine specially designed and optimized
for Android.
The Dalvik VM makes use of Linux core features like memory management and
multi-threading, which is intrinsic in the Java language. The Dalvik VM enables every
Android application to run in its own process, with its own instance of the Dalvik
virtual machine.
Application Framework
Applications
You will find all the Android application at the top layer. You will write your
application to be installed on this layer only. Examples of such applications are
Contacts Books, Browser, Games etc.
b) Differentiate between JVM and DVM.
By the help of activity, you can place all your UI components or widgets in a single
screen.
Let’s see the 7 lifecycle methods of android activity.
Method Description
onCreate called when activity is first created.
onStart called when activity is becoming visible to the user.
onResume called when activity will start interacting with the user.
onPause called when activity is not visible to the user.
onStop called when activity is no longer visible to the user.
onRestart called after your activity is stopped, prior to start.
onDestroy called before the activity is destroyed.
d) Discuss the need of permissions in Android. Describe the permissions to set system
functionalities like bluetooth,camera.
For example, suppose your app needs to be able to take pictures with the device
camera. Your app can request the CAMERA permission, which allows your app to
access the camera directly. Your app would then use the camera APIs to control the
camera and take a picture. This approach gives your app full control over the
photography process, and lets you incorporate the camera UI into your app.
if (ContextCompat.checkSelfPermission(thisActivity, Manifest.permission.CAMERA)
!= PackageManager.PERMISSION_GRANTED) {
Answer: As we know Android world is increasing day by day. Billions of Android apps
has been published on Google Play store. So it is the need of time that we should
learn some basics of Android development. Android Studio is an IDE (Integrated
Development Environment) for Android application development.
Installation
Step 1: Download android studio
Follow steps below for complete installation and configuration of Android Studio.
Click next and select Android SDK checked if you don’t have it already. Better is to
leave the default settings.
Step 7: Finish
This informs you installation has completed. Click Finish. Make sure Start Android
Studio is checked. Following splash screen of Android Studio will appear.
Apart form date attributes, DatePicker object is also passed into this function. You
can use the following methods of the DatePicker to perform further operation.
1
This method gets the selected day of month
getMonth()
2
This method gets the selected month
getYear()
3
This method gets the selected year
setMaxDate(long maxDate)
4
This method sets the maximal date supported by this DatePicker in milliseconds
since January 1, 1970 00:00:00 in getDefault() time zone
setMinDate(long minDate)
5
This method sets the minimal date supported by this NumberPicker in milliseconds
since January 1, 1970 00:00:00 in getDefault() time zone
setSpinnersShown(boolean shown)
6
This method sets whether the spinners are shown
updateDate(int year, int month, int dayOfMonth)
7
This method updates the current date
getCalendarView()
8
This method returns calendar view
getFirstDayOfWeek()
9
This Method returns first day of the week
Android Time Picker allows you to select the time of day in either 24 hour or
AM/PM mode. The time consists of hours, minutes and clock format. Android
provides this functionality through TimePicker class.
android:layout_height=”wrap_content” />
is24HourView()
1
This method returns true if this is in 24 hour view else false
isEnabled()
2
This method returns the enabled status for this view
setCurrentHour(Integer currentHour)
3
This method sets the current hour
setCurrentMinute(Integer currentMinute)
4
This method sets the current minute
setEnabled(boolean enabled)
5
This method set the enabled state of this view
setIs24HourView(Boolean is24HourView)
6
This method set whether in 24 hour or AM/PM mode
setOnTimeChangedListener(TimePicker.OnTimeChangedListener onTimeChangedL
istener)
7
This method Set the callback that indicates the time has been adjusted by the user
Here, we are going to see the example of sqlite to store and fetch the data. Data is
displayed in the logcat. For displaying data on the spinner or listview, move to the
next page.
Database Creation
In order to create a database you just need to call this method
openOrCreateDatabase with your database name and mode as a parameter. It
returns an instance of SQLite database which you have to receive in your own
object.Its syntax is given below
Apart from this , there are other functions available in the database package , that
does this job. They are listed below
1 This method only opens the existing database with the appropriate flag mode. The
common flags mode could be OPEN_READWRITE OPEN_READONLY
2
It is similar to the above method as it also opens the existing database but it does not
define any handler to handle the errors of databases
openOrCreateDatabase(String path, SQLiteDatabase.CursorFactory factory)
3
It not only opens but create the database if it not exists. This method is equivalent to
openDatabase method.
openOrCreateDatabase(File file, SQLiteDatabase.CursorFactory factory)
4
This method is similar to above method but it takes the File object as a path rather then
a string. It is equivalent to file.getPath()
h) Observe the following GUI and write an XML file using relative layout to create
the same.
android:layout_height=”fill_parent” android:paddingLeft=”16dp”
android:paddingRight=”16dp” >
<EditText
android:id=”@+id/name” android:layout_width=”fill_parent”
android:layout_height=”wrap_content” android:hint=”@string/reminder” />
<EditText
android:id=”@+id/name” android:layout_width=”fill_parent”
android:layout_height=”wrap_content” android:hint=”@string/reminder” />
<EditText
android:id=”@+id/name” android:layout_width=”fill_parent”
android:layout_height=”wrap_content” android:hint=”@string/reminder” />
</LinearLayout>
Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all
required details to create a new project.
<shape
android :useLevel= “true” > <!– this line fixes the issue for lollipop api 21 –>
<gradient
</shape>
</rotate>
android :shape= “ring” android :thickness= “1dp” android :useLevel= “false” >
<solid android :color= “#CCC” />
</shape>
<ProgressBar
</RelativeLayout>
<application
<intent-filter>
</intent-filter>
</activity>
</application>
</manifest>
Answer: In Android, Zoom Controls class display simple set of controls that is used
for zooming and provides callback to register for events. Zoom Controls has two
buttons ZoomIn and ZoomOut which are used to control the zooming functionality.
android:layout_height=”wrap_content” />
Important Methods Of Zoom Controls:
Now let’s discuss some common methods which are used to configure
ZoomControls in our application.
This method is used to hide the ZoomControls from the screen. In some
1. hide():
cases we need to hide the ZoomControls from the screen so that we use this
function.
This method is used to show the ZoomControls which we hide from the
2. show():
screen by using hide method.
This example demonstrates how do I
Zoom In and Zoom Out an android
ImageView.
Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all
required details to create a new project.
<LinearLayout
xmlns:android=”http://schemas.android.com/apk/res/android” xmlns:tools=”http://schemas.a
ndroid.com/tools”
android:layout_width=”match_parent” android:layout_height=”match_parent”
android:orientation=”vertical” android:padding=”16dp” android:gravity=”center”
tools:context=”.MainActivity”>
</LinearLayout>
Step 3 − Add the following code to src/MainActivity.java
import android.view.MotionEvent;
ScaleListener());
@Override
public boolean onTouchEvent(MotionEvent motionEvent) {
scaleGestureDetector.onTouchEvent(motionEvent); return true;
@Override
return true;
}
Step 4 − Add the following code to androidManifest.xml
android:roundIcon=”@mipmap/ic_launcher_round” android:supportsRtl=”true”
android:theme=”@style/AppTheme”>
<activity android:name=”.MainActivity”>
<intent-filter>
</intent-filter>
</activity>
</application>
</manifest>
k) Develop an application to send and receive SMS. (Write ONLY .java and permission tag
in manifest file)
Answers: In Android, you can use SmsManager API or devices Built-in SMS
application to send SMS’s. In this tutorial, we shows you two basic examples to send
SMS message –
SmsManager API
SmsManager smsManager = SmsManager.getDefault();
startActivity(sendIntent);
import android.Manifest;
import android.app.Activity;
import android.util.Log;
import android.view.Menu; import android.view.View;
@Override
sendSMSMessage();
});
if (ContextCompat.checkSelfPermission(this, Manifest.permission.SEND_SMS)
!= PackageManager.PERMISSION_GRANTED) {
if (ActivityCompat.shouldShowRequestPermissionRationale(this,
Manifest.permission.SEND_SMS)) {
} else { ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.SEND_SMS},
MY_PERMISSIONS_REQUEST_SEND_SMS);
@Override
switch (requestCode) {
case MY_PERMISSIONS_REQUEST_SEND_SMS: {
if (grantResults.length > 0
Toast.LENGTH_LONG).show();
} else { Toast.makeText(getApplicationContext(),
<activity
android:name=”com.example.tutorialspoint.MainActivity”
android:label=”@string/app_name” >
<intent-filter>
</intent-filter>
</activity>
</application>
</manifest>
6 marks Questions :
android:layout_height=”match_parent”
android:paddingBottom=”@dimen/activity_vertical_margin”
android:paddingLeft=”@dimen/activity_horizontal_margin”
android:paddingRight=”@dimen/activity_horizontal_margin”
android:paddingTop=”@dimen/activity_vertical_margin”
tools:context=”com.android_examples.com.edittextimageadd.MainActivity” >
<FrameLayout>
<ImageView
android:layout_width=”wrap_content”
android:layout_height=”wrap_content”
android:src=”@drawable/banner_image”
android:contentDescription=”@string/my_image_description”
/>
>
</FrameLayout>
android:layout_centerHorizontal=”true” android:layout_centerVertical=”true”
android:ems=”10″ android:drawableLeft=”@drawable/name_image” >
<requestFocus />
</EditText>
android:layout_centerHorizontal=”true” android:layout_centerVertical=”true”
android:ems=”10″ android:drawableLeft=”@drawable/email_image” >
<requestFocus />
</EditText>
android:layout_height=”wrap_content” android:layout_centerHorizontal=”true”
android:layout_centerVertical=”true”
android:ems=”10″ android:drawableLeft=”@drawable/pass_image” >
<requestFocus />
</EditText>
<requestFocus />
</EditText>
<EditText android:id=”@+id/editText1″
<requestFocus />
</EditText>
<RadioButton
android:id=”@+id/radioMale” android:layout_width=”wrap_content”
android:layout_height=”wrap_content” android:text=”male” android:checked=”true” />
<RadioButton
android:id=”@+id/radioFemale” android:layout_width=”wrap_content”
android:layout_height=”wrap_content” android:text=”female” />
<Button
android:id=”@+id/btnDisplay” android:layout_width=”wrap_content”
android:layout_height=”wrap_content” android:text=”register” />
</RelativeLayout>
Answer: Here’s an example activity that will launch the camera app and then retrieve
the image and display it.
package edu.gvsu.cis.masl.camerademo;
import android.widget.ImageView;
@Override
super.onCreate(savedInstanceState); setContentView(R.layout.main);
@Override
{
if (checkSelfPermission(Manifest.permission.CAMERA) !=
PackageManager.PERMISSION_GRANTED)
requestPermissions(new String[]{Manifest.permission.CAMERA},
MY_CAMERA_PERMISSION_CODE);
else
startActivityForResult(cameraIntent, CAMERA_REQUEST);
});
@Override
if (requestCode == MY_CAMERA_PERMISSION_CODE)
if (grantResults[0] == PackageManager.PERMISSION_GRANTED)
startActivityForResult(cameraIntent, CAMERA_REQUEST);
else
@Override
}
Here is the layout that the above activity uses. It is simply a LinearLayout containing
a Button with id button1 and an ImageView with id imageview1:
android:layout_width=”fill_parent” android:layout_height=”fill_parent”
>
<Button android:id=”@+id/button1″ android:layout_width=”wrap_content”
android:layout_height=”wrap_content” android:text=”@string/photo”></Button>
</LinearLayout>
<uses-feature android:name=”android.hardware.camera”></uses-feature>
Answers:
import android.view.View;
import android.widget.EditText;
@Override
editTextTo=(EditText)findViewById(R.id.editText1);
editTextSubject=(EditText)findViewById(R.id.editText2);
editTextMessage=(EditText)findViewById(R.id.editText3);
send=(Button)findViewById(R.id.button1);
send.setOnClickListener(new OnClickListener(){
@Override
String to=editTextTo.getText().toString();
String subject=editTextSubject.getText().toString();
String message=editTextMessage.getText().toString();
});
@Override
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.activity_main, menu);
return true; } }
Answer: There are two ways to get a users location in our application:
Google officially recommends using Google Play Location Service APIs. Android
Location Services API is still used to develop location-based apps for devices that
don’t support Google Play Services.
XML File
<?xml version=”1.0″ encoding=”utf-8″?>
<RelativeLayout
xmlns:android=”http://schemas.android.com/apk/res/android” xmlns:tools=”http://schemas.a
ndroid.com/tools” android:layout_width=”match_parent”
android:layout_height=”match_parent”
android:paddingBottom=”@dimen/activity_vertical_margin”
android:paddingLeft=”@dimen/activity_horizontal_margin”
android:paddingRight=”@dimen/activity_horizontal_margin”
android:paddingTop=”@dimen/activity_vertical_margin”
tools:context=”com.currentlocation.MainActivity”>
<Button
android:layout_width=”match_parent” android:layout_height=”wrap_content”
android:text=”Get Current Location” android:id=”@+id/getLocationBtn”/>
<TextView android:layout_width=”wrap_content”
android:layout_height=”wrap_content” android:id=”@+id/locationText”
android:layout_below=”@id/getLocationBtn”/>
</RelativeLayout>
Manifest File
<activity android:name=”.MainActivity”>
<intent-filter>
</intent-filter>
</activity>
</application>
</manifest>
MainActivity.java
package com.currentlocation;
@Override
});
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 5000,
5, this);
catch(SecurityException e) { e.printStackTrace();
@Override
location.getLongitude());
@Override
@Override
@Override