-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #236 from myofficework000/broadcast_receivers
Added two new broadcast receivers
- Loading branch information
Showing
7 changed files
with
87 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
..._all_in_one/application_components/broadcastreceiver/batterybroadcast/BatteryBroadcast.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.example.jetpack_compose_all_in_one.application_components.broadcastreceiver.batterybroadcast | ||
|
||
import android.content.BroadcastReceiver | ||
import android.content.Context | ||
import android.content.Intent | ||
import android.os.BatteryManager | ||
import android.util.Log | ||
|
||
class BatteryBroadcast: BroadcastReceiver() { | ||
override fun onReceive(context: Context?, intent: Intent?) { | ||
val level = intent?.getIntExtra(BatteryManager.EXTRA_LEVEL, -1) ?: 1 | ||
val scale = intent?.getIntExtra(BatteryManager.EXTRA_SCALE, -1) ?: 1 | ||
val batteryPercentage = level * 100 / scale.toFloat() | ||
|
||
Log.i("Battery Broadcast", "Your battery is at: $batteryPercentage %") | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...k_compose_all_in_one/application_components/broadcastreceiver/smsrecevier/SmsBroadcast.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package com.example.jetpack_compose_all_in_one.application_components.broadcastreceiver.smsrecevier | ||
|
||
import android.content.BroadcastReceiver | ||
import android.content.Context | ||
import android.content.Intent | ||
import android.provider.Telephony | ||
import android.util.Log | ||
|
||
class SmsBroadcast: BroadcastReceiver() { | ||
override fun onReceive(context: Context?, intent: Intent?) { | ||
if (intent?.action == Telephony.Sms.Intents.SMS_RECEIVED_ACTION) { | ||
Log.i("SMS Broadcast","You have received a SMS message") | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters