双卡手机如何指定SIM卡打电话

package com.example.dualsimtest;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;

public class MainActivity extends Activity {
    public static final String[] dualSimTypes = { "subscription", "Subscription", 
        "com.android.phone.extra.slot", 
        "phone", "com.android.phone.DialingMode", 
        "simId", "simnum", "phone_type", 
        "simSlot" };
    EditText inputV;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        
        inputV = (EditText) findViewById(R.id.input);
        
        findViewById(R.id.call).setOnClickListener(new View.OnClickListener() {
            
            @Override
            public void onClick(View arg0) {
                String number = inputV.getText().toString().trim();
               if (number.equals("")) { 
                   Toast.makeText(MainActivity.this, "输入号码不恩为空", 1500).show();
               } else {
                   call(number); 
               }
            }
        });
    }
    
    
    private void call(String phone) {
        Intent callIntent = new Intent(Intent.ACTION_CALL)
                .setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        callIntent.setData(Uri.parse("tel:" + phone));
        for (int i=0; i < dualSimTypes.length; i++) {
            callIntent.putExtra(dualSimTypes[i], 2);
        }
        this.startActivity(callIntent);
    }
    
}

相关推荐