4

I have a dual SIM (slot 0 and slot 1) phone. I have the phonestatelistener in my service. This listener receives the callback only when the SIM in the sim slot 0 receives the call. This listener is not getting callback when a call comes for SIM in SIM slot 1.

I have swapped the SIM and confirmed that irrespective of the SIM the phonestatelistener getting callback for the SIM in the SIM slot 0 only.

I couldn't' understand the issue.

Please let me know what could be the problem

Phone model samsung galaxy s duos 2 (GT-S7562) OS jelly bean 4.2.2

Homeservice.java

public class Homeservice extends Service{


   TelephonyManager telephonyManager;  
   PhoneStateListener listener;



    @Override
    public void onCreate() {


         // Get the telephony manager    
         telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);

         // Create a new PhoneStateListener    
         listener = new PhoneStateListener() {      

         @Override      
         public void onCallStateChanged(int state, String incomingNumber) { 


             switch (state) {
                    case TelephonyManager.CALL_STATE_IDLE:
                        //finish something
                            break;
                    case TelephonyManager.CALL_STATE_OFFHOOK:
                        //do somethings
                        break; 
                    case TelephonyManager.CALL_STATE_RINGING: 
                        break;
                        } 
                    }
                };


                // Register the listener wit the telephony manager              
                telephonyManager.listen(listener, PhoneStateListener.LISTEN_CALL_STATE);




    }




    @Override
    public int onStartCommand(Intent intent, int flags, int startId) {
        // TODO Auto-generated method stub

        return START_STICKY;



    }


    @Override
    public void onDestroy() {

        super.onDestroy();
    }

    @Override
    public IBinder onBind(Intent arg0) {
        // TODO Auto-generated method stub
        return null;
    }




}

Manifest.xml

<service
        android:name="com.kabil.homeservice"
        >
   </service>
JasonMArcher
  • 14,195
  • 22
  • 56
  • 52
user1123931
  • 479
  • 1
  • 8
  • 24

2 Answers2

1

PhoneStateListener have another constructor PhoneStateListener(Integer subId) where you can pass your sim subscription id to the constructor and it will do the remaining task as it is.

Nigam Patro
  • 2,760
  • 1
  • 18
  • 33
0

An instance of TelephoneManager is tied to a specific SIM (subscriptionId). Use TelephonyManager.createForSubscription to obtain an instance for the SIM slot you desire.

sooniln
  • 14,607
  • 4
  • 29
  • 35