add context to phone state listener.
authorTrillGates <williamtrillgates@gmail.com>
Mon, 19 Jul 2021 03:00:04 +0000 (11:00 +0800)
committerTrillGates <williamtrillgates@gmail.com>
Mon, 19 Jul 2021 03:00:04 +0000 (11:00 +0800)
app/src/main/java/com/enqualcomm/support/CoreService.java

index 4eb283f..54a628f 100644 (file)
@@ -934,9 +934,10 @@ public class CoreService extends Service {
      * 监听电话状态
      */
     private void registerPhoneStateListener() {
-        PhoneCallListener phoneCallListener = new PhoneCallListener();
+        Context applicationContext = getApplicationContext();
+        PhoneCallListener phoneCallListener = new PhoneCallListener(applicationContext);
         TelephonyManager telephonyManager =
-                (TelephonyManager) getApplicationContext().getSystemService(TELEPHONY_SERVICE);
+                (TelephonyManager) applicationContext.getSystemService(TELEPHONY_SERVICE);
         if (telephonyManager != null) {
             telephonyManager.listen(phoneCallListener, PhoneCallListener.LISTEN_CALL_STATE);
         }