0% found this document useful (0 votes)
15 views49 pages

Unit 6 Notes MAD

The document outlines the development of an Android application for sending and receiving SMS, including necessary XML layouts, Java code, and permissions in the AndroidManifest.xml file. It also explains the SMS service in Android, types of permissions, and the importance of permissions for user privacy. Additionally, it covers geocoding and reverse geocoding processes with examples and code snippets for implementing these functionalities.

Uploaded by

Gajanan Markad
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)
15 views49 pages

Unit 6 Notes MAD

The document outlines the development of an Android application for sending and receiving SMS, including necessary XML layouts, Java code, and permissions in the AndroidManifest.xml file. It also explains the SMS service in Android, types of permissions, and the importance of permissions for user privacy. Additionally, it covers geocoding and reverse geocoding processes with examples and code snippets for implementing these functionalities.

Uploaded by

Gajanan Markad
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/ 49

Unit – 6 Security and Application Deployment

Q.1] Develop and application to send and receive SMS (Design


minimal UI as per your choice. Write XML, java and manifest file)
(Note: Consider appropriate XML file. All attributes are not required.
In java file all imports are not expected. Different relevant login/code
can be considered. Statements showing permissions can be written
under AndroidManifest.xml)OR
Develop and application to send SMS (Design minimal UI as per
your choice. Write XML ,Java and manifest file).

Permissions and <receiver> tag required in 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>
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:id="@+id/textView"
android:layout_width="81dp"
android:layout_height="41dp"
android:layout_marginEnd="268dp"
android:layout_marginBottom="576dp"
android:text="To :"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
<TextView
android:id="@+id/textView2"
android:layout_width="70dp"
android:layout_height="43dp"
android:layout_marginEnd="276dp"
android:layout_marginBottom="512dp"
android:text="Sms Text"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
<EditText
android:id="@+id/etPhno"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="40dp"
android:layout_marginBottom="572dp"
android:ems="10"
android:inputType="textPersonName"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
<EditText
android:id="@+id/etmsg"
android:layout_width="193dp"
android:layout_height="51dp"
android:layout_marginEnd="56dp"
android:layout_marginBottom="504dp"
android:inputType="textPersonName"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
tools:ignore="SpeakableTextPresentCheck" />
<Button
android:id="@+id/btnSms"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="156dp"
android:layout_marginBottom="400dp"
android:text="SEND SMS"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

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.permi
ssion.SEND_SMS)!=
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) {
Object[] sms = (Object[]) bundle.get("pdus");
for (int i=0; i < sms.length; i++) {
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();
}
}
}
}
Q.2] Define SMS service in android application development.
SMS:
▪ In Android, you can use SmsManager API or devices Built-in SMS
application to send SMS's
▪ Android SMS is stored in PDU (protocol description unit) format
SmsManager class takes care of sending the SMS message.
▪ We just need to get an instance of it and send the SMS message.
▪ We need to add permission to SEND_SMS in the Android manifest file.
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage("phoneNo", null, "sms message", null, null);
Q.3] Develop an android application for sending Short Message
Service (SMS). OR Develop a program to send an SMS.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/fstTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="100dp"
android:layout_marginTop="150dp"
android:text="Mobile No" />
<EditText
android:id="@+id/mblTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="100dp"
android:ems="10"/>
<TextView
android:id="@+id/secTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Message"
android:layout_marginLeft="100dp" />
<EditText
android:id="@+id/msgTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="100dp"
android:ems="10" />
<Button
android:id="@+id/btnSend"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="100dp"
android:text="Send SMS" />
</LinearLayout>
MainActivity.java
package in.org.msbte.sendsmsexample;
import android.content.Intent;
import android.net.Uri;
import android.provider.Telephony;
import android.support.v7.app.AppCompatActivity;
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 {
private EditText txtMobile;
private EditText txtMessage;
private Button btnSms;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
txtMobile = (EditText)findViewById(R.id.mblTxt);
txtMessage = (EditText)findViewById(R.id.msgTxt);
btnSms = (Button)findViewById(R.id.btnSend);
btnSms.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
try{
SmsManager smgr = SmsManager.getDefault();
smgr.sendTextMessage(txtMobile.getText().toString(),null,txtMessage.ge
tText().toString(),null,null);
Toast.makeText(MainActivity.this, "SMS Sent Successfully",
Toast.LENGTH_SHORT).show();
}
catch (Exception e){
Toast.makeText(MainActivity.this, "SMS Failed to Send, Please try
again",
Toast.LENGTH_SHORT).show();
}
}
});
}
}
Q.4] List types of permissions in android.
1. Normal Permissions
2. Dangerous Permissions
3. Signature Permissions

Q.5] Elaborate the need of permissions in Android. Explain the


