Question Bank MAD PT2 Exam 22-23-CO-IF
Question Bank MAD PT2 Exam 22-23-CO-IF
Android-powered devices have built-in sensors that measure motion, orientation, and various
environmental conditions. These sensors are capable of providing raw data with high precision and
accuracy, and are useful if you want to monitor three-dimensional device movement or positioning,
or you want to monitor changes in the ambient environment near a device.
Motion sensors
These sensors measure acceleration forces and rotational forces along three axes. This category
includes accelerometers, gravity sensors, gyroscopes, and rotational vector sensors.
Environmental sensors
These sensors measure various environmental parameters, such as ambient air temperature and
pressure, illumination, and humidity. This category includes barometers, photometers, and
thermometers.
Position sensors
Android Intent is the message that is passed between components such as activities, content
providers, broadcast receivers, services etc. It is generally used with startActivity() method to invoke
activity, broadcast receivers etc.
1) Implicit Intent
It doesn't specify the component. In such case, intent provides information of available components
provided by the system that is to be invoked.
2) Explicit Intent
It specifies the component. In such case, intent provides the external class to be invoked.
Android service is a component that is used to perform operations on the background such as
playing music, handle network transactions, interacting content providers etc. It doesn't has any UI
(user interface).The service runs in the background indefinitely even if application is
destroyed.Moreover, service can be bounded by a component to perform interactivity and inter
process communication (IPC).
There can be two forms of a service.The lifecycle of service can follow two different paths: started or
bound.
1. Started
2. Bound
A service is started when application component (like activity) starts or 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. A bound
service offers a client-server interface that allows components to interact with the service, send
requests, get results, and even do so across processes with interprocess communication (IPC).The
client can unbind the service by calling the unbindService() method.The service cannot be stopped
until all clients unbind the service.
Animation is the process of creating motion and shape change. Animation in android is possible in 3
ways:
1. Property Animations — They are used to alter property of objects (Views or non view objects).
We specify certain properties(like translateX, TextScaleX) of the objects to change. Various
characteristics of animation which can be manipulated are animation duration, whether to reverse
it and for how many times we want to repeat the animation etc. They were introduced in Android
3.0 (API level 11).
2. View Animations — They are used to do simple animations like changing size, position, rotation,
control transparency. They are easy to build and are very fast but have their own constraints. For
eg — Their state changes but their property does not change. View animations will be covered in
part 2.
3. Drawable Animations — This is used to do animation using drawables. An XML file specifying
various list of drawables is made which are run one by one just like a roll of a film. This is not
much used so I won‟t cover it.
Text to speech, abbreviated as TTS, is a form of speech synthesis that converts text into spoken
voice output. Text to speech systems were first developed to aid the visually impaired by offering a
computer-generated spoken voice that would "read" text to the user. Android TTS API offers
multiple-language support, control of voice characteristics and features, file output, and so on.
With just a small number of lines of code, you can make your apps reach out to a wider audience.
1. Shared Preferences
You should use this to save primitive data in key-value pairs. You have a key, which must be a
String, and the corresponding value for that key, which can be one of: boolean, float, int, long or
string. Internally, the Android platform stores an app‟s Shared Preferences in an xml file in a private
directory.
2. Internal Storage
The Internal Storage data storage method is specifically for those situations where you need to store
data to the device filesystem, but you do not want any other app (even the user) to read this data.
Data stored using the Internal Storage method is completely private to your application, and are
deleted from the device when your app is uninstalled.
To save (and/or read) files to the device‟s external storage, your app must request for the
WRITE_EXTERNAL_STORAGE permission. If you only want to read from the External Storage
without writing, request for the READ_EXTERNAL_STORAGE permission. The
WRITE_EXTERNAL_STORAGE permission grants both read/write access.
4. SQLite database
Finally, Android provides support for apps to use SQLite databases for data storage. Databases
created are app specific, and are available to any class within the app, but not to outside applications.
The Location object represents a geographic location which can consist of a latitude, longitude, time
stamp, and other information such as bearing, altitude and velocity. There are following important
methods which you can use with Location object to get location specific information −
1
float distanceTo(Location dest)
Returns the approximate distance in meters between this location and the given location.
2
float getAccuracy()
Get the estimated accuracy of this location, in meters.
3
double getAltitude()
Get the altitude if available, in meters above sea level.
4
float getBearing()
Get the bearing, in degrees.
5
double getLatitude()
Get the latitude, in degrees.
7
float getSpeed()
Get the speed if it is available, in meters/second over ground.
8
boolean hasAccuracy()
True if this location has an accuracy.
9
boolean hasAltitude()
True if this location has an altitude.
10
boolean hasBearing()
True if this location has a bearing.
11
boolean hasSpeed()
True if this location has a speed.
12
void reset()
Clears the contents of the location.
13
void setAccuracy(float accuracy)
Set the estimated accuracy of this location, meters.
14
void setAltitude(double altitude)
Set the altitude, in meters above sea level.
15
void setBearing(float bearing)
Set the bearing, in degrees.
16
void setLatitude(double latitude)
Set the latitude, in degrees.
17
void setLongitude(double longitude)
Set the longitude, in degrees.
19
String toString()
Returns a string containing a concise, human-readable description of this object.
The most common IDE for Android development is Android Studio, which comes directly from
Google itself.
After the installation of Android Studio, You also need to install Java on your machine to use
Android Studio. The JDK is able to interpret and compile your code for the application development.
Choose „Start a new Android Studio Project‟ option. Enter the name you want for your application
and your „company domain‟. All these elements will be used to create your package name in a format
like: com.companyname.appname
Moreover, you‟ll be given the option to pick the way you want the app to look at the beginning. This
will be the look of your main „Activity Module‟ which is basically the main page of your app. There
are various fields available which you have to choose according to your app needs, such as templates,
title, access to Google maps, full-screen activity, blank activity etc. As per my view, it‟s better to go
for „Basic Activity‟ to keep things as simple as possible and for all intents and purposes.
Go to the activity_main.xml tab if it is not open. Click and drag the “Hello, world!” from the upper
left corner of the phone display to the center of the screen. Then go to the values folder, and double-
click the strings.xml file. In this file, find the line “Hello world!” and add “Welcome to my App!”
In the Palette menu to the left of display, find Button. Click and drag Button to be positioned beneath
welcome message. Afterward, go to properties and find the field for text. Change the text from “New
Button” to “Next Page”.
Now go back to your content_main.xml and click on the button. In the right corner, where you have
your parameters for the button, you will catch an option called „onClick‟. Click on this and then
select the „onClick‟. By doing this, you have told Android Studio that you want to associate the
section of code with the button created.
Finally, all that‟s missing to do is run the app you just made. Simple go to „run‟ along the top and
then select „run app‟ from the drop-down menu. Follow the steps to launch the emulator running
your app.
syntax:
1. Create an account
Firstly, To publish your app on google play store, you need to have account on google. You may
have already personal email account with them but for your app it's better to separate one for manage
your app(s) easily. You would have to pay a registration fees of 25 USD, using Google payments,
While registering your publisher account. After that, a verification mail would be sent to you and
then you sign in to your developer console, where all action would take place.
Developer console is starting point and main dashboard for publishing tools and operations. Before
you go ahead, familiarise yourself with list of merchant countries and developer countries. You need
to review list of merchant countries if you want to sell apps or in app purchases or have subscriptions
and list of developer countries will tell you about locations where distribution to Google play users is
supported. Apart from this, also looks the Google Play‟s Terms and conditions.
After this, you have to provide your complete account details like you have to provide your
developer name, the name which would be displayed in Google Play Store. You will have to wait for
anything between just a little and 48 hours, after filling the details for Google play developer
registration to be processed.
If you have a paid app or subscription or in app purchases, then you have to inter link your google
payments merchant account and developer profile. It can be used for tax and financial identification
as well as monthly payout from sale.
When you are sign in your Google Play developer console, click on “Add new application” from
“All Applications tab”. After this select correct “Default Language” from drop down menu and then
type “title” of your app which would be appear on Google Play store. Then, select “Upload APK”
It is essential to test it with sample of end users to get feedback of app before launch your app even
Google play take care of this as well. In section of your app “APK” of developer console, you will
find option related to “Alpha Testing” and “Beta Testing”. After you uploaded your app‟s “APK” file
you can use these options for receive URL that can be shared with testers. By using this link, Testers
can download app beta or alpha version. Your testers can not provide reviews and feedback on app
page. Now you use this feedback to make relevant changes and optimise your app before publishing
in app store.
After uploading “APK” file go to “Store listing” tab. Over there you need to add details of app like
“Full description” and “Short description”. Along with this add categorisation, contact details, link of
promo video if you have, add screenshots and other necessary details to app. After complete
mandatory fields click on “Save” button. You can update your store listing anytime.
Now move on next tab, which is “Pricing and Distribution” and select it is “Paid” or “Free” app. You
also select distribution countries and check boxes stating your app complies with content guidelines.
If your app is an game one, then you can put in limelight using “Google Play for Game” option. Now
save changes and move on next step.
When all three tabs “Pricing and Distribution”, “Store Listing” and “APK” have been filled then
appear a green check mark next to them you are all ready to publish app in Google Play. After then
click on “Publish this app” button under “Ready to Publish” drop down menu at top right corner of
Developer console. A confirmation bar would show up stating your app would appear shortly in
Google Play Store.
Google map displays your current location, navigate location direction, search location etc. Google
Maps provides four types of maps. They are −
ROADMAP (normal, default 2D map)− This is the default type. If you haven't chosen any of
the types, this will be displayed. It shows the street view of the selected region.
SATELLITE (photographic map)− This is the map type that shows the satellite images of
the selected region.
HYBRID (photographic map + roads and city names)− This map type shows the major
streets on satellite images.
TERRAIN (map with mountains, rivers, etc.) − This is the map type that shows the terrain
and vegetation
Permissions are divided into several protection levels. The protection level affects whether runtime
permission requests are required. There are three protection levels that affect third-party
apps: normal, signature, and dangerous permissions.
Normal permissions
Normal permissions cover areas where your app needs to access data or resources outside the app's
sandbox, but where there's very little risk to the user's privacy or the operation of other apps. For
example, permission to set the time zone is a normal permission.
Signature permissions
The system grants these app permissions at install time, but only when the app that attempts to use a
permission is signed by the same certificate as the app that defines the permission.
Dangerous permissions cover areas where the app wants data or resources that involve the user's
private information, or could potentially affect the user's stored data or the operation of other apps.
For example, the ability to read the user's contacts is a dangerous permission. If an app declares that
it needs a dangerous permission, the user has to explicitly grant the permission to the app. Until the
user approves the permission, your app cannot provide functionality that depends on that permission.
Special permissions
There are a couple of permissions that don't behave like normal and dangerous
permissions. SYSTEM_ALERT_WINDOW and WRITE_SETTINGS are particularly sensitive, so
most apps should not use them. If an app needs one of these permissions, it must declare the
permission in the manifest, and send an intent requesting the user's authorization. The system
responds to the intent by showing a detailed management screen to the user.
Starting from Android 6.0 (API 23), users are not asked for permissions at the time of installation
rather developers need to request for the permissions at the run time. Only the permissions that
are defined in the manifest file can be requested at run time.
If the user Accepts the permissions, the app is installed. Else the app installation is cancelled.
2. Run-Time Permissions: If the Android 6 (API 23) or higher, the permission is requested at
the run time during the runnnig of the app.
Activity is one of the building blocks of Android OS. In simple words Activity is a screen that user
interact with. Every Activity have a predefined life-cycle methods. Activity in android has lifecycle
like created, started, resumed, paused, stopped or destroyed. These different states are known
as Activity Lifecycle.
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.
19.State syntax to create Text View and Image button with any two attributes of
each.
Text View:
<TextView
android:id="@+id/txt1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Enter Your name" />
Attributes/Properties of TextView:
ImageButton:
Syntax :
<ImageButton
android:id="@+id/addBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/add_icon" />
Attributes/Properties of ImageButton:
id: id is an attribute used to uniquely identify a image button.
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">
<TextView
android:id="@+id/txt1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="35dp"
android:text="Enter Your name"
android:textSize="20dp" />
<EditText
android:id="@+id/username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/txt1"
android:ems="20"
android:textSize="20dp" />
<TextView
<EditText
android:id="@+id/password"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/txt2"
android:inputType="phone"
android:ems="20"
android:textSize="20dp" />
<Button
android:id="@+id/button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/password"
android:ems="20"
android:text="Submit"
android:textSize="20dp" />
<TextView
android:id="@+id/txt3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/button"
android:textSize="20dp" />
</RelativeLayout>
Java:
package com.example.exp7_2;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
MAD Ques. Bank CO/IF PT-2 exam 22-23 Page 17
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="MSBTE 6th Sem Subjects"
android:textColor="@color/teal_200"
android:textSize="30sp"
android:layout_margin="20dp"
android:textAlignment="center"
/>
<AutoCompleteTextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="30dp"
android:layout_marginVertical="20dp"
android:layout_marginHorizontal="20dp"
android:id="@+id/AutoCompleteTextView"
android:ems="20">
<requestFocus/>
</AutoCompleteTextView>
</LinearLayout>
Java Code
package com.example.exp8_2;
import androidx.appcompat.app.AppCompatActivity;
import android.database.DataSetObserver;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Adapter;
import android.widget.ArrayAAdapter;
import android.widget.AutoCompleteTextView;
public class MainActivity extends AppCompatActivity {
String[] sub={"MAD","WBP","PWP","ETI","MGT","CPE"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ArrayAdapter<String> arrayAdapter=new
ArrayAdapter<String>(this,android.R.layout.select_dialog_item,sub);
AutoCompleteTextView actv=(AutoCompleteTextView)
findViewById(R.id.AutoCompleteTextView);
actv.setAdapter(arrayAdapter);
actv.setThreshold(1);
actv.setTextColor(Color.RED);
}
}
22.Write a program to create a text field and button “Navigate”. When you enter
www.google.com and press on navigate button it should open the google page.
activity_main.xml
<EditText
android:id="@+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="60dp"
android:ems="10"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.575"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<Button
android:id="@+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="8dp"
android:layout_marginLeft="156dp"
android:layout_marginTop="172dp"
android:text="Navigate"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
</androidx.constraintlayout.widget.ConstraintLayout>
MainActivity.java
package com.example.implicit_intent_navigate;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.content.Intent;
import android.net.Uri;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
Button button;
EditText editText;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
button = findViewById(R.id.button);
editText = findViewById(R.id.editText);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String url=editText.getText().toString();
Intent intent=new Intent(Intent.ACTION_VIEW,
Uri.parse(url));
startActivity(intent);
}
});
}
}
XML CODE:
JAVA CODE:
package com.example.exp13_1;
import androidx.appcompat.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.Button;
public class MainActivity extends AppCompatActivity {
Button b1;
ProgressBar pb;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
b1=(Button) findViewById(R.id.button);
pb=(ProgressBar) findViewById(R.id.ProgressBar);
}
public void display(View view){
pb.setVisibility(View.VISIBLE);
}
}
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="249dp"
android:layout_weight="1"
android:src="@drawable/sun_spring_green_forest"/>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="change image" />
</LinearLayout>
MainActivity.java
package com.example.changeimage;
import android.app.Activity;
import android.content.DialogInterface;
import android.os.Bundle;
import android.widget.Button;
import android.widget.ImageView;
import android.view.View;
Button button;
ImageView img;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
addListenerOnButton();
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
img.setImageResource(R.drawable.palombaggia_beach_sunny);
}
});
}
}