Recent

Author Topic: android.permission.READ_PHONE_STATE does not work  (Read 332 times)

RDL

  • New member
  • *
  • Posts: 37
android.permission.READ_PHONE_STATE does not work
« on: February 12, 2019, 01:03:26 pm »
hi.
I don’t understand why it doesn’t work for me android.permission.READ_PHONE_STATE

Code: Pascal  [Select]
  1. procedure TfrmMain.frmMainJNIPrompt(Sender: TObject);
  2. var
  3.   manifestPermissions: TDynArrayOfString;
  4. begin
  5. if IsRuntimePermissionNeed() then   // that is, if target API >= 23
  6.    begin
  7.      ShowMessage('RequestRuntimePermission....');
  8.      ////https://developer.android.com/guide/topics/security/permissions#normal-dangerous
  9.      SetLength(manifestPermissions, 1);
  10.      manifestPermissions[1]:= 'android.permission.READ_PHONE_STATE';      //from AndroodManifest.xml
  11.      Self.RequestRuntimePermission(manifestPermissions, 1212);   //handled by OnRequestPermissionResult
  12.      SetLength(manifestPermissions, 1);
  13.    end;
  14. end;
  15.  
  16. procedure TfrmMain.frmMainRequestPermissionResult(Sender: TObject;
  17.   requestCode: integer; manifestPermission: string;
  18.   grantResult: TManifestPermissionResult);
  19. begin
  20. case requestCode of
  21.     1212:begin
  22.            if grantResult = PERMISSION_GRANTED  then
  23.            begin
  24.               //ShowMessage('Success! ['+manifestPermission+'] Permission granted!!! ' );
  25.  
  26.               if manifestPermission = 'android.permission.READ_PHONE_STATE' then
  27.                  showmessage('read_call_state_ok');
  28.  
  29.            end
  30.           else//PERMISSION_DENIED
  31.           begin
  32.               ShowMessage('Sorry... ['+manifestPermission+'] permission not granted... ' );
  33.           end;
  34.        end;
  35.   end;
  36. end;
  37.  
  38. procedure TfrmMain.jTelephonyManager1CallStateChanged(Sender: TObject;
  39.   state: TTelephonyCallState; phoneNumber: string);
  40. begin
  41. if state=csIdle then
  42.    showmessage('csIdle');
  43. if state=csRinging then
  44.    showmessage('pause');
  45. if state=csOffHook then
  46.    showmessage('start')
  47. end;  
  48.  

The application is successfully compiled and installed on the phone. But when I receive an incoming call, not one of the TTelephonyCallState events does not work.

Why?
Sorry for my english, google translation!

A.S.

  • Jr. Member
  • **
  • Posts: 73
Re: android.permission.READ_PHONE_STATE does not work
« Reply #1 on: February 12, 2019, 09:57:39 pm »
manifestPermissions[0]

RDL

  • New member
  • *
  • Posts: 37
Re: android.permission.READ_PHONE_STATE does not work
« Reply #2 on: February 13, 2019, 01:51:29 pm »
sorry, this is my mistake.
in my code is 0.
but interception of call status does not work.
Sorry for my english, google translation!

RDL

  • New member
  • *
  • Posts: 37
Re: android.permission.READ_PHONE_STATE does not work
« Reply #3 on: February 22, 2019, 05:41:56 am »
Tell me how to determine the status of the phone? (waiting or incoming call) :-[
Sorry for my english, google translation!