permissions to set system functionalities like SEND-SMS,
Bluetooth.
The purpose of a permission is to protect the privacy of an Android user. Android
apps must request permission to access sensitive user data (such as contacts and
SMS), as well as certain system features (such as camera and internet).
Depending on the feature, the system might grant the permission automatically
or might prompt the user to approve the request.
1. android. permission. SEND_SMS
▪ Allows the app to send SMS messages. This may result in unexpected
charges.
▪ Malicious apps may cost you money by sending messages without your
confirmation.
Following is the code snippet to set SEND_SMS permissions in manifest file.
<uses-permission android: name="android.permission.SEND_SMS"/>
2. android. permission. BLUETOOTH
You need to provide following permissions in AndroidManifest.xml file.
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"
/>
Q.6] Define Geocoding and Reverse Geocoding.
1. Geocoding:
Geocoding is the process of transforming a street address or
other description of a location into a (latitude, longitude) coordinate.
2. Reverse Geocoding:
Reverse geocoding is the process of transforming a
(latitude, longitude) coordinate into a (partial) address.
Q.7] Explain Geocoding and Reverse Geocoding with suitable example.
▪ Geocoding is the process of transforming a street address or other
description of a location into a (latitude, longitude) coordinate.
▪ Reverse geocoding is the process of transforming a (latitude, longitude)
coordinate into a (partial) address.
▪ The amount of detail in a reverse geocoded location description may vary,
for example one might contain the full street address of the closest building,
while another might contain only a city name and postal code.
▪ The Geocoder class requires a backend service that is not included in the
core android framework.

