title: Incoming number is null after ending the call in android PIE 9
body: <p>I have been working on this problem since weeks. I am making an app which picks the incoming number and shows it in a dialog box after the call is ended. Everything is working fine below android PIE 9.0. The number is always null in android PIE. I have given all permissions including <code>READ_CALL_LOGS</code> but same problem. The incoming number is null. So please anyone help me...</p>
  
  <p><strong>Here is my manifest file :</strong></p>
  
  <pre><code>&lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
  package="com.softixtechnologies.phonemanager"&gt;
  
  &lt;uses-permission android:name="android.permission.READ_PHONE_STATE" /&gt;
  &lt;uses-permission android:name="android.permission.READ_CALL_LOG" /&gt;
  &lt;uses-permission android:name="android.permission.WRITE_CALL_LOG" /&gt;
  &lt;uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" /&gt;
  &lt;uses-permission android:name="android.permission.ACTION_MANAGE_OVERLAY_PERMISSION" /&gt;
  &lt;uses-permission android:name="android.permission.GET_ACCOUNTS" /&gt;
  &lt;uses-permission android:name="android.permission.READ_PROFILE" /&gt;
  &lt;uses-permission android:name="android.permission.READ_CONTACTS" /&gt;
  &lt;uses-permission android:name="android.permission.WRITE_CONTACTS" /&gt;
  &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt;
  
  &lt;application
      android:allowBackup="true"
      android:icon="@drawable/calllogo"
      android:label="@string/app_name"
      android:persistent="true"
      android:roundIcon="@drawable/calllogo"
      android:supportsRtl="true"
      android:theme="@style/AppTheme"
      android:usesCleartextTraffic="true"&gt;
      &lt;activity android:name=".activities.CallLogEntryActivity"&gt;&lt;/activity&gt;
      &lt;activity android:name=".activities.CallLogsActivity" /&gt;
      &lt;activity android:name=".activities.IgnoredNumbersActivity" /&gt;
      &lt;activity android:name=".activities.IContactsActivity" /&gt;
      &lt;activity android:name=".activities.SplashActivity"&gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.MAIN" /&gt;
  
              &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
          &lt;/intent-filter&gt;
      &lt;/activity&gt;
      &lt;activity android:name=".activities.CategoryPhoneActivity" /&gt;
      &lt;activity
          android:name=".activities.LogsActivity"
          android:label="@string/title_activity_logs"
          android:theme="@style/AppTheme.NoActionBar" /&gt;
      &lt;activity
          android:name=".activities.CategoryActivity"
          android:label="@string/title_activity_category"
          android:theme="@style/AppTheme.NoActionBar" /&gt;
      &lt;activity android:name=".MainActivity" /&gt;
  
      &lt;receiver
          android:name=".callhelpers.CallReciever"
          android:enabled="true"&gt;
          &lt;intent-filter&gt;
              &lt;action android:name="android.intent.action.PHONE_STATE" /&gt;
          &lt;/intent-filter&gt;
      &lt;/receiver&gt;
  
      &lt;provider
          android:name="android.support.v4.content.FileProvider"
          android:authorities="${applicationId}.provider"
          android:exported="false"
          android:grantUriPermissions="true"&gt;
          &lt;meta-data
              android:name="android.support.FILE_PROVIDER_PATHS"
              android:resource="@xml/provider_paths" /&gt;
      &lt;/provider&gt;
  &lt;/application&gt;
  </code></pre>
  
  <p></p>
  
  <p><strong>Here is my code</strong> : </p>
  
  <pre><code>    public class PhoneCallReceiver extends BroadcastReceiver {
      private static int lastState = TelephonyManager.CALL_STATE_IDLE;
      private static Date callStartTime;
      private static boolean isIncoming;
      private static String savedNumber;
      public String phoneNr ;
      DatabaseHelper databaseHelper ;
  
      @Override
      public void onReceive(final Context context, Intent intent) {
          databaseHelper = new DatabaseHelper(context);
  
  
      if (intent.getAction().equals("android.intent.action.NEW_OUTGOING_CALL")) {
                  savedNumber = intent.getExtras().getString("android.intent.extra.PHONE_NUMBER");
              } else {
                  String stateStr = intent.getExtras().getString(TelephonyManager.EXTRA_STATE);
                  String number = intent.getExtras().getString(TelephonyManager.EXTRA_INCOMING_NUMBER);
  
                  int state = 0;
                  if (stateStr.equals(TelephonyManager.EXTRA_STATE_IDLE)) {
                      state = TelephonyManager.CALL_STATE_IDLE;
                  } else if (stateStr.equals(TelephonyManager.EXTRA_STATE_OFFHOOK)) {
                      state = TelephonyManager.CALL_STATE_OFFHOOK;
                  } else if (stateStr.equals(TelephonyManager.EXTRA_STATE_RINGING)) {
                      state = TelephonyManager.CALL_STATE_RINGING;
                  }
                  onCallStateChanged(context, state, number);
              }
      }
  
      protected void onIncomingCallStarted(Context ctx, String number, Date start){}
  
      protected void onOutgoingCallStarted(Context ctx, String number, Date start){}
  
      protected void onIncomingCallEnded(Context ctx, String number, Date start, Date end){}
  
      protected void onOutgoingCallEnded(Context ctx, String number, Date start, Date end){}
  
      protected void onMissedCall(final Context ctx, final String number, Date start){}
  
      public void onCallStateChanged(Context context, int state, String number){
              if (lastState == state) {
                  return;
              }
              switch (state) {
                  case TelephonyManager.CALL_STATE_RINGING:
                      isIncoming = true;
                      callStartTime = new Date();
                      savedNumber = number;
  
                      onIncomingCallStarted(context, number, callStartTime);
                      break;
  
                  case TelephonyManager.CALL_STATE_OFFHOOK:
                      if (lastState != TelephonyManager.CALL_STATE_RINGING) {
                          isIncoming = false;
                          callStartTime = new Date();
                          onOutgoingCallStarted(context, savedNumber, callStartTime);
                      }
                      break;
  
                  case TelephonyManager.CALL_STATE_IDLE:
  
                      if (lastState == TelephonyManager.CALL_STATE_RINGING) {
                              onMissedCall(context, savedNumber, callStartTime);
                      } else if (isIncoming) {
  
                          onIncomingCallEnded(context, savedNumber, callStartTime, new Date());
                      } else {
                          onOutgoingCallEnded(context, savedNumber, callStartTime, new Date());
                      }
                      break;
              }
              lastState = state;
      }
      public boolean contactExists(Context context, String number) {
          Uri lookupUri = Uri.withAppendedPath(
                  ContactsContract.PhoneLookup.CONTENT_FILTER_URI,
                  Uri.encode(number));
          String[] mPhoneNumberProjection = { ContactsContract.PhoneLookup._ID, ContactsContract.PhoneLookup.NUMBER, ContactsContract.PhoneLookup.DISPLAY_NAME };
          Cursor cur = context.getContentResolver().query(lookupUri,mPhoneNumberProjection, null, null, null);
          try {
              if (cur.moveToFirst()) {
                  return true;
              }
          } finally {
              if (cur != null)
                  cur.close();
          }
          return false;
      }
  }
  
  </code></pre>
  
  <p>Your help is greatly appreciated!!</p>