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

Chapter 6 Mad

The document provides an overview of SMS telephony, location-based services, and the Android security model. It details how to send and receive SMS messages, access user location, and manage permissions, emphasizing the importance of security and privacy. Additionally, it outlines the application deployment process, including building, signing, and distributing Android apps.

Uploaded by

Sayee Lembhe
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 views21 pages

Chapter 6 Mad

The document provides an overview of SMS telephony, location-based services, and the Android security model. It details how to send and receive SMS messages, access user location, and manage permissions, emphasizing the importance of security and privacy. Additionally, it outlines the application deployment process, including building, signing, and distributing Android apps.

Uploaded by

Sayee Lembhe
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/ 21

SMS Telephony in Android

1. Introduction to SMS Telephony in Android


SMS (Short Message Service) telephony in Android allows applications to send and receive
text messages programmatically. Android provides APIs for sending SMS, listening for
incoming messages, and managing SMS communication.

2. Sending SMS in Android

Using SmsManager API

The SmsManager class provides methods to send SMS messages.

Steps to Send SMS:


Get SmsManager Instance:​
java​
CopyEdit​
SmsManager smsManager = SmsManager.getDefault();

1.​

Send SMS:​
java​
CopyEdit​
smsManager.sendTextMessage(phoneNumber, null, message, null, null);

2.​
3.​ Permissions Required:

Add the following permission in AndroidManifest.xml:​


xml​
CopyEdit​
<uses-permission android:name="android.permission.SEND_SMS"/>
For Android 6.0+ (API 23+), request runtime permissions:​
java​
CopyEdit​
ActivityCompat.requestPermissions(this, new
String[]{Manifest.permission.SEND_SMS}, REQUEST_CODE);

○​

3. Receiving SMS in Android


To receive SMS, use a BroadcastReceiver to listen for incoming messages.

Steps to Receive SMS:


Create a Broadcast Receiver​
java​
public class SmsReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Bundle bundle = intent.getExtras();
if (bundle != null) {
Object[] pdus = (Object[]) bundle.get("pdus");
for (Object pdu : pdus) {
SmsMessage sms = SmsMessage.createFromPdu((byte[])
pdu);
String sender = sms.getOriginatingAddress();
String messageBody = sms.getMessageBody();
Log.d("SMSReceiver", "From: " + sender + ", Message:
" + messageBody);
}
}
}
}

1.​

Register the Receiver in AndroidManifest.xml​


xml​
<receiver android:name=".SmsReceiver">
<intent-filter>
<action
android:name="android.provider.Telephony.SMS_RECEIVED"/>
</intent-filter>
</receiver>

2.​

Permissions Required:​

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

4. SMS via Intent (Opening Default Messaging App)


Instead of sending an SMS programmatically, an app can launch the default SMS app:

java
CopyEdit
Intent smsIntent = new Intent(Intent.ACTION_VIEW);
smsIntent.setData(Uri.parse("sms:" + phoneNumber));
smsIntent.putExtra("sms_body", "Hello!");
startActivity(smsIntent);

5. Handling Permissions in Newer Android Versions


●​ Android 8.0+ (Oreo) requires foreground services for background SMS operations.
●​ Android 10+ restricts SMS access unless the app is the default SMS app.

To request default SMS app status:

java
CopyEdit
Intent intent = new
Intent(Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT);
intent.putExtra(Telephony.Sms.Intents.EXTRA_PACKAGE_NAME,
getPackageName());
startActivity(intent);

6. Security and Privacy Considerations


●​ Permission Restrictions: Ensure permissions are explicitly requested from users.
●​ Spam Prevention: Avoid sending bulk SMS to prevent app bans.
●​ Data Encryption: Secure sensitive SMS communications.

7. Conclusion
SMS telephony in Android enables apps to send and receive messages using SmsManager,
BroadcastReceiver, and Intents. However, with stricter permission policies in newer
Android versions, developers must handle permissions carefully and comply with security
guidelines.

Would you like code snippets for a full working example? 🚀

Notes on Location-Based Services (LBS)


in Android
1. Introduction to Location-Based Services (LBS)
Location-Based Services (LBS) in Android enable apps to access the device’s location using
GPS, Wi-Fi, and mobile networks. Android provides APIs for obtaining real-time location,
geocoding, and location updates.

2. Key Components of Location-Based Services


1. Google Location Services API

●​ The recommended way to get location in Android.


●​ Provides high accuracy and battery efficiency.

2. GPS (Global Positioning System)

●​ Provides precise location data using satellites.


●​ Works best outdoors but consumes more battery.

3. Network Provider (Wi-Fi & Cellular Towers)