activity_maps.xml
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="example.com.mapexample.MapsActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<EditText
android:layout_width="248dp"
android:layout_height="wrap_content"
android:id="@+id/editText"
android:hint="Search Location" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="searchLocation"
android:text="Search" />
</LinearLayout>
</fragment>
AndroidManifest.xml
<uses-permission
android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission
android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
MapsActivity.java
package example.com.mapexample;
import android.location.Address;
import android.location.Geocoder;
import android.os.Build;
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
import com.google.android.gms.location.LocationServices;
import android.location.Location;
import android.Manifest;
import android.content.pm.PackageManager;
import android.support.v4.content.ContextCompat;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.location.LocationListener;
import com.google.android.gms.location.LocationRequest;
import java.io.IOException;
import java.util.List;
public class MapsActivity extends FragmentActivity implements
OnMapReadyCallback,
LocationListener,GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener{
private GoogleMap mMap;
Location mLastLocation;
Marker mCurrLocationMarker;
GoogleApiClient mGoogleApiClient;
LocationRequest mLocationRequest;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
// Obtain the SupportMapFragment and get notified when the map is
ready to be
used.
SupportMapFragment mapFragment = (SupportMapFragment)
getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
if (android.os.Build.VERSION.SDK_INT >=
Build.VERSION_CODES.M) {
if (ContextCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_FINE_LOCATION)
== PackageManager.PERMISSION_GRANTED) {
buildGoogleApiClient();
mMap.setMyLocationEnabled(true);
}
}
else {
buildGoogleApiClient();
mMap.setMyLocationEnabled(true);
}
}
protected synchronized void buildGoogleApiClient() {
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API).build();
mGoogleApiClient.connect();
}
@Override
public void onConnected(Bundle bundle) {
mLocationRequest = new LocationRequest();
mLocationRequest.setInterval(1000);
mLocationRequest.setFastestInterval(1000);
mLocationRequest.setPriority(LocationRequest.PRIORITY_BALANCE
D_POWER_ACCURACY);
if (ContextCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_FINE_LOCATION)
== PackageManager.PERMISSION_GRANTED) {
LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleA
piClient,
mLocationRequest, this);
}
}
@Override
public void onConnectionSuspended(int i) {
}
@Override
public void onLocationChanged(Location location) {
mLastLocation = location;
if (mCurrLocationMarker != null) {
mCurrLocationMarker.remove();
}
//Place current location marker
LatLng latLng = new LatLng(location.getLatitude(),
location.getLongitude());
MarkerOptions markerOptions = new MarkerOptions();
markerOptions.position(latLng);
markerOptions.title("Current Position");
markerOptions.icon(BitmapDescriptorFactory.defaultMarker(BitmapDes
criptorFactory.HUE_GREEN));
mCurrLocationMarker = mMap.addMarker(markerOptions);
//move map camera
mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
mMap.animateCamera(CameraUpdateFactory.zoomTo(11));
//stop location updates
if (mGoogleApiClient != null) {
LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleA
piClient, this);
}
}
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
}
public void searchLocation(View view) {
Edit Text location Search = (EditText) findViewById(R.id.editText);
String location = locationSearch.getText().toString();
List<Address> addressList = null;
if (location != null || !location.equals("")) {
Geocoder geocoder = new Geocoder(this);
try {
addressList = geocoder.getFromLocationName(location, 1);
} catch (IOException e) {
e.printStackTrace();
}
Address address = addressList.get(0);
LatLng latLng = new LatLng(address.getLatitude(),
address.getLongitude());
mMap.addMarker(new MarkerOptions().position(latLng).title(location));
mMap.animateCamera(CameraUpdateFactory.newLatLng(latLng));
Toast.makeText(getApplicationContext(),address.getLatitude()+"
"+address.getLongitude(),Toast.LENGTH_LONG).show();
}
}
}
Q.8] State and elaborate the syntax of required class and methods
for Geocoding.
Syntax
Geocoder (Context context)
Constructs a Geocoder localized for the default locale.
Geocoder(Context context, Locale locale)
Constructs a Geocoder localized for the given locale.
Methods with Syntax
a. getFromLocation
Syntax
public List<Address> getFromLocation (double latitude, double longitude, int
maxResults)
public void getFromLocation (double latitude, double longitude, int maxResults,
Geocoder.GeocodeListener listener)
This method returns an array of Addresses that attempt to describe the area
immediately surrounding the given latitude and longitude. The returned addresses
should be localized for the locale provided to this class's constructor.
b. getFromLocationName
Syntax :
● public List<Address> getFromLocationName (String locationName, int
maxResults, double lowerLeftLatitude, double lowerLeftLongitude, double
upperRightLatitude, double upperRightLongitude)
● public void getFromLocationName (String locationName, int maxResults,
double lowerLeftLatitude, double lowerLeftLongitude, double
upperRightLatitude, double upperRightLongitude, Geocoder.GeocodeListener
listener)
● public void getFromLocationName (String locationName, int maxResults,
Geocoder.GeocodeListener listener)
● public List<Address> getFromLocationName (String locationName, int
maxResults)
Returns an array of Addresses that attempt to describe the named location, which
may be a place name such as "Dalvik, Iceland", an address such as "1600
Amphitheatre Parkway,
Mountain View, CA", an airport code such as "SFO", and so forth. The returned
addresses should be localized for the locale provided to this class's constructor.
c. isPresent
Syntax
public static boolean isPresent ()
Returns true if there is a geocoder implementation present that may return
results. If true, there is still no guarantee that any individual geocoding attempt
will succeed.
Q.9] Explain the procedure of Geo-coding and reverse Geo-coding.
Geo-Coding:
▪ If we know the latitude and longitude of a location, we can find out its
address using a process known as Geocoding. Google Maps in Android
supports this via the Geocoder class.
The following code shows how we can find out the address of a location we
have just touched using the getFromLocation() method:
classMapOverlay extends com.google.android.maps.Overlay
{
@Override
publicboolean draw(Canvas canvas, MapViewmapView,
boolean shadow, long when)
{
//...
}
@Override
publicbooleanonTouchEvent(MotionEvent event, MapViewmapView)
{
//---when user lifts his finger---
if (event.getAction() == 1) {
GeoPoint p = mapView.getProjection().fromPixels(
(int) event.getX(),
(int) event.getY());
Geocoder geoCoder = new Geocoder(
getBaseContext(), Locale.getDefault());
try {
List<Address> addresses = geoCoder.getFromLocation(
p.getLatitudeE6() / 1E6,
p.getLongitudeE6() / 1E6, 1);
String add = "";
if (addresses.size() > 0)
{
for (inti=0; i<addresses.get(0).getMaxAddressLineIndex();
i++)
add += addresses.get(0).getAddressLine(i) + "n";
}
Toast.makeText(getBaseContext(), add,
Toast.LENGTH_SHORT).show();
}
catch (IOException e) {
e.printStackTrace();
}
return true;
}
else
return false;
}
}
Reverse-geocoding:
▪ If we know the address of a location but want to know its latitude and
longitude, we can do so via reverse-Geocoding. Again, we can use the
Geocoder class for this purpose.
The following code shows how we can find the exact location of the Empire State
Building by using the getFromLocationName() method:
Geocoder geoCoder = new Geocoder(this, Locale.getDefault());
try {
List<Address> addresses = geoCoder.getFromLocationName(
"empire state building", 5);
String add = "";
if (addresses.size() > 0) {
p = new GeoPoint(
(int) (addresses.get(0).getLatitude() * 1E6),
(int) (addresses.get(0).getLongitude() * 1E6));
mc.animateTo(p);
mapView.invalidate();
}
} catch (IOException e) {
e.printStackTrace();
}
Once. the location is found, the above code navigates the map to the location.

Q.10] State syntax to display built in zoom control.


