如何从Samsung 10.1 Android平板电脑拨打电话?平板电脑支持迷你SIM卡,2G和3G网络。但是,我可以在平板电脑上收到短信,但我无法拨打任何电话。当我想从我的应用程序中拨打电话时,我被重定向到添加新联系人。 (请注意,它可以通过电话设备拨打电话!)以下是我拨打电话的代码:
public void onClick(View v) {
String destination = mContactsAt.getText().toString();
Log.d("CallActivity", "after getting the contact name");
String phoneNo = getPhoneNumber(destination);
Log.d("CallActivity", "after showing number");
if (phoneNo.startsWith("+")){
phoneNo.replace("+", "00");
}
phoneNo.replaceAll("[^0-9]+", "");
Log.d("CallActivity", "phoneNo to call =" + phoneNo + " destination " + destination);
phoneNumber = phoneNo;
contactName = destination;
Intent intent = new Intent(Intent.ACTION_CALL);
intent.setData(Uri.parse("tel:"+phoneNo.trim()));
startActivity(intent);
}
答案 0 :(得分:1)
将它放在你的oncreate()中:
// Register for Phone Calling
PhoneCallListener phoneListener = new PhoneCallListener();
TelephonyManager telephonyManager = (TelephonyManager) this
.getSystemService(Context.TELEPHONY_SERVICE);
telephonyManager.listen(phoneListener,
PhoneStateListener.LISTEN_CALL_STATE);
这是您开始通话的地方:
Intent callIntent = new Intent(
Intent.ACTION_CALL);
callIntent.setData(Uri.parse("tel:06641234567"));
startActivity(callIntent);
至少:
public class PhoneCallListener extends PhoneStateListener {
private boolean isPhoneCalling = false;
String LOG_TAG = "LOGGING 123";
@Override
public void onCallStateChanged(int state, String incomingNumber) {
if (TelephonyManager.CALL_STATE_RINGING == state) {
// phone ringing
Log.i(LOG_TAG, "RINGING, number: " + incomingNumber);
}
if (TelephonyManager.CALL_STATE_OFFHOOK == state) {
// active
AudioManager audioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
audioManager.setMode(AudioManager.MODE_IN_CALL);
audioManager.setSpeakerphoneOn(true);
System.out.println("SPEAKER ON!!");
Log.i(LOG_TAG, "OFFHOOK");
isPhoneCalling = true;
}
if (TelephonyManager.CALL_STATE_IDLE == state) { // run when
//class initial and phone call ended, // need detect flag from
//CALL_STATE_OFFHOOK Log.i(LOG_TAG, "IDLE");
if (isPhoneCalling) {
Log.i(LOG_TAG, "restart app");
//restart app
Intent i = getBaseContext().getPackageManager()
.getLaunchIntentForPackage( getBaseContext().getPackageName());
i.addFlags(Intent.FLAG_ACTIVITY_PREVIOUS_IS_TOP);
startActivity(i);
isPhoneCalling = false; }
}
}
}