Pro Android with Kotlin


Download 5.42 Mb.
Pdf ko'rish
bet96/223
Sana04.11.2023
Hajmi5.42 Mb.
#1746807
1   ...   92   93   94   95   96   97   98   99   ...   223
Bog'liq
@de android telegram Pro Android with Kotlin Developing Modern Mobile

106
CHAPTER 7: Permissions
The question is, how would we know which permissions exactly we need for our app? The 
answer has three parts.

Android Studio tells you about a permission your app needs. If you, 
for example, write the following, Android Studio tells you a certain 
permission is required (Figure 
7-1
):
val uri = CallLog.Calls.CONTENT_URI
val cursor = contentResolver.query(
uri, null, null, null, null)

During development and testing, your app crashes and in the logs you 
see an entry like this:
Caused by: java.lang.SecurityException: Permission
Denial: opening provider
com.android.providers.contacts.CallLogProvider
from
ProcessRecord{faeda9c 4127:de.pspaeth.cp1/u0a96}
(pid=4127, uid=10096) requires
android.permission.READ_CALL_LOG or
android.permission.WRITE_CALL_LOG

The list of system permissions tells you that you need a certain 
permission for a certain task. See Table 
7-1
.
Figure 7-1. Android Studio telling you about a permission requirement
Once the usage of the permission is declared in the top-level element 
it still must be connected to the app’s components. This happens either inside the 
 element if you want to connect the permission to all components at once 
or, better, on a per-component base. In either case you declare the permission inside the 
permission attribute, as follows:
...
"com.example.myapp.ExampleActivity"
android:permission=
"com.eample.myapp.abcPermission"/>
...


107
CHAPTER 7: Permissions
Table 7-1. System Permissions
Permission
Group
Description
READ_CALENDAR
CALENDAR
Allows for reading the calendar. Manifest entry:
android.permission.READ_CALENDAR
WRITE_CALENDAR
CALENDAR
Allows for writing the calendar. Manifest entry:
android.permission.READ_CALENDAR
CAMERA
CAMERA
Allows for accessing the camera. Manifest entry:
android.permission.CAMERA
READ_CONTACTS
CONTACTS
Read from the contacts table. Manifest entry:
android.permission.READ_CONTACTS
WRITE_CONTACTS
CONTACTS
Write into the contacts table. Manifest entry:
android.permission.WRITE_CONTACTS
GET_ACCOUNTS
CONTACTS
Allows for listing accounts from the Accounts Service. 
Manifest entry:
android.permission.GET_ACCOUNTS
ACCESS_FINE_LOCATION
LOCATION
Allows an app to access fine-grained location. Manifest 
entry:
android.permission.ACCESS_FINE_LOCATION
ACCESS_COARSE_LOCATION
LOCATION
Allows an app to access approximate location. Manifest 
entry:
android.permission.ACCESS_COARSE_LOCATION
RECORD_AUDIO
MICROPHONE
Allows for recording audio. Manifest entry:
android.permission.RECORD_AUDIO
READ_PHONE_STATE
PHONE
Allows read access to phone state (phone number of the 
device, current cellular network information, the status 
of any ongoing calls, and a list of any PhoneAccounts 
registered on the device). Manifest entry:
android.permission.READ_PHONE_STATE
READ_PHONE_NUMBERS
PHONE
Read access to the device’s phone number. Manifest 
entry:
android.permission.READ_PHONE_NUMBERS
CALL_PHONE
PHONE
Allows an application to initiate a phone call without 
going through the dialer user interface. Manifest entry:
android.permission.CALL_PONE
ANSWER_PHONE_CALLS
PHONE
Allows an application to answer an incoming phone call. 
Manifest entry:
android.permission.ANSWER_PHONE_CALLS
(continued)



Download 5.42 Mb.

Do'stlaringiz bilan baham:
1   ...   92   93   94   95   96   97   98   99   ...   223




Ma'lumotlar bazasi mualliflik huquqi bilan himoyalangan ©fayllar.org 2024
ma'muriyatiga murojaat qiling