2012-11-05 68 views
18

我有一個雙卡android手機。我正在使用此代碼撥打電話:來自第二個SIM卡的電話

private void callBack(String phone, Context context) { 
     Intent callIntent = new Intent(Intent.ACTION_CALL) 
       .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
     callIntent.setData(Uri.parse("tel:" + phone)); 
     context.startActivity(callIntent); 

    } 

它工作正常。但它總是從sim1打電話(最好是sim)。我如何通過Sim2撥打電話?有沒有辦法處理雙SIM卡手機?

回答

30

這似乎是在一個大範圍的雙SIM卡的設備如摩托羅拉,Micromax的,HTC的工作,三星

intent.putExtra("com.android.phone.extra.slot", 0); //For sim 1 

OR

intent.putExtra("com.android.phone.extra.slot", 1); //For sim 2 

,如果不行試試這個,在三星S二重奏這工作得很好。

intent.putExtra("simSlot", 0); //For sim 1 

OR

intent.putExtra("simSlot", 1); //For sim 2 

不幸的是,這些事情,我們必須進入命中/試用模式,因爲沒有正式的文件是有雙卡的支持。

+0

由於工作。讓我在其他手機上檢查它。順便說一句,你是怎麼知道這件事的?沒有記錄在哪裏? –

+1

我的幾次隨機嘗試之一 – 2013-10-21 07:04:45

+0

它的工作!已經等了幾個月了......乾杯! :D –

1

Android不提供API來支持雙SIM卡設備。 Android的SIM卡相關API僅支持默認SIM卡(通常爲SIM#1)。在Android上支持雙SIM的硬件實現方式,因此設備製造商必須實現自己的API或定製源代碼以支持其硬件組件。您可以聯繫設備製造商獲取支持雙卡的SDK。

4
final Intent intent = new Intent(Intent.ACTION_CALL, Uri.parse("tel:" + phoneNumberOrUssd)); 
    final int simSlotIndex = 1; //Second sim slot 

    try { 
     final Method getSubIdMethod = SubscriptionManager.class.getDeclaredMethod("getSubId", int.class); 
     getSubIdMethod.setAccessible(true); 
     final long subIdForSlot = ((long[]) getSubIdMethod.invoke(SubscriptionManager.class, simSlotIndex))[0]; 

     final ComponentName componentName = new ComponentName("com.android.phone", "com.android.services.telephony.TelephonyConnectionService"); 
     final PhoneAccountHandle phoneAccountHandle = new PhoneAccountHandle(componentName, String.valueOf(subIdForSlot)); 
     intent.putExtra("android.telecom.extra.PHONE_ACCOUNT_HANDLE", phoneAccountHandle); 
    } catch (Exception e) { 
     e.printStackTrace(); 
    } 

    intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 
    context.startActivity(intent); 

上雙SIM華碩Fonepad 7的Android 5.0