Unit Vi
Unit Vi
The Android Security Model keeps your data and device safe using different methods.
The five main parts are:
A. Design Review
Experts check Android’s design early to find and fix possible security problems.
B. Penetration Testing and Code Review
Google tests the system and reviews the code to catch and fix security bugs
before updates are released.
C. Open Source and Community Review
Android is open-source, so anyone in the developer community can check the
code and report issues.
D. Incident Response
Google has a team that quickly fixes security issues and sends updates to users
and phone companies.
E. Monthly Security Updates
Android phones get security updates every month to protect against new
threats.
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/sensorListText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
android:textSize="16sp" />
</ScrollView>
import android.app.Activity;
import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.os.Bundle;
import android.widget.TextView;
import java.util.List;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
textView.setText(sensors.toString());
setContentView(textView);
}
}
<Button
android:id="@+id/sendEmailButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Send Email" />
</LinearLayout>
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (emailIntent.resolveActivity(getPackageManager()) != null) {
startActivity(Intent.createChooser(emailIntent, "Send Email"));
}
}
});
}
}
6. Write a program to show users current location.
<TextView
android:id="@+id/locationText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Fetching location..."
android:textSize="18sp" />
</LinearLayout>
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import com.google.android.gms.location.FusedLocationProviderClient;
import com.google.android.gms.location.LocationServices;
import com.google.android.gms.tasks.OnSuccessListener;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
locationText = findViewById(R.id.locationText);
fusedLocationClient = LocationServices.getFusedLocationProviderClient(this);
// Check permission
if (ContextCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_FINE_LOCATION)
!= PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, 1);
} else {
showLocation();
}
}
✅ 1. Permissions in AndroidManifest.xml
<EditText
android:id="@+id/phoneNumber"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter phone number"
android:inputType="phone" />
<EditText
android:id="@+id/message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Enter message"
android:inputType="textMultiLine" />
<Button
android:id="@+id/sendBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Send SMS" />
</LinearLayout>
✅ 3. Java Code (MainActivity.java)
import android.Manifest;
import android.app.Activity;
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;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
phoneNumber = findViewById(R.id.phoneNumber);
message = findViewById(R.id.message);
sendBtn = findViewById(R.id.sendBtn);
sendBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
String number = phoneNumber.getText().toString();
String msg = message.getText().toString();
try {
SmsManager smsManager = SmsManager.getDefault();
smsManager.sendTextMessage(number, null, msg, null, null);
Toast.makeText(getApplicationContext(), "SMS Sent",
Toast.LENGTH_SHORT).show();
} catch (Exception e) {
Toast.makeText(getApplicationContext(), "SMS Failed",
Toast.LENGTH_SHORT).show();
e.printStackTrace();
}
}
});
}
}
8. Explain two methods of Google Map.
addMarker()
This method is used to add a marker (pin) on the map at a specific latitude and
longitude.
Example:
googleMap.addMarker(new MarkerOptions().position(new LatLng(19.0760,
72.8777)).title("Mumbai"));
moveCamera()
It is used to move the camera view to a specific location on the map.
Example:googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(new
LatLng(19.0760, 72.8777), 12));
A. Geocoding:
It is the process of converting an address or location name into geographic
coordinates (latitude & longitude).
1. Example: "Taj Mahal, Agra" → 27.1751, 78.0421
B. Reverse Geocoding:
It is the process of converting geographic coordinates into a readable address.
10. Develop an application to display a Google Map. (Write JAVA and Manifest file)
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.simplemap">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<application
android:label="Simple Map"
android:theme="@style/Theme.AppCompat.Light.NoActionBar">
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="YOUR_API_KEY_HERE" />
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
<fragment xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/map"
android:name="com.google.android.gms.maps.SupportMapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
✅ Java Code (MainActivity.java)
import androidx.fragment.app.FragmentActivity;
import android.os.Bundle;
import com.google.android.gms.maps.*;
import com.google.android.gms.maps.model.*;
🔹 Main Methods:
1. getFromLocation(double latitude, double longitude, int maxResults)
🔁 Converts coordinates to address (Reverse Geocoding).
List<Address> addresses = geocoder.getFromLocation(19.0760, 72.8777, 1);
latitude and longitude: GPS coordinates.
maxResults: Number of results you want (usually 1).
returns: List of Address objects.
✅ Example:
Geocoder geocoder = new Geocoder(this, Locale.getDefault());
List<Address> addresses = geocoder.getFromLocation(28.6139, 77.2090, 1);
if (!addresses.isEmpty()) {
String address = addresses.get(0).getAddressLine(0);
}
12. Develop and application to send and receive SMS (Design minimal UI as per your choice.
Write XML, java and manifest file)
✅ 1. AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.smsapp">
<application
android:label="SMS App"
android:theme="@style/Theme.AppCompat.Light.DarkActionBar">
<receiver android:name=".SMSReceiver">
<intent-filter>
</intent-filter>
</receiver>
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:padding="20dp"
android:layout_width="match_parent" android:layout_height="match_parent">
<EditText
android:id="@+id/phoneNumber"
android:layout_width="match_parent"
android:layout_height="wrap_content"
<EditText
android:id="@+id/message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
<Button
android:id="@+id/sendBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
<TextView
android:id="@+id/receivedMsg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Received Message:"
android:textSize="16sp" />
</LinearLayout>
✅ 3. MainActivity.java
import android.Manifest;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.view.View;
import android.widget.*;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
Button sendBtn;
@Override
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
phoneNumber = findViewById(R.id.phoneNumber);
message = findViewById(R.id.message);
sendBtn = findViewById(R.id.sendBtn);
receivedMsg = findViewById(R.id.receivedMsg);
// Request permissions
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.SEND_SMS, Manifest.permission.RECEIVE_SMS,
Manifest.permission.READ_SMS}, 1);
sendBtn.setOnClickListener(new View.OnClickListener() {
@Override
try {
} catch (Exception e) {
});
✅ 1. Permissions in AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.cartracker">
<application
android:label="Car Location Tracker"
android:theme="@style/Theme.AppCompat.Light.NoActionBar">
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="YOUR_API_KEY_HERE" />
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
🔁 Replace YOUR_API_KEY_HERE with your actual Google Maps API key.
✅ 3. MainActivity.java
import android.Manifest;
import android.content.pm.PackageManager;
import android.location.Location;
import android.os.Bundle;
import androidx.annotation.NonNull;
import androidx.core.app.ActivityCompat;
import androidx.fragment.app.FragmentActivity;
import com.google.android.gms.location.*;
import com.google.android.gms.maps.*;
import com.google.android.gms.maps.model.*;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
fusedLocationClient = LocationServices.getFusedLocationProviderClient(this);
SupportMapFragment mapFragment = (SupportMapFragment)
getSupportFragmentManager()
.findFragmentById(R.id.map);
mapFragment.getMapAsync(this);
}
@Override
public void onMapReady(GoogleMap googleMap) {
mMap = googleMap;
if (ActivityCompat.checkSelfPermission(this,
Manifest.permission.ACCESS_FINE_LOCATION) !=
PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, 1);
return;
}
mMap.setMyLocationEnabled(true);
@Override
public void onRequestPermissionsResult(int requestCode,
@NonNull String[] permissions,
@NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
if (requestCode == 1 && grantResults.length > 0 &&
grantResults[0] == PackageManager.PERMISSION_GRANTED) {
onMapReady(mMap);
}
}
}
🔹 Geocoding
Definition: Geocoding is the process of converting a place name or address into latitude
and longitude coordinates.
Example:
Input: "Gateway of India, Mumbai"
Output: Latitude = 18.921984, Longitude = 72.834654
📌 Used in: Finding the location of landmarks, addresses, or user input on a map.
🔹 Reverse Geocoding
Definition: Reverse Geocoding is the process of converting latitude and longitude into a
human-readable address.
Example:
Input: Latitude = 28.6139, Longitude = 77.2090
Output: "Rajpath Area, Central Secretariat, New Delhi, India"
18. List and elaborate steps to deploy an Android application on Google play store.
Create Developer Account – Register at Google Play Console and pay one-time
$25 fee.
Build Signed APK/AAB – Create a signed app bundle for release.
Test the App – Make sure the app runs smoothly on devices.
Create App in Play Console – Add app name, details, and accept policies.
Upload AAB File – Go to Production > Create Release, upload the AAB.
Add Store Listing – Fill title, description, screenshots, icon, etc.
Set Rating and Pricing – Choose content rating and free/paid status.
Review and Publish – Review all settings and click "Publish".
19. Develop an android application for sending Short Message Service (SMS).
✅ 1. Permission in AndroidManifest.xml
<uses-permission android:name="android.permission.SEND_SMS" />
✅ 2. Layout (activity_main.xml)
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent" android:padding="16dp">
import android.Manifest;
import android.os.Bundle;
import android.telephony.SmsManager;
import android.view.View;
import android.widget.*;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
phone = findViewById(R.id.phone);
message = findViewById(R.id.message);
send = findViewById(R.id.send);
send.setOnClickListener(v -> {
String number = phone.getText().toString();
String msg = message.getText().toString();
SmsManager.getDefault().sendTextMessage(number, null, msg, null, null);
Toast.makeText(this, "SMS Sent!", Toast.LENGTH_SHORT).show();
});
}
}