我无法为通话设置默认 SIM 卡。我试图在每次发送 ACTION_CALL 意图之前更改系统设置以更改默认 sim,但每次我得到 sim 选择对话框
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;
}
}
我的意图是通过使用 Android 5.1 API 的特定 sim 进行呼叫。请让我知道是否有任何替代方法。