FMX.AddressBook.TCustomAddressBook.RequestPermission
Delphi
procedure RequestPermission(ADisplayRationaleEvent: TDisplayRationaleEvent = nil); overload;
C++
void __fastcall RequestPermission(System::Permissions::TDisplayRationaleEvent ADisplayRationaleEvent = 0x0)/* overload */;
Properties
Type | Visibility | Source | Unit | Parent |
---|---|---|---|---|
procedure function |
public | FMX.AddressBook.pas FMX.AddressBook.hpp |
FMX.AddressBook | TCustomAddressBook |
Description
RequestPermission sends a request to access a device Address Book. To process the system response, use the OnPermissionRequest event handler.
Remember to use RequestPermission method before accessing any functionality of a device Address Book. Otherwise, your application cannot work with a device Address Book and might fail. For example, you can call the RequestPermission method in the TForm.onShow event handler.
RequestPermission now has a new parameter ADisplayRationaleEvent: TDisplayRationaleEvent
that is a callback for explaining to the user why permission is needed.
APostRationalProc
routine, which will then request the required permissions.Examples
To clarify, consider the following examples. These code snippets illustrate how to implement the OnShow and OnPermissionRequest event handlers request permission to access a device Address Book.
Delphi:
procedure TForm1.FormShow(Sender: TObject);
begin
AddressBook1.RequestPermission;
end;
procedure TForm1.AddressBook1PermissionRequest(ASender: TObject;
const AMessage: string; const AAccessGranted: Boolean);
begin
if AAccessGranted then
begin
// Do something with Address Book
end
else
ShowMessage('You cannot access Address Book. Reason: ' + sLineBreak + AMessage);
end;
C++Builder:
void __fastcall TForm1::FormShow(TObject *Sender) {
AddressBook1->RequestPermission();
}
void __fastcall TForm1::AddressBook1PermissionRequest(TObject *ASender,
const UnicodeString AMessage, const bool AAccessGranted) {
if (AAccessGranted) {
// Do something with Address Book
}
else {
ShowMessage("You cannot access Address Book. Reason: " + sLineBreak + AMessage);
}
}
For more information and samples, see Mobile Tutorial: Using an Address Book Component (iOS and Android).