1 year ago
#313504
Range
How get simId in call/sms receiver for device with dual sim?
I implemented interface BroadcastReceiver for hook incoming call and sms. I want get simId to which the incoming call or sms comes. How to do it?
My code for receiver calls and sms:
public class SmsAndCallReceiver extends BroadcastReceiver {
public void _onReceive(Context context, Intent intent) {
// here I define incoming call or sms
// here I get simId !!!
}
}
I also registered class in AndroidManifest.xml:
<receiver android:name=".receivers.SmsAndCallReceiver" android:exported="true">
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE"/>
</intent-filter>
</receiver>
And also I add permissions:
<uses-permission android:name="android.permission.SEND_SMS"/>
<uses-permission android:name="android.permission.RECEIVE_SMS"/>
<uses-permission android:name="android.permission.READ_SMS"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.READ_CALL_LOG"/>
<uses-permission android:name="android.permission.READ_PHONE_NUMBERS"/>
I saw this option, but it doesn't work on my device:
public class MyCallReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String callingSIM = "";
callingSIM = intent.getExtras().getInt("simId", -1);
if(callingSIM == "0"){
//SIM1
}
else if(callingSIM =="1"){
//SIM2
}
}
}
My device: Samsung SM-J260F
Version android: 8.1.0 (API 27)
Root device: no
java
android
broadcastreceiver
samsung-mobile
0 Answers
Your Answer