Chapter 6 Mad
Chapter 6 Mad
1.
Send SMS:
java
CopyEdit
smsManager.sendTextMessage(phoneNumber, null, message, null, null);
2.
3. Permissions Required:
○
1.
2.
Permissions Required:
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
java
CopyEdit
Intent smsIntent = new Intent(Intent.ACTION_VIEW);
smsIntent.setData(Uri.parse("sms:" + phoneNumber));
smsIntent.putExtra("sms_body", "Hello!");
startActivity(smsIntent);
java
CopyEdit
Intent intent = new
Intent(Telephony.Sms.Intents.ACTION_CHANGE_DEFAULT);
intent.putExtra(Telephony.Sms.Intents.EXTRA_PACKAGE_NAME,
getPackageName());
startActivity(intent);
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.
xml
CopyEdit
<uses-permission
android:name="android.permission.ACCESS_BACKGROUND_LOCATION"/>
java
CopyEdit
ActivityCompat.requestPermissions(this, new
String[]{Manifest.permission.ACCESS_FINE_LOCATION}, REQUEST_CODE);
1.
2.
3. Handling Permissions at Runtime
Ensure ACCESS_FINE_LOCATION permission is granted before requesting location.
java
CopyEdit
LocationRequest locationRequest = LocationRequest.create();
locationRequest.setInterval(10000); // 10 seconds
locationRequest.setFastestInterval(5000);
locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
java
CopyEdit
fusedLocationClient.removeLocationUpdates(locationCallback);
java
CopyEdit
Geocoder geocoder = new Geocoder(this, Locale.getDefault());
List<Address> addresses = geocoder.getFromLocation(latitude,
longitude, 1);
String address = addresses.get(0).getAddressLine(0);
java
CopyEdit
List<Address> addresses = geocoder.getFromLocationName("New York,
USA", 1);
double lat = addresses.get(0).getLatitude();
double lng = addresses.get(0).getLongitude();
xml
CopyEdit
<service android:name=".LocationService"
android:foregroundServiceType="location"/>
1.
2.
3.
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.
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.
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
● 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.
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.
</manifest>
● Normal Permissions (e.g., INTERNET) are granted automatically.
● Dangerous Permissions (e.g., ACCESS_FINE_LOCATION) require runtime
approval from the user.
if (ContextCompat.checkSelfPermission(this, LOCATION_PERMISSION)
!= PackageManager.PERMISSION_GRANTED) {
// Request permission
ActivityCompat.requestPermissions(this,
arrayOf(LOCATION_PERMISSION), 100)
}
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()
}
}
}
In the AndroidManifest.xml:
xml
CopyEdit
<permission
android:name="com.example.myapp.MY_CUSTOM_PERMISSION"
android:protectionLevel="normal" />
xml
CopyEdit
<uses-permission
android:name="com.example.myapp.MY_CUSTOM_PERMISSION" />
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.
AAB Optimized app format that Recommended for Play Store (Google Play
reduces size. generates APKs from AAB).
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.
Types of Signing
sh
CopyEdit
keytool -genkey -v -keystore my-release-key.jks -keyalg RSA -keysize
2048 -validity 10000 -alias my-key-alias
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.
✔ A Google account
✔ A Google Play Developer Account ($25 one-time fee)
✔ Keystore for signing apps
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.
🎉
● 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.
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.