a) Built in Zoom control in Google map can be displayed with:
UiSettings.setZoomControlsEnabled(true);
OR
b) In case, while display Google map by intent, default zoom level can be given
in the form of data as geo:latitude,longitude?z=zoom where lat and lag are for
location and zoom level is to set initial zoom level whichranges from 0 to 21.
OR
c) In any normal activity, ZoomControl can be displayed as component by
following
syntax :
ZoomControl zoomControls = (ZoomControls)
findViewById(R.id.simpleZoomControl);
zoomControls.show().
Q.12] Develop a program to add "Hello World" marker at (10 ,10)
co-ordinates. Write only . java file.
Activity_maps.xml
package com.example.googlemap;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
public class MapsActivity extends FragmentActivity implements
OnMapReadyCallback {
private GoogleMap mMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
// Obtain the SupportMapFragment and get notified when the map is
ready to
be used.
SupportMapFragment mapFragment = (SupportMapFragment)
getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
// Add a marker in Sydney and move the camera
LatLng hello = new LatLng(10,10);
mMap.addMarker(new MarkerOptions().position(hello).title("Marker
Hello
World"));
mMap.moveCamera(CameraUpdateFactory.newLatLngZoom(mumbai,10
F));
}
}
Q.13] Describe the process of getting the map API key.
Step 1: Create a Google Cloud Project
Step 2: Enable the Maps SDK for Android
Step 3: Get the API Key
Step 4: Get Your SHA-1 Fingerprint (for Android Apps)
Step 5: Add the API Key to Your Android Project
Step 6: Verify and Test the API Key

Q.14] Explain two methods of Google Map.


1. getMyLocation(): This method returns the currently displayed user
location.
2. moveCamera(CameraUpdate update): This method repositions the
camera according to the instructions defined in the update.
Q.15] Develop an application to display a Google Map. (Write
JAVA & Manifest file).
AndroidManifest.xml code:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="example.com.mapexample">
<uses
permission android:name="android.permission.ACCESS_FINE_LOCATION
" />
<uses
permission android:name="android.permission.ACCESS_COARSE_LOCAT
ION" />
<uses-permission android:name="android.permission.INTERNET" />
<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/AppTheme">
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="@string/google_maps_key" />
<activity
android:name=".MapsActivity"
android:label="@string/title_activity_maps">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
code of MapsActivity.java:
package example.com.mapexample;
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
public class MapsActivity extends FragmentActivity implements
OnMapReadyC
allback{
private GoogleMap mMap;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
// Obtain the SupportMapFragment and get notified when the map is
ready to be used
.
SupportMapFragment mapFragment = (SupportMapFragment)
getSupportFragment
Manager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
// Add a marker in Sydney and move the camera
LatLng sydney = new LatLng(-34, 151);
mMap.addMarker(new MarkerOptions().position(sydney).title("Marker
in Sy
dney"));
mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
}
}

Q.16] Develop an application to display Google map with user's


current location. (Note : Consider the appropriate XML file. All
attributes are not required. In java file all imports are not expected.
Different relevant logic/code can be considered.)
OR Write a program to show users current location

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">
<fragment
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/google_map"
android:name="com.google.android.gms.maps.SupportMapFragment" />
</RelativeLayout>

MainActivity.Java:

package com.example.location;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
import androidx.fragment.app.FragmentActivity;
import android.Manifest;
import android.content.pm.PackageManager;
import android.location.Location;
import android.os.Bundle;
import android.widget.Toast;
import com.google.android.gms.location.FusedLocationProviderClient;
import com.google.android.gms.location.LocationServices;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.MarkerOptions;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.android.gms.tasks.Task;
public class MainActivity extends FragmentActivity implements
OnMapReadyCallback
{
Location currentlocation;
FusedLocationProviderClient fusedLocationProviderClient;
private static final int REQUEST_CODE = 101;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
fusedLocationProviderClient =
LocationServices.getFusedLocationProviderClient(this);
fetchLastLocation();
}
private void fetchLastLocation() {
if (ActivityCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_FINE_LOCATION) !=
PackageManager.PERMISSION_GRANTED &&
ActivityCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_COARSE_LOCATION) !=
PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this,new
String[]{Manifest.permission.ACCESS_FINE_LOCATION},REQUEST
_CODE);
return;
}
Task<Location> task = fusedLocationProviderClient.getLastLocation();
task.addOnSuccessListener(new OnSuccessListener<Location>() {
@Override
public void onSuccess(Location location) {
if(location!=null)
{
currentlocation=location;
Toast.makeText(getApplicationContext(),currentlocation.getLatitude()+""
+current
location.getLongitude(), Toast.LENGTH_SHORT).show();
SupportMapFragment supportMapFragment =
(SupportMapFragment)getSupportFragmentManager().findFragmentById
(R.id.go
ogle_map);
supportMapFragment.getMapAsync(MainActivity.this);
}
}
});
}
@Override
public void onMapReady(@NonNull GoogleMap googleMap) {
LatLng latLng=new
LatLng(currentlocation.getLatitude(),currentlocation.getLongitude());
MarkerOptions markerOptions=new MarkerOptions().position(latLng)
.title("I am Here");
googleMap.animateCamera(CameraUpdateFactory.newLatLng(latLng));
googleMap.animateCamera(CameraUpdateFactory.newLatLngZoom(latL
ng,5));
googleMap.addMarker(markerOptions);
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull
String[]
permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions,
grantResults);
switch (requestCode) {
case REQUEST_CODE:
if (grantResults.length > 0 && grantResults[0] ==
PackageManager.PERMISSION_GRANTED) {
fetchLastLocation();
}
break;
}
}
}