●​ Provides approximate location using Wi-Fi and mobile network signals.


●​ Faster but less accurate than GPS.
4. Geocoding & Reverse Geocoding

●​ Converts latitude/longitude to an address (Reverse Geocoding).


●​ Converts an address to latitude/longitude (Geocoding).

3. Setting Up Location in Android

Permissions Required (AndroidManifest.xml)


xml
CopyEdit
<uses-permission
android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission
android:name="android.permission.ACCESS_COARSE_LOCATION"/>

For Android 10+ (API 29+), add:

xml
CopyEdit
<uses-permission
android:name="android.permission.ACCESS_BACKGROUND_LOCATION"/>

For runtime permission requests (Android 6.0+), use:

java
CopyEdit
ActivityCompat.requestPermissions(this, new
String[]{Manifest.permission.ACCESS_FINE_LOCATION}, REQUEST_CODE);

4. Getting User Location Using


FusedLocationProviderClient
Google’s FusedLocationProviderClient provides the best way to get location
efficiently.

Steps to Get Location:


Initialize FusedLocationProviderClient​
java​
CopyEdit​
FusedLocationProviderClient fusedLocationClient =
LocationServices.getFusedLocationProviderClient(this);

1.​

Request Location Updates​


java​
CopyEdit​
fusedLocationClient.getLastLocation()
.addOnSuccessListener(this, location -> {
if (location != null) {
double latitude = location.getLatitude();
double longitude = location.getLongitude();
Log.d("Location", "Lat: " + latitude + ", Long: " +
longitude);
}
});

2.​
3.​ Handling Permissions at Runtime​
Ensure ACCESS_FINE_LOCATION permission is granted before requesting location.

5. Requesting Continuous Location Updates


For tracking location continuously, use LocationRequest with
FusedLocationProviderClient.

java
CopyEdit
LocationRequest locationRequest = LocationRequest.create();
locationRequest.setInterval(10000); // 10 seconds
locationRequest.setFastestInterval(5000);
locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);

LocationCallback locationCallback = new LocationCallback() {


@Override
public void onLocationResult(LocationResult locationResult) {
if (locationResult == null) return;
for (Location location : locationResult.getLocations()) {
Log.d("Location Update", "Lat: " +
location.getLatitude() + ", Long: " + location.getLongitude());
}
}
};

// Start location updates


fusedLocationClient.requestLocationUpdates(locationRequest,
locationCallback, Looper.getMainLooper());

To stop updates when no longer needed:

java
CopyEdit
fusedLocationClient.removeLocationUpdates(locationCallback);

6. Geocoding and Reverse Geocoding


To convert coordinates to address:

java
CopyEdit
Geocoder geocoder = new Geocoder(this, Locale.getDefault());
List<Address> addresses = geocoder.getFromLocation(latitude,
longitude, 1);
String address = addresses.get(0).getAddressLine(0);

To convert address to coordinates:

