0

I am developing a Xamarin.Android App to read the incoming call phone number, and I was able to get the same in Android Oreo. But once we upgraded to Android Pie

string telephone = intent.GetStringExtra(TelephonyManager.ExtraIncomingNumber);

always returns 'null'.

While Searching, I find out that by adding 'READ_CALL_LOG' permission it will work in Android Pie.

I already tried by adding 'READ_CALL_LOG' to AndroidManifest.xml,

Also given the run time permission for 'READ_CALL_LOG' and 'READ_PHONE_STATE' in my MainActivity.cs

But Nothing worked for me.

Please tell me if I am missing anything?

```in AndroidManifest.xml
<uses-permission android:name="android.permission.READ_CALL_LOG" />


```in MainActivity.cs
if (ContextCompat.CheckSelfPermission(this,
    Manifest.Permission.ReadPhoneState) != 
    Android.Content.PM.Permission.Granted ||                
    Manifest.Permission.ReadCallLog) != Android.Content.PM.Permission.Granted)
{
    ActivityCompat.RequestPermissions(this,
    new string[] { Manifest.Permission.ReadCallLog, 
    Manifest.Permission.ReadPhoneState },2);
}
Gireesh
  • 45
  • 1
  • 5
  • Does it work for you ? – Leo Zhu Sep 10 '19 at 03:01
  • Does this answer your question? [TelephonyManager.EXTRA\_INCOMING\_NUMBER always null on Android 9](https://stackoverflow.com/questions/55634155/telephonymanager-extra-incoming-number-always-null-on-android-9) – Bink May 25 '22 at 22:49

1 Answers1

1

in Android 9, you have to explicitly ask for both the READ_PHONE_STATE and the READ_CALL_LOG permissions at run time. In previous Android versions you only had to ask for the READ_PHONE_STATE permission. Both of them have to be asked at run time.

If the receiving app has Manifest.permission.READ_CALL_LOG and Manifest.permission.READ_PHONE_STATE permission, it will receive the broadcast twice; one with the EXTRA_INCOMING_NUMBER populated with the phone number, and another with it blank

Here is the TelephonyManager docoument.

Leo Zhu
  • 15,726
  • 1
  • 7
  • 23