Pro Android with Kotlin



Yüklə 4,6 Kb.
Pdf görüntüsü
səhifə58/231
tarix29.11.2023
ölçüsü4,6 Kb.
#138831
1   ...   54   55   56   57   58   59   60   61   ...   231
@de android telegram Pro Android with Kotlin Developing Modern Mobile

53
CHAPTER 5: Broadcasts
Receiving Implicit Broadcasts
To receive an implicit broadcast, for a limited set of broadcast types (see the section “The 
System Intent Filters” of the online text companion) you can specify a 
BroadcastListener
inside 
AndroidManifest.xml
as follows:

...


"com.xyz.myapp.DO_STH" />
"android.intent.category.DEFAULT"/>
"com.xyz.myapp.MY_CATEG"/>
android:port="80"
android:host="com.xyz"
android:path="items/7"
android:mimeType="text/html" />



The 

element shown here is just an example; see Chapter 
3
 for all the possibilities.
In contrast to that, adding a programmatic listener for implicit broadcasts to your code is 
unrestricted.
class MainActivity : AppCompatActivity() {
private var bcReceiver:BroadcastReceiver? = null
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
// ...
bcReceiver = MyReceiver()
val ifi:IntentFilter =
IntentFilter("de.pspaeth.myapp.DO_STH")
registerReceiver(bcReceiver, ifi)
}
override fun onDestroy() {
super.onDestroy()
// ...
unregisterReceiver(bcReceiver)
}
}
The 
MyReceiver
is an implementation of class 
android.content.BroadcastReceiver
.


54
CHAPTER 5: Broadcasts
Listening to System Broadcasts
To listen to system broadcasts, see the list in the online text companion’s “System 
Broadcasts” section. You can just use a programmatic registration as shown earlier. For 
most of them, you cannot use the manifest registration method for background execution 
limits imposed since Android 8.0 (API level 26). However, for a number of them, you can also 
use the manifest file to specify listeners.
 
ACTION_LOCKED_BOOT_COMPLETED

ACTION_BOOT_COMPLETED
:
Apps may need those to schedule jobs, alarms, and so on.
 
ACTION_USER_INITIALIZE

"android.intent.action.USER_ADDED"

"android.intent.action.USER_REMOVED"
:
These are protected by privileged permissions, so the use cases are 
limited.
 
"android.intent.action.TIME_SET"

ACTION_TIMEZONE_CHANGED

ACTION_
NEXT_ALARM_CLOCK_CHANGED
:
These are needed by clock apps.
 
ACTION_LOCALE_CHANGED
:
The locale changed, and apps might need to update their data when this 
happens.
 
ACTION_USB_ACCESSORY_ATTACHED

ACTION_USB_ACCESSORY_DETACHED

ACTION_USB_DEVICE_ATTACHED
,
ACTION_USB_DEVICE_DETACHED
:
These are USB-related events.
 
ACTION_CONNECTION_STATE_CHANGED

ACTION_ACL_ CONNECTED
,
ACTION_ACL_DISCONNECTED
:
These are Bluetooth events.
 
ACTION_CARRIER_CONFIG_CHANGED

Yüklə 4,6 Kb.

Dostları ilə paylaş:
1   ...   54   55   56   57   58   59   60   61   ...   231




Verilənlər bazası müəlliflik hüququ ilə müdafiə olunur ©genderi.org 2024
rəhbərliyinə müraciət

    Ana səhifə