Q.17] Name any four methods to get location data in android.


1. float distanceTo(Location dest)
2. float getAccuracy()
3. float getBearing()
4. double getAltitude()
5. double getLatitude()
6. float getSpeed()
7. boolean hasAccuracy()
8. boolean hasAltitude()
9. boolean hasBearing()
10.boolean hasBearing()
11.boolean hasSpeed()
12.void reset()
13.void setAccuracy(float accuracy)
14.void setAltitude(double altitude)

Q.18] Write a program to send e-mail.


(Note: Consider the appropriate XML file. All attributes are not
required.
Different relevant logic/code can be considered.)
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
package com.example.email;
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;
EditTextsendto,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 :"));
});
}
}
Q.19] Develop an android application to show current location of
an user's car
activity_maps.xml
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:map="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="example.com.mapexample.MapsActivity" />
MapsActivity.java
import android.os.Build;
import android.support.v4.app.FragmentActivity;
import android.os.Bundle;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.android.gms.maps.CameraUpdateFactory;
import com.google.android.gms.maps.GoogleMap;
import com.google.android.gms.maps.OnMapReadyCallback;
import com.google.android.gms.maps.SupportMapFragment;
import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import com.google.android.gms.maps.model.LatLng;
import com.google.android.gms.maps.model.Marker;
import com.google.android.gms.maps.model.MarkerOptions;
import com.google.android.gms.location.LocationServices;
import android.location.Location;
import android.Manifest;
import android.content.pm.PackageManager;
import android.support.v4.content.ContextCompat;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.location.LocationListener;
import com.google.android.gms.location.LocationRequest;
public class MapsActivity extends FragmentActivity implements
OnMapReadyCallback,
LocationListener,GoogleApiClient.ConnectionCallbacks,
GoogleApiClient.OnConnectionFailedListener{
private GoogleMap mMap;
Location mLastLocation;
Marker mCurrLocationMarker;
GoogleApiClient mGoogleApiClient;
LocationRequest mLocationRequest;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_maps);
// Obtain the SupportMapFragment and get notified when the map is
ready to be used.
SupportMapFragment mapFragment = (SupportMapFragment)
getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
if (android.os.Build.VERSION.SDK_INT >=
Build.VERSION_CODES.M) {
if (ContextCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_FINE_LOCATION)
== PackageManager.PERMISSION_GRANTED) {
buildGoogleApiClient();
mMap.setMyLocationEnabled(true);
}
}
else {
buildGoogleApiClient();
mMap.setMyLocationEnabled(true);
}
}
protected synchronized void buildGoogleApiClient() {
mGoogleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(LocationServices.API).build();
mGoogleApiClient.connect();
}
@Override
public void onConnected(Bundle bundle) {
mLocationRequest = new LocationRequest();
mLocationRequest.setInterval(1000);
mLocationRequest.setFastestInterval(1000);
mLocationRequest.setPriority(LocationRequest.PRIORITY_BALANCE
D_POWER_ACCURACY)
;
if (ContextCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_FINE_LOCATION)
== PackageManager.PERMISSION_GRANTED) {
LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleA
piClient,
mLocationRequest, this);
}
}
@Override
public void onConnectionSuspended(int i) {
}
@Override
public void onLocationChanged(Location location) {
mLastLocation = location;
if (mCurrLocationMarker != null) {
mCurrLocationMarker.remove();
+
//Place current location marker
LatLng latLng = new LatLng(location.getLatitude(),
location.getLongitude());
MarkerOptions markerOptions = new MarkerOptions();
markerOptions.position(latLng);
markerOptions.title("Current Position");
markerOptions.icon(BitmapDescriptorFactory.defaultMarker(BitmapDes
criptorFactory.HUE_GREEN));
mCurrLocationMarker = mMap.addMarker(markerOptions);
//move map camera
mMap.moveCamera(CameraUpdateFactory.newLatLng(latLng));
mMap.animateCamera(CameraUpdateFactory.zoomTo(11));
//stop location updates
if (mGoogleApiClient != null) {
LocationServices.FusedLocationApi.removeLocationUpdates(mGoogleA
piClient,
this);
}
}
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
}
}
Add the following user-permission in AndroidManifest.xml file.
<uses-permission
android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission
android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />
Note: only the permission line can be written , no entire code is required
for manifest file.

Q.20] Explain android security model.


Elaborate Android Security Model.
Explain the Android security model.
▪ Android is a multi-process system, in which each application (and parts of
the system) runs in its own process.
▪ Most security between applications and the system is enforced at the
process level through standard Linux facilities, such as user and group IDs
that are assigned to applications.
▪ Additional finer-grained security features are provided through a
“permission” mechanism that enforces restrictions on the specific
operations that a particular process can perform, and per-URI permissions
for granting ad-hoc access to specific pieces of data.
▪ The Android security model is primarily based on a sandbox and
permission mechanism.
▪ Each application is running in a specific Dalvik virtual machine with a
unique user ID assigned to it, which means the application code runs in
isolation from the code of all others applications. As a consequence, one
application has not granted access to other applications’ files.
▪ Android application has been signed with a certificate with a private key
Know the owner of the application is unique.
▪ This allows the author of The application will be identified if needed.
▪ When an application is installed in The phone is assigned a user ID, thus
avoiding it from affecting it Other applications by creating a sandbox for
it. This user ID is permanent on which devices and applications with the
same user ID are allowed to run in a single process.
▪ This is a way to ensure that a malicious application has Can not access /
compromise the data of the genuine application.
▪ It is mandatory for an application to list all the resources it will Access
during installation.
▪ The purpose of a permission is to protect the privacy of an Android user.
Android apps must request permission to access sensitive user data (such
as contacts and SMS), as well as certain system features (such as camera
and internet).
▪ Permissions are divided into several protection levels. The protection level
affects whether runtime permission requests are required.

▪ Android introduced shared user ID & permission to allow application


components talk to each other & enable application to access to critical
system in Android devices
Q.21] Describe permissions required for android application
development.
▪ The Android security model is primarily based on a sandbox and permission
mechanism.
▪ Each application is running in a specific Dalvik virtual machine with a unique
user ID assigned to it, which means the application code runs in isolation from
the code of all other applications. Therefore, one application has not granted
access to other applications’ files.
▪ Android application has been signed with a certificate with a private key Know
the owner of the application is unique. This allows the author of the application
will be identified if needed. When an application is installed in the phone is
assigned a user ID, thus avoiding it from affecting it other applications by
creating a sandbox for it. This user ID is permanent n which devices and
applications with the same user ID are allowed to run in a single process. This
is a way to ensure that a malicious application has Cannot access /compromise
the data of the genuine application. It is mandatory for an application to list all
the resources it will Access during installation. Terms are required of an
application, in the installation process should be user-based or interactive
Check with the signature of the application.
Declaring and Using Permissions
▪ The purpose of a permission is to protect the privacy of an Android user.
Android apps must request permission to access sensitive user data (such
as contacts and SMS), as well as certain system features (such as camera
and internet). Depending on the feature, the system might grant the
permission automatically or might prompt the user to approve the request.
▪ Permissions are divided into several protection levels. The protection level
affects whether runtime permission requests are required. There are three
protection levels that affect thirdparty 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. If an app declares in its manifest
that it needs a normal permission, the system automatically grants the app
that permission at install time. The system doesn’t prompt the user to grant
normal permissions, and users cannot revoke these permissions.
Signature permissions:
The system grants these app permissions at install time, but only when the
app that attempts to use permission is signed by the same certificate as the
app that defines the permission.
Dangerous permissions:
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 must explicitly grant the
permission to the app. Until the user approves the permission, your app
cannot provide functionality that depends on that permission. To use a
dangerous permission, your app must prompt the user to grant permission
at runtime. For more details about how the user is prompted, see Request
prompt for dangerous permission.
Q.22] Write down <user-permission> tag to acquire internet
permission.
To acquire internet permission in an Android app, you need to add the `<uses-
permission>` tag with the `android.permission.INTERNET` permission to your
app's manifest file. Here's
the syntax for the tag:
<uses-permission android:name="android.permission.INTERNET" />

Q.23] Describe types of permissions used while developing