java
CopyEdit
List<Address> addresses = geocoder.getFromLocationName("New York,
USA", 1);
double lat = addresses.get(0).getLatitude();
double lng = addresses.get(0).getLongitude();

7. Handling Location in Foreground and Background


●​ Foreground Location Tracking: Works when the app is open.
●​ Background Location Tracking: Requires ACCESS_BACKGROUND_LOCATION
permission in Android 10+ and foreground service in Android 11+.

Example for foreground service in Android 11+:

xml
CopyEdit
<service android:name=".LocationService"
android:foregroundServiceType="location"/>

Use WorkManager or Foreground Services for background updates.

8. Google Maps Integration


To show location on Google Maps:

Add Maps SDK Dependency (build.gradle)​


gradle​
CopyEdit​
implementation 'com.google.android.gms:play-services-maps:18.1.0'

1.​

Add Google Maps API Key in AndroidManifest.xml​


xml​
CopyEdit​
<meta-data
android:name="com.google.android.geo.API_KEY"
android:value="YOUR_API_KEY"/>

2.​

Load Google Map in Activity​


java​
CopyEdit​
SupportMapFragment mapFragment = (SupportMapFragment)
getSupportFragmentManager().findFragmentById(R.id.map);
mapFragment.getMapAsync(googleMap -> {
LatLng location = new LatLng(latitude, longitude);
googleMap.addMarker(new
MarkerOptions().position(location).title("My Location"));
googleMap.moveCamera(CameraUpdateFactory.newLatLngZoom(location,
15));
});

3.​

9. Security and Privacy Considerations


●​ Request location only when necessary.
●​ Inform users why location access is needed.
●​ Use ACCESS_COARSE_LOCATION instead of ACCESS_FINE_LOCATION when high
accuracy is not required.
●​ Respect Android’s background location restrictions.

10. Conclusion
Android Location-Based Services provide essential features for location tracking, geocoding,
and mapping. With FusedLocationProviderClient, developers can efficiently obtain
user locations while balancing accuracy and battery efficiency.

Would you like a full working example for a project? 🚀


Notes on Android Security Model

The Android security model is designed to protect user data, maintain system integrity, and
ensure app isolation. It incorporates multiple security mechanisms to defend against
malicious attacks and unauthorized access.

1. Key Security Principles


●​ Sandboxing: Each app runs in its own process and is assigned a unique user ID
(UID), preventing access to other apps' data.
●​ Least Privilege: Apps get only the permissions they request and need to function.
●​ User-Given Permissions: Users must grant explicit permissions for sensitive actions
(e.g., accessing location, camera, microphone).
●​ Verified Boot: Ensures the device boots only from a trusted OS image.

2. Security Features
Application Sandbox

●​ Each app runs in an isolated environment using the Linux kernel and its process
isolation features.
●​ Data is protected within an app’s private storage unless explicitly shared.

Permissions Model

●​ Install-time permissions: Apps declare permissions in AndroidManifest.xml.


●​ Runtime permissions: Apps must request user approval for sensitive actions (e.g.,
contacts, SMS, storage).

Secure Interprocess Communication (IPC)

●​ Apps communicate using Binder, a lightweight, secure IPC mechanism.


●​ Intents and Content Providers allow controlled data sharing between apps.

Encryption & Data Protection

●​ File-based encryption (FBE): Encrypts files separately for better security and
multi-user support.
●​ Keystore System: Securely stores cryptographic keys and performs operations in
hardware-backed storage.

SELinux (Security-Enhanced Linux)


●​ Enforces Mandatory Access Control (MAC) to prevent unauthorized access to
system resources.

Google Play Protect

●​ Scans apps for malware before and after installation.


●​ Detects harmful behavior and warns users.

Verified Boot & Trusted Execution Environment (TEE)

●​ Ensures system integrity by checking each stage of the boot process.


●​ Stores sensitive operations (fingerprint, payment data) in a secure, isolated
environment.

3. Security Updates & Patch Management


●​ Monthly security patches: Google releases regular updates to fix vulnerabilities.
●​ Project Treble: Improves update delivery speed by separating vendor code from the
OS framework.
●​ Android Enterprise Security: Additional security layers for enterprise use, including
work profiles and device management tools.

4. Common Security Threats & Mitigations


Threat Mitigation

Malware & Trojans Google Play Protect, app


sandboxing

Data leaks Permission model, encryption

Root exploits Verified Boot, SELinux

Phishing attacks Safe Browsing API, user awareness

Man-in-the-middle (MITM) attacks Enforced TLS encryption

5. Best Practices for Secure App Development


●​ Use secure communication (HTTPS/TLS for network requests).
●​ Minimize permissions (request only necessary permissions).
●​ Avoid storing sensitive data on the device when possible.
●​ Use Android Keystore to manage cryptographic keys securely.
●​ Keep dependencies and libraries updated to patch vulnerabilities.

Conclusion

Android’s security model integrates multiple layers of protection, from app sandboxing to
verified boot and encryption. Regular updates and Google Play Protect help mitigate
evolving threats, making Android devices more secure while balancing usability.

Declaring and Using Permissions in Android


Android permissions control what an app can access, such as location, camera, contacts,
etc. Permissions are categorized into normal and dangerous permissions, where
dangerous permissions require runtime approval from the user.

1. Declaring Permissions in AndroidManifest.xml


Before an app can use certain features, it must declare permissions in the manifest file.

Example: Requesting Internet and Location Permissions


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

<!-- Normal permission (granted automatically) -->


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

<!-- Dangerous permission (requires user approval) -->


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

</manifest>
●​ Normal Permissions (e.g., INTERNET) are granted automatically.
●​ Dangerous Permissions (e.g., ACCESS_FINE_LOCATION) require runtime
approval from the user.

2. Requesting Dangerous Permissions at Runtime


For dangerous permissions, you must ask the user for approval at runtime (Android 6.0+).

Steps to Request a Permission

1.​ Check if the permission is granted.


2.​ Request permission if not granted.
3.​ Handle the user’s response.

Example: Requesting Location Permission (Kotlin)


kotlin
CopyEdit
val LOCATION_PERMISSION = Manifest.permission.ACCESS_FINE_LOCATION

if (ContextCompat.checkSelfPermission(this, LOCATION_PERMISSION)
!= PackageManager.PERMISSION_GRANTED) {

// Request permission
ActivityCompat.requestPermissions(this,
arrayOf(LOCATION_PERMISSION), 100)
}

Handling the User’s Response


kotlin
CopyEdit
override fun onRequestPermissionsResult(requestCode: Int,
permissions: Array<out String>, grantResults: IntArray) {
super.onRequestPermissionsResult(requestCode, permissions,
grantResults)

if (requestCode == 100) {
if (grantResults.isNotEmpty() && grantResults[0] ==
PackageManager.PERMISSION_GRANTED) {
Toast.makeText(this, "Permission Granted",
Toast.LENGTH_SHORT).show()
} else {
Toast.makeText(this, "Permission Denied",
Toast.LENGTH_SHORT).show()
}
}
}

3. Using Custom Permissions


Custom permissions allow apps to define their own security rules for accessing specific
features.

Declaring a Custom Permission

In the AndroidManifest.xml:

xml
CopyEdit
<permission
android:name="com.example.myapp.MY_CUSTOM_PERMISSION"
android:protectionLevel="normal" />

●​ protectionLevel="normal" → Automatically granted.


●​ protectionLevel="dangerous" → Requires user approval.

Applying a Custom Permission

In the app requiring the permission:

xml
CopyEdit
<uses-permission
android:name="com.example.myapp.MY_CUSTOM_PERMISSION" />

Restricting Access to Components (Example: Custom Permission for an


Activity)
xml
CopyEdit
<activity android:name=".SecureActivity"
android:permission="com.example.myapp.MY_CUSTOM_PERMISSION">
</activity>
●​ Only apps with the specified permission can start SecureActivity.

4. Protection Levels for Custom Permissions


Protection Level Description

normal Automatically granted.

dangerous Requires user approval (like camera, contacts).

signature Only granted if apps are signed with the same


certificate.

signatureOrSy Granted to system apps or signed apps.


stem

Summary
●​ Declare permissions in AndroidManifest.xml before using features.
●​ Request dangerous permissions at runtime using requestPermissions().
●​ Use custom permissions to control access to app components.
●​ Set protection levels to define how permissions are granted.
Notes on Application Deployment in Android
Android application deployment involves packaging, signing, testing, and distributing the app
via different channels like the Google Play Store or direct APK distribution.

1. Application Build Process


Stages of App Deployment:

1.​ Development: Writing code in Java/Kotlin using Android Studio.


2.​ Compilation: Converting source code into DEX (Dalvik Executable) format.
3.​ Packaging (APK/AAB): Bundling the app with resources, manifest, and compiled
code.
4.​ Code Signing: Securing the app with a digital signature.
5.​ Distribution: Publishing the app via Google Play Store or other channels.

2. Generating APK/AAB for Deployment


APK (Android Package) vs. AAB (Android App Bundle)
Format Description Usage

APK Standard Android package Used for direct installation, sideloading.


file.

AAB Optimized app format that Recommended for Play Store (Google Play
reduces size. generates APKs from AAB).

Generating a Signed APK/AAB in Android Studio:

1.​ Open Android Studio → Click on Build → Select Generate Signed Bundle / APK.
2.​ Choose Android App Bundle (AAB) or APK.
3.​ Create or select an existing Keystore file (used for signing).
4.​ Set the Key Alias, Password, and Validity.
5.​ Click Finish to generate the file.

3. Signing the Application


Why Signing is Required?
●​ Android requires all apps to be digitally signed for security.
●​ Prevents unauthorized modifications and verifies authenticity.

Types of Signing

1.​ Debug Signing (For development & testing)


2.​ Release Signing (For production & publishing)

Creating a Keystore for Signing

Use keytool command:

sh
CopyEdit
keytool -genkey -v -keystore my-release-key.jks -keyalg RSA -keysize
2048 -validity 10000 -alias my-key-alias

●​ my-release-key.jks: Keystore file


●​ my-key-alias: Alias for the key

Signing with Keystore in Android Studio

1.​ Build → Generate Signed APK / AAB


2.​ Select your Keystore and enter credentials
3.​ Choose V1 (Jar Signing) and V2 (Full APK Signing)

4. Publishing the App on Google Play Store


Steps for Publishing:

1.​ Create a Google Play Developer Account ($25 one-time fee).


2.​ Upload App to Play Console (Submit AAB/APK).
3.​ Provide App Details (Name, description, screenshots, category, contact details).
4.​ Set Pricing & Distribution (Free/Paid, countries, age rating).
5.​ Review & Submit for Approval (Google Play will review for policy compliance).

5. Alternative Distribution Methods


1. Direct APK Distribution (Sideloading)

●​ Share APK via website, email, or third-party app stores.


●​ Users must enable "Install Unknown Apps" in settings.

2. Enterprise Deployment (MDM Solutions)

●​ Managed deployment using Mobile Device Management (MDM) tools.


●​ Used for corporate apps in organizations.

3. Third-Party App Stores

●​ Amazon Appstore, Samsung Galaxy Store, Huawei AppGallery.


●​ Requires compliance with respective store policies.

6. Post-Deployment Updates & Maintenance


●​ Versioning: Use versionCode & versionName in build.gradle.
●​ Crash Reporting: Integrate Firebase Crashlytics for bug tracking.
●​ Security Updates: Regularly update dependencies & libraries.
●​ A/B Testing: Use Firebase Remote Config for feature rollout.

7. Best Practices for Deployment


✅ Use AAB instead of APK for Play Store.​
✅ Sign the app with a secure Keystore.​
✅ Test thoroughly before deployment (Firebase Test Lab).​
✅ Optimize app size using ProGuard & R8.​
✅ Follow Google Play Store policies to avoid rejection.

Conclusion

Deploying an Android app involves building, signing, testing, and distributing via the Play
Store or alternative methods. Google Play ensures security, updates, and user engagement,
making it the preferred distribution channel.
Android Developer Console (Google Play
Console)
The Google Play Console (also called the Developer Console) is an online platform for
Android developers to manage and publish apps on the Google Play Store. It provides tools
for app distribution, performance monitoring, monetization, and user analytics.

1. Accessing the Google Play Console


🔗 URL: https://play.google.com/console
Requirements to Use the Console:

✔ A Google account​
✔ A Google Play Developer Account ($25 one-time fee)​
✔ Keystore for signing apps

2. Key Features of the Google Play Console


1. App Management & Publishing

●​ Upload and manage APK/AAB files


●​ Track app release status
●​ Beta testing and staged rollouts

2. User and Performance Analytics

●​ Google Play Statistics: Monitor installs, uninstalls, and user engagement.


●​ Android Vitals: Detect crashes, ANRs (App Not Responding), and performance
issues.

3. Monetization & Ads

●​ In-app purchases (IAPs) and subscriptions


●​ Google AdMob integration for ad revenue tracking
●​ Pricing and distribution control

4. App Ratings & Reviews Management

●​ Monitor user feedback and respond to reviews


●​ Analyze app ratings and trends
5. Security & Policy Compliance

●​ Pre-launch reports: Automated testing for security and crashes


●​ Policy compliance checks to avoid rejection

3. Steps to Publish an App on Google Play Console


Step 1: Create a Developer Account

1.​ Visit Google Play Console.


2.​ Pay the $25 registration fee.
3.​ Complete your developer profile.

Step 2: Create a New App

1.​ Click "Create App" → Enter App Name and Default Language.
2.​ Select App Type (App/Game) and Pricing Model (Free/Paid).
3.​ Agree to Google Play policies.

Step 3: Upload Your App (AAB/APK)

1.​ Go to App Releases → Production.


2.​ Click Upload and select the signed AAB/APK file.
3.​ Enter release notes and rollout percentage (for staged rollout).

Step 4: Enter App Details

●​ Short & Full Description


●​ Screenshots, App Icon, and Feature Graphics
●​ Category & Content Rating
●​ Contact Email & Website

Step 5: Set Pricing & Distribution

●​ Choose Free or Paid (Paid apps require a linked payment account).


●​ Select Available Countries.

Step 6: Submit for Review

🎉
●​ Click "Publish" → Google will review the app (takes a few hours to a few days).
●​ If approved, your app will be live on the Play Store!
4. Post-Launch Monitoring & Updates
1. Track App Performance

●​ Monitor installs, crashes, ANRs, and revenue in the Play Console dashboard.
●​ Use Firebase Crashlytics for advanced debugging.

2. Reply to User Reviews

●​ Engage with users to improve ratings and feedback.


●​ Use Google Play Review API to request in-app ratings.

3. Roll Out Updates & New Features

●​ Publish app updates with version control.


●​ Use staged rollouts to test updates before a full launch.

5. Best Practices for Using Google Play Console


✅ Use AAB format for smaller app size and faster downloads.​
✅ Regularly check Android Vitals to fix performance issues.​
✅ Follow Google Play policies to avoid app suspension.​
✅ Use Google Play Console Insights for better user engagement.​
✅ Localize your app for global reach.

Conclusion

The Google Play Console is an essential tool for Android developers to publish, manage,
and analyze app performance. It ensures secure app distribution and helps improve user
engagement.

You might also like