I am not able to set the default sim for calling. I am trying to alter the system settings to change the default sim every before I sent the ACTION_CALL intent but ever time I am getting the sim selection dialog
public class CallUtil {
public static void sendCallIntent(Context context, String number) {
Intent intent = new Intent(Intent.ACTION_CALL)
.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.setData(Uri.parse("tel:" + number));
setDefaultSim(context);
if (ActivityCompat.checkSelfPermission(context, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED) {
return;
}
context.startActivity(intent);
}
public static void setDefaultSim(Context context) {
try {
ContentValues val = new ContentValues();
List<Integer> sims = getInsertedSIMIds(context);
val.put("value", sims.get(0));
context.getContentResolver().update(Uri.parse("content://settings/system"), val, "name='voice_call_sim_setting'", null);
} catch (Exception e) {
}
}
public static List<Integer> getInsertedSIMIds(Context context){
List<Integer> list = new ArrayList<Integer>();
SubscriptionManager sm=(SubscriptionManager)context.getSystemService(Context.TELEPHONY_SUBSCRIPTION_SERVICE);
for ( SubscriptionInfo sub: sm.getActiveSubscriptionInfoList()) {
list.add(sub.getSimSlotIndex());
}
return list;
}
}
My intention is to place the call through a specific sim using Android 5.1 APIs. Please let me know if there is any alternate approach.