2013-08-27 69 views
-3

如何從三星10.1 Android平板電腦撥打電話?該平板電腦支持迷你SIM卡,2G和3G網絡。不過,我可以在平板電腦上收到短信,但我無法撥打電話。當我想在我的應用內撥打電話時,我被重定向到添加新聯繫人。 (請注意,它工作正常進行從手機設備的呼叫!)這是我的代碼用於撥打電話:在你的OnCreate()打電話給三星10.1 Android平板電腦

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); 
    } 
+1

您是否檢查平板電腦是否啓用了電話功能。 –

+0

嗨,我查閱了關於啓用電話功能的教程,但是如果我可以在代碼中完成,我還會等待更多的反饋。這裏是教程,如果有人需要它:http://androidadvices.com/enable-phone-calling-feature-in-galaxy-tab-10-1-750-tutorial/ – Diana

回答

1

將這個:

// 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; } 

      } 

    } 
} 
相關問題