android application.
Types of permissions
1. Install-time permissions
▪ Install-time permissions give your app limited access to restricted data, and
they allow your app to perform restricted actions that minimally affect the
system or other apps.
▪ When you declare install-time permissions in your app, the system
automatically grants your app the permissions when the user installs your
app.
▪ Android includes several sub-types of install-time permissions, Normal
permissions and Signature permissions.
a) Normal permissions
▪ These permissions allow access to data and actions that extend beyond
your app's sandbox.
▪ However, the data and actions present very little risk to the user's privacy,
and the peration of other apps.
b) Signature permissions
▪ If the app declares a signature permission that another app has defined, and
if the two apps are signed by the same certificate, then the system grants
the permission to the first app at install time.
▪ Otherwise, that first app cannot be granted the permission.
2. Runtime permissions
1. Runtime permissions, also known as dangerous permissions, give your app
additional access to restricted data, and they allow your app to perform
restricted actions that more substantially affect the system and other apps.
2. Many runtime permissions access private user data, a special type of
restricted data that includes potentially sensitive information. Examples of
private user data include location and contact information.
3. The system assigns the "dangerous" protection level to runtime
permissions.
3. Special permissions
▪ Special permissions correspond to particular app operations.
▪ Only the platform and OEMs can define special permissions.
▪ Additionally, the platform and OEMs usually define special permissions
when they want to protect access to particularly powerful actions, such as
drawing over other apps.
Q.24] Explain the steps to deploy app on Google Play Store.
Describe steps for deploying android application on Google
Play Store.
List and elaborate steps to deploy an Android application on
Google play store.
Describe the steps for publishing android app.
Step 1: Create a Developer Account
Before you can publish any app on Google Play, you need to create a
Developer Account. You can easily sign up for one using your existing Google
Account. You’ll need to pay a one-time registration fee of $25 using your
international credit or debit card. It can take up to 48 hours for your registration
to be fully processed.
Step 2: Plan to Sell? Link Your Merchant Account
If you want to publish a paid app or plan to sell in-app purchases, you
need to create a payments center profile, i.e. a merchant account. A merchant
account will let you manage your app sales and monthly payouts, as well as
analyze your sales reports right in your Play Console.
Step 3: Create an App
After creating application by clicking on ‘Create Application'. Here you
have to select your app’s default language from the drop-down menu and then
type in a title for your app. The title of your app will show on Google Play after
you’ve published.
Step 4: Prepare Store Listing
▪ Before you can publish your app, you need to prepare its store listing.
These are all the details that will show up to customers on your app’s listing
on Google Play. You not necessarily complete it at once, you can always
save a draft and revisit it later when you’re ready to publish.
▪ The information required for your store listing is divided into several
categories such as
Product Details containing title, short and full description of the app, your app’s
title and description should be written with a great user experience in mind. Use
the right keywords, but don’t overdo it. Make sure your app doesn’t come across
as spam-y or promotional, or it will risk getting suspended on the Play Store.
Graphic Assets where you can add screenshots, images, videos, promotional
graphics, and icons that showcase your app’s features and functionality.
Languages & Translations, Categorization where in category can be selected
to which your app belong to. Contact Details, Privacy Policy for apps that
request access to sensitive user data or permissions, you need to enter a
comprehensive privacy policy that effectively discloses how your app collects,
uses, and shares that data.
Step 5: Upload APK to an App Release
▪ Finally upload your app, by uploading APK file. Before you upload APK,
you need to create an app release. You need to select the type of release
you want to upload your first app version to. You can choose between an
internal test, a closed test, an open test, and a production release.
▪ The first three releases allow you to test out your app among a select group
of users before you make it go live for everyone to access.
▪ This is a safer option because you can analyze the test results and optimize
or fix your app accordingly if you need to before rolling it out to all users.
▪ Once you create a production release, your uploaded app version will
become accessible to everyone in the countries you choose to distribute it
in and click on ‘Create release.’
Step 6: Provide an Appropriate Content Rating
▪ If you don’t assign a rating to your app, it will be listed as ‘Unrated’. Apps
that are ‘Unrated’ may get removed from Google Play.
▪ To rate your app, you need to fill out a content rating questionnaire An
appropriate content rating will also help you get to the right audience,
which will eventually improve your engagement rates.
Step 7: Set Up Pricing & Distribution
▪ Before you can fill out the details required in this step, you need to
determine your app’s monetization strategy. Once you know how your app
is going to make money, you can go ahead and set up your app as free or
paid.
▪ You can always change your app from paid to free later, but you cannot
change a free app to paid. For that, you’ll need to create a new app and set
its price.
Step 8: Rollout Release to Publish Your App
▪ The final step involves reviewing and rolling out your release after making
sure you’ve taken care of everything else.
▪ Before you review and rollout your release, make sure the store listing,
content rating, and pricing and distribution sections of your app each have
a green check mark next to them.
▪ Once you’re sure about the correctness of the details, select your app and
navigate to ‘Release management’ – ‘App releases.’ You can always opt for
reviews by clicking on ‘Review’ to be taken to the ‘Review and rollout
release’ screen. Here, you can see if there are any issues or warnings you
might have missed out on.
▪ Finally, select ‘Confirm rollout.’ This will also publish your app to all users
in your target countries on Google Play.

Q.25] Explain importance of developer console in android


application development. OR Discuss developer console with at
least four features
1. Error Debugging:
The console logs runtime errors, crashes, and warnings. It provides detailed
stack traces, making it easier to identify and fix issues during development.
2. Real-Time Logs:
It displays real-time application logs, allowing developers to track events,
actions, and method calls while the app is running.
3. Performance Monitoring:
Helps measure memory usage, CPU activity, and network operations to
optimize the app’s performance.
4. Debugging UI Issues:
The console highlights UI-related errors like invalid layouts or missing
resources, helping ensure proper user interface design.
5. Testing and Feedback:
Supports testing by showing outputs of log messages (Log.d, Log.e, etc.),
making it easier to verify functionality and behavior during development.
Q.26] Design an app to make a phone call for a specific mobile
number OR Example of Intent
AndroidManifest.xml
<uses-permission android:name="android.permission.CALL_PHONE" />
Activity_main.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"
android:padding="16dp"
android:gravity="center">

