Permissions, Performance & Security in Android
Permissions, Performance & Security in Android
Permissions in Android
Permissions are used to protect user data and system features.
Types of Permissions
| Type | Description | Example |
|---|---|---|
| Normal | Low risk | Internet |
| Dangerous | Needs user approval | Camera, Location |
| Signature | Same app signature | System apps |
Declare Permission
<uses-permission android:name="android.permission.INTERNET"/>
Runtime Permission (Android 6+)
if (ContextCompat.checkSelfPermission(this, Manifest.permission.CAMERA)
!= PackageManager.PERMISSION_GRANTED) {
ActivityCompat.requestPermissions(this,
new String[]{Manifest.permission.CAMERA}, 1);
}
Permission Flow
Request → User Prompt → Allow / Deny → App Action
Firebase
Backend-as-a-Service platform.
Services
| Service | Use |
|---|---|
| Authentication | Login system |
| Firestore | NoSQL DB |
| Realtime DB | Live data |
| Cloud Messaging | Notifications |
| Analytics | App tracking |
Firebase Architecture
App → Firebase SDK → Cloud Services → Database/Analytics
AdMob (Google Ads)
Used to monetize apps by showing ads.
Ad Types
| Type | Description |
|---|---|
| Banner | Small ads |
| Interstitial | Full screen |
| Rewarded | User earns reward |
Example
AdView adView = findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder().build();
adView.loadAd(adRequest);
APK Signing
Process of digitally signing APK before release.
Why Needed?
- Ensures app authenticity
- Required for Play Store
Signing Types
| Type | Use |
|---|---|
| Debug | Testing |
| Release | Production |
Signing Process
Code → Build APK → Sign with Key → Release APK
Packaging & Deployment
Steps
- Build APK / AAB
- Optimize app
- Test
- Deploy
Deployment Flow
Code → Build → Test → Upload → Publish
Publish App (Play Store)
Steps
- Create account on Google Play Console
- Upload APK/AAB
- Add app details
- Set pricing
- Publish
Requirements
- Signed APK
- Privacy policy
- Screenshots
Google Maps
Used to display maps in apps.
Features
- Markers
- Location tracking
- Navigation
Example
GoogleMap map;
map.addMarker(new MarkerOptions().position(new LatLng(28.6, 77.2)));
GPS & Wi-Fi Positioning
Location Sources
| Source | Accuracy | Use |
|---|---|---|
| GPS | High | Outdoor |
| Wi-Fi | Medium | Indoor |
| Mobile Network | Low | General |
Location Flow
GPS/Wi-Fi → Location Manager → App
Location Services
Example
FusedLocationProviderClient client = LocationServices.getFusedLocationProviderClient(this);
Permissions Required
- ACCESS_FINE_LOCATION
- ACCESS_COARSE_LOCATION
Download Manager
Handles long-running downloads.
Features
- Runs in background
- Retry support
Example
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
WorkManager
Used for deferrable background tasks.
Features
- Guaranteed execution
- Works even after restart
WorkManager Flow
WorkRequest → WorkManager → Background Execution
Example
WorkRequest work = new OneTimeWorkRequest.Builder(MyWorker.class).build();
WorkManager.getInstance(this).enqueue(work);
Alarms (AlarmManager)
Schedules tasks at specific time.
Example
AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
Alarm Flow
Set Time → Alarm Trigger → BroadcastReceiver → Action
Sensors in Android
Types
| Sensor | Use |
|---|---|
| Accelerometer | Motion |
| Gyroscope | Rotation |
| Proximity | Distance |
Example
SensorManager sm = (SensorManager) getSystemService(SENSOR_SERVICE);
Performance Optimization
Techniques
- Use background threads
- Optimize layouts
- Reduce memory usage
- Use caching
Performance Tips Table
| Technique | Benefit |
|---|---|
| Lazy loading | Faster UI |
| Caching | Reduce network |
| RecyclerView | Efficient UI |
Security Best Practices
Techniques
- Use HTTPS
- Encrypt data
- Secure APIs
- Use ProGuard
Security Layers
User → App → Encryption → Secure Server
Important Exam Questions
Short Questions
- What is APK signing?
- Define WorkManager.
- What is Firebase?
Long Questions
- Explain permissions in Android.
- Describe Google Maps integration.
- Explain WorkManager vs AlarmManager.
Practical Questions
- Request runtime permission.
- Implement WorkManager.
- Show map with marker.
Final Summary
- Permissions → user security
- Firebase → backend
- AdMob → monetization
- APK Signing → authenticity
- WorkManager → background tasks
- Google Maps → location features
- Sensors → hardware interaction