Lazarus

Programming => Operating Systems => Android => Topic started by: RDL on February 12, 2019, 01:03:26 pm

Title: android.permission.READ_PHONE_STATE does not work
Post by: RDL 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?
Title: Re: android.permission.READ_PHONE_STATE does not work
Post by: A.S. on February 12, 2019, 09:57:39 pm
manifestPermissions[0]
Title: Re: android.permission.READ_PHONE_STATE does not work
Post by: RDL 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.
Title: Re: android.permission.READ_PHONE_STATE does not work
Post by: RDL on February 22, 2019, 05:41:56 am
Tell me how to determine the status of the phone? (waiting or incoming call) :-[
Title: Re: android.permission.READ_PHONE_STATE does not work
Post by: RDL on March 01, 2019, 11:03:09 am
Tell me how to determine the status of the phone? (waiting or incoming call)
Help please
Title: Re: android.permission.READ_PHONE_STATE does not work
Post by: jmpessoa on March 23, 2019, 05:13:01 pm

Hi, RDL!

finally!

Now demo "AppTelephonyManagerDemo1" can handle
"incoming call"  when the app is in background....

You,  can try the demo "AppBroadcastReceiverDemo2",  too!

Thank you!
TinyPortal © 2005-2018