<Button
android:id="@+id/call_button"
android:text="Call"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

</LinearLayout>
MainActivity.java
package com.example.call;
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends AppCompatActivity {

Button mCallButton;

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

mCallButton = findViewById(R.id.call_button);

mCallButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String phoneNumber = "8767847219";
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:" + phoneNumber));
startActivity(intent);

}
});
}
}
Q.27] Write a program to demonstrate declaring and using
permissions with any relevant example.
Permission declaring:
The permissions are declared in AndroidManifest.xml file under Manifest folder.
Permission can be set by <uses-permission> tag in AndroidManifest.xml.
Example:
Following example is to send SMS.
AndroidManifest.xml
<uses-permission android:name="android.permission.SEND_SMS"/>
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:id="@+id/textView"
android:layout_width="81dp"
android:layout_height="41dp"
android:layout_marginEnd="268dp"
android:layout_marginBottom="576dp"
android:text="To :"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>
<TextView
android:id="@+id/textView2"
android:layout_width="70dp"
android:layout_height="43dp"
android:layout_marginEnd="276dp"
android:layout_marginBottom="512dp"
android:text="Sms Text"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
<EditText
android:id="@+id/etPhno"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="40dp"
android:layout_marginBottom="572dp"
android:ems="10"
android:inputType="textPersonName"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
<EditText
android:id="@+id/etmsg"
android:layout_width="193dp"
android:layout_height="51dp"
android:layout_marginEnd="56dp"
android:layout_marginBottom="504dp"
android:inputType="textPersonName"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
tools:ignore="SpeakableTextPresentCheck" />
<Button
android:id="@+id/btnSms"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="156dp"
android:layout_marginBottom="400dp"
android:text="SEND SMS"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
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 {
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.permi
ssion.SEN
D_SMS)!=
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,"Smssentsuccessfully",
Toast.LENGTH_LONG).show();
}
catch(Exception e)
{
Toast.makeText(MainActivity.this,"Sms failed to send... try again",
Toast.LENGTH_LONG).show();
}
}
});
}
}

5th Chapter Question


Q.1] Explain significance of content provider.
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
Q.2] Design an app to accept a username in an edit text and on click
button click me it should open another activity to show
Hello<username>
Acivity_main.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"
android:padding="16dp">

<EditText
android:id="@+id/edittext"
android:hint="Username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text" />

<Button
android:id="@+id/button"
android:text="Show Username"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="showUsername" />
</LinearLayout>

Activity_greeting.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"
android:gravity="center"
android:padding="16dp">

<TextView
android:id="@+id/textview"
android:textSize="24sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />

</LinearLayout>
MainActivity.java
package com.example.username;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity extends AppCompatActivity {

Button btn;
EditText et;
String st;

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

btn = findViewById(R.id.button);
et = findViewById(R.id.edittext);

btn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent i = new Intent(MainActivity.this, GreetingActivity.class);
st = et.getText().toString();
i.putExtra("Value", st);
startActivity(i);
finish();
;
}
});
}
}
GreetingActivity.java
package com.example.username;
import static com.example.username.R.id.textview;
import android.annotation.SuppressLint;
import android.content.Intent;
import android.os.Bundle;
import android.widget.TextView;
import androidx.appcompat.app.AppCompatActivity;
public class GreetingActivity extends AppCompatActivity {

TextView tv;
String st;
@SuppressLint("MissingInflatedId")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_greeting);
tv=findViewById(textview);
st=getIntent().getExtras().getString("Value");
tv.setText(st);
}
}

Q.3] Enlist different location-based services. Explain any one


location-based service in detail.
▪ This became possible with the help of Google Play Services, which
falicitates adding location awareness to your app with automated location
tracking, geofencing, and activity recognition.
▪ A location based service (LBS) is a software service for mobile device
application that requires knowledge about where the mobile device is
geographicaly located.
▪ The application collects geodata, which is data gathered in real time using
one or more location tracking technologies.
There are numerous location-based services, including
1. Waze
2. Google Maps
3. Lyft
4. Uber
5. GasBuddy
6. WhatsApp
Google Map:
Google Maps is a popular location-based service that uses a combination of GPS,
satellite imagery, and other location data to provide users with maps, directions,
and other location-based information.
Here are some of the key features of Google Maps:
1] Maps and directions:
Google Maps provides detailed maps and
directions for users in over 220 countries and territories around the world. Users
can enter a destination address, and Google Maps will provide turn-by-turn
directions, estimated travel times, and traffic information.
2] Street View:
Google Maps also offers a feature called Street View, which
provides 360-degree panoramic views of streets and landmarks. Users can
explore neighborhoods, see businesses and landmarks up close, and even take
virtual tours of famous locations around the world.

You might also like