title: How to invoke native camera in Delphi Android application?
body: <p>I'm using Delphi 10.3 Community Edition to write a simple Android app and trying to invoke native device camera, but getting an error instead.</p>
  
  <p>I'm following the official Delphi <a href="http://docwiki.embarcadero.com/RADStudio/XE5/en/Mobile_Tutorial:_Taking_and_Sharing_a_Picture_(iOS_and_Android)" rel="nofollow noreferrer">guide</a>:</p>
  
  <blockquote>
    <p>On the Form Designer, select the button (for taking a photo).
    In the Object Inspector, select the drop-down list for the Action property.
    Select New Standard Action | Media Library | TTakePhotoFromCameraAction:</p>
    
    <p>On the Events tab, expand the Action node, and then double-click the OnDidFinishTaking event.</p>
    
    <p>Add the following code to the OnDidFinishTaking event handler:</p>
  
  <pre><code>procedure TForm1.TakePhotoFromCameraAction1DidFinishTaking(Image: TBitmap);
  begin
    Image1.Bitmap.Assign(Image);
  end;
  </code></pre>
    
    <p>This code assigns a picture taken from the mobile device camera to the Bitmap property of the TImage component.</p>
  </blockquote>
  
  <p>I have verified that Project | Options | Uses Permissions - Camera setting is set to <code>true</code>. I'm requesting required permission on the app start as well. There's no difference between running in Debug or Release.</p>
  
  <p>However there is a problem. When clicking the button I get the following error message:</p>
  
  <blockquote>
    <p>java.lang.NullPointerException: Attempt to invoke virtual method 'android.content.res.XmlResourceParser android.content.pm.PackageItemInfo.loadXmlMetaData(android.content.pm.PackageManager, java.lang.String)' on a null object reference.</p>
  </blockquote>
  
  <p>Here's the code I've written for the simplest test app:</p>
  
  <pre><code>unit Unit1;
  interface
  uses
    System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
    FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, System.Permissions,
    FMX.StdCtrls, FMX.MediaLibrary, FMX.Platform, System.Messaging, FMX.Objects,
    System.Actions, FMX.ActnList, FMX.StdActns, FMX.MediaLibrary.Actions,
    FMX.Controls.Presentation;
  
  type
    TForm1 = class(TForm)
      Button1: TButton;
      ActionList1: TActionList;
      TakePhotoFromCameraAction1: TTakePhotoFromCameraAction;
      procedure FormCreate(Sender: TObject);
    private
      procedure PermissionRequestResult(Sender: TObject; const APermissions: TArray&lt;string&gt;; const AGrantResults: TArray&lt;TPermissionStatus&gt;);
      procedure DisplayRationale(Sender: TObject; const APermissions: TArray&lt;string&gt;; const APostRationaleProc: TProc);
    end;
  
  var
    Form1: TForm1;
  
  implementation
  uses
  {$IFDEF ANDROID}
    Androidapi.Helpers,
    Androidapi.JNI.JavaTypes,
    Androidapi.JNI.Os,
  {$ENDIF}
    FMX.DialogService;
  
  {$R *.fmx}
  
  procedure TForm1.PermissionRequestResult(Sender: TObject; const APermissions: TArray&lt;string&gt;; const AGrantResults: TArray&lt;TPermissionStatus&gt;);
  begin
    // 3 permission involved
    if (Length(AGrantResults) = 3)
    and (AGrantResults[0] = TPermissionStatus.Granted)
    and (AGrantResults[1] = TPermissionStatus.Granted)
    and (AGrantResults[2] = TPermissionStatus.Granted) then
    else
      ShowMessage('Required permission has not been granted') ;
  end;
  
  procedure TForm1.DisplayRationale(Sender: TObject; const APermissions: TArray&lt;string&gt;; const APostRationaleProc: TProc);
  begin
    TDialogService.ShowMessage('Need to access the camera',
      procedure(const AResult: TModalResult)
      begin
        APostRationaleProc;
      end);
  end;
  
  procedure TForm1.FormCreate(Sender: TObject);
  var
    permCam, permRead, permWrite: string;
  begin
    // Request permissions
    permCam := JStringToString(TJManifest_permission.JavaClass.CAMERA);
    permRead := JStringToString(TJManifest_permission.JavaClass.READ_EXTERNAL_STORAGE);
    permWrite := JStringToString(TJManifest_permission.JavaClass.WRITE_EXTERNAL_STORAGE);
    PermissionsService.RequestPermissions([permCam, permRead, permWrite], PermissionRequestResult, DisplayRationale);
  end;
  
  end.
  </code></pre>
  
  <p>How to make the native camera TTakePhotoFromCameraAction to work?</p>