Pro Android with Kotlin
Download 5.42 Mb. Pdf ko'rish
|
@de android telegram Pro Android with Kotlin Developing Modern Mobile
55
CHAPTER 5: Broadcasts ACTION_NEW_OUTGOING_CALL: This intercepts outgoing calls. ACTION_DEVICE_OWNER_CHANGED: Some apps might need to receive this so that they know the device’s security status has changed. ACTION_EVENT_REMINDER: This is sent by the calendar provider to post an event reminder to the calendar app. ACTION_MEDIA_MOUNTED, ACTION_MEDIA_CHECKING, ACTION_MEDIA_UNMOUNTED, ACTION_MEDIA_EJECT, ACTION_MEDIA_UNMOUNTABLE,ACTION_MEDIA_REMOVED, ACTION_MEDIA_BAD_ REMOVAL: Apps might need to know about the user’s physical interactions with the device. SMS_RECEIVED_ACTION, WAP_PUSH_RECEIVED_ACTION: These are needed by SMS recipient apps. Adding Security to Broadcasts Security in broadcasting messages is handled by the permission system, which gets handled in more detail in Chapter 7 . In the following sections, we distinguish between explicit and implicit broadcasts. Securing Explicit Broadcasts For nonlocal broadcasting (i.e., not using the LocalBroadcastManager), permissions can be specified on both sides, the receiver and the sender. For the latter, the broadcast-sending methods have overloaded versions, including a permission specifier: ... val intent = Intent(this, MyReceiver::class.java) ... sendBroadcast(intent, "com.xyz.theapp.PERMISSION1") ... This expresses sending a broadcast to a receiver that is protected by com.xyz.theapp. PERMISSION1. Of course, you should write your own package names here and use appropriate permission names. 56 CHAPTER 5: Broadcasts Instead, sending a broadcast without a permission specification may address receivers with and without permission protection: ... val intent = Intent(this, MyReceiver::class.java) ... sendBroadcast(intent) ... This means that specifying permissions on the sender side is not supposed to tell the receiver that the sender is protected in any way. For adding permissions to the receiver side, we first need to declare using it inside AndroidManifest.xml on an app level. ... Here, MyReceiver is an implementation of android.content.BroadcastReceiver. Third, since this is a custom permission, you have to declare itself in the manifest file. "com.xyz.theapp.PERMISSION1"/> ... The allows for a couple of more attributes; see the section “Manifest Top Level Entries” in the online text companion to learn more about the protection level. The details for and implications of it are explained thoroughly in Chapter 7 . For noncustom permissions, you don’t need to use the element. Caution Specifying a permission on the sender side without having a matching permission on the receiver side silently fails when you try to send a broadcast. There are also no logging entries, so be careful with sender-side permissions. |
Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling
ma'muriyatiga murojaat qiling