2013-11-14 55 views
3

我開發了一個客戶使用sip撥打互聯網電話的應用程序。爲此他向我提供了兩個有效的sip user_id和密碼。上午使用SIP API實現.customer表示通話不會進行,他在使用他的賬號登錄時不會收到任何有關未接電話的通知。我不能在代碼中發現任何錯誤。請幫助我。代碼是下面給出。使用android sip撥打Android音頻電話

public class CallActivity extends Activity { 
     public String sipAddress = null; 
     public SipManager mSipManager = null; 
     public SipProfile mSipProfile = null; 
     public SipAudioCall call = null; 
     Button b1; 
     TextView sipadd; 

     @Override 
     protected void onCreate(Bundle savedInstanceState) { 
      // TODO Auto-generated method stub 
      super.onCreate(savedInstanceState); 
      setContentView(R.layout.calling); 
      sipAddress = (String) getIntent().getExtras().get("sipAddress"); 
      b1 = (Button) findViewById(R.id.sipcallbtnend); 
      b1.setOnClickListener(new OnClickListener() { 

       @Override 
       public void onClick(View v) { 
        finish(); 
       } 
      }); 

      sipadd = (TextView) findViewById(R.id.sipcalltvdialedaddress); 

      sipadd.setText(sipAddress); 
      b1.setOnClickListener(new OnClickListener() { 

       @Override 
       public void onClick(View v) { 
        if (call != null) { 
         call.close(); 
        } 
        finish(); 
       } 
      }); 
      initializeManager(); 
     } 

     @Override 
     public void onStart() { 
      super.onStart(); 
      // When we get back from the preference setting Activity, assume 
      // settings have changed, and re-login with new auth info. 
      initializeManager(); 
     } 

     @Override 
     public void onDestroy() { 
      super.onDestroy(); 
      if (call != null) { 
       call.close(); 
      } 

      closeLocalProfile(); 

      // if (callReceiver != null) { 
      // this.unregisterReceiver(callReceiver); 
      // } 
     } 

     public void initializeManager() { 
      if (mSipManager == null) { 
       mSipManager = SipManager.newInstance(this); 
      } 

      initializeLocalProfile(); 
     } 

     public void initializeLocalProfile() { 
      if (mSipManager == null) { 
       return; 
      } 

      if (mSipProfile != null) { 
       closeLocalProfile(); 
      } 
      SharedPreferences prefs = PreferenceManager 
        .getDefaultSharedPreferences(getBaseContext()); 
      String username = prefs.getString("namePref", ""); 
      String domain = prefs.getString("domainPref", ""); 
      String password = prefs.getString("passPref", ""); 

      if (username.length() == 0 || domain.length() == 0 
        || password.length() == 0) { 
       // showDialog(UPDATE_SETTINGS_DIALOG); 
       return; 
      } 

      try { 
       SipProfile.Builder builder = new SipProfile.Builder(username, 
         domain); 
       builder.setPassword(password); 
       builder.setDisplayName(username); 
       builder.setAuthUserName(username); 
       mSipProfile = builder.build(); 

       Intent i = new Intent(); 
       i.setAction("android.SipDemo.INCOMING_CALL"); 
       PendingIntent pi = PendingIntent.getBroadcast(this, 0, i, 
         Intent.FILL_IN_DATA); 
       mSipManager.open(mSipProfile, pi, null); 
       // 
       // 
       // // This listener must be added AFTER manager.open is called, 
       // // Otherwise the methods aren't guaranteed to fire. 

       mSipManager.setRegistrationListener(mSipProfile.getUriString(), 
         new SipRegistrationListener() { 
          public void onRegistering(String localProfileUri) { 
           // updateStatus("Registering with SIP Server..."); 
           Log.d("onRegistering", 
             "Registering with SIP Server..."); 
          } 

          public void onRegistrationDone(String localProfileUri, 
            long expiryTime) { 
           // updateStatus("Ready"); 
           Log.d("onRegistrationDone", 
             "RegistrationDone..Ready"); 

          } 

          public void onRegistrationFailed(
            String localProfileUri, int errorCode, 
            String errorMessage) { 
           // updateStatus("Registration failed. Please check settings."); 
           Log.d("onRegistrationFailed", "RegistrationFailed"); 

          } 
         }); 
      } catch (ParseException pe) { 
       // updateStatus("Connection Error."); 
      } catch (SipException se) { 
       // updateStatus("Connection error."); 
      } 

      initiateCall(); 
     } 

     public void closeLocalProfile() { 
      if (mSipManager == null) { 
       return; 
      } 
      try { 
       if (mSipProfile != null) { 
        mSipManager.close(mSipProfile.getUriString()); 
       } 
      } catch (Exception ee) { 
       Log.d("WalkieTalkieActivity/onDestroy", 
         "Failed to close local profile.", ee); 
      } 
     } 

     public void initiateCall() { 

      // updateStatus(sipAddress); 
      Log.d("nzm", "initiatecall"); 

      try { 
       SipAudioCall.Listener listener = new SipAudioCall.Listener() { 
        // Much of the client's interaction with the SIP Stack will 
        // happen via listeners. Even making an outgoing call, don't 
        // forget to set up a listener to set things up once the call is 
        // established. 
        @Override 
        public void onCallEstablished(SipAudioCall call) { 
         call.startAudio(); 
         call.setSpeakerMode(true); 
         call.toggleMute(); 
         Log.d("on call established", "on call established"); 
         // updateStatus(call); 
        } 

        @Override 
        public void onCallEnded(SipAudioCall call) { 
         // updateStatus("Ready."); 
         // Intent i = new 
         // Intent(getBaseContext(),DialActivity.class); 
         // startActivity(i); 
         finish(); 
        } 
       }; 

       call = mSipManager.makeAudioCall(mSipProfile.getUriString(), sipAddress, 
         listener, 3000); 
       Log.d("call", "" + call.getState()); 
      } catch (Exception e) { 
       Log.i("WalkieTalkieActivity/InitiateCall", 
         "Error when trying to close manager.", e); 
       if (mSipProfile != null) { 
        try { 
         mSipManager.close(mSipProfile.getUriString()); 
        } catch (Exception ee) { 
         Log.i("WalkieTalkieActivity/InitiateCall", 
           "Error when trying to close manager.", ee); 
         ee.printStackTrace(); 
        } 
       } 
       if (call != null) { 
        call.close(); 
       } 
      } 
     } 

    } 

清單中的權限如下

<uses-permission android:name="android.permission.USE_SIP" /> 
    <uses-permission android:name="android.permission.INTERNET" /> 
    <uses-permission android:name="android.permission.VIBRATE" /> 
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /> 
    <uses-permission android:name="android.permission.WAKE_LOCK" /> 
    <uses-permission android:name="android.permission.RECORD_AUDIO" /> 

    <uses-feature android:name="android.hardware.sip.voip" android:required="true" /> 
    <uses-feature android:name="android.hardware.wifi" android:required="true" /> 
    <uses-feature android:name="android.hardware.microphone" android:required="true" /> 

給出請幫我.Thanks提前。

+0

你好我使用分配VOIP SIP作爲一個在大學裏的項目。而且我面臨着很多麻煩。你有工作嗎?如果是的話,那麼你可以給我的項目,因爲Android樣本不工作。我會非常感謝 –

+0

我很抱歉,我的應用程序無法正常工作..如果我能找到任何對您有用的東西,那麼我會通知您。請將您的郵件ID發送到[email protected] – Noufal

+0

@ Noufal我在使用SIP時遇到了一個不好的問題。如果你找到任何解決方案,我很樂意知道。請參閱我的問題:http://stackoverflow.com/questions/25520246/local-voip-call-with-sip – user2808671

回答

3

也許正在使用Android的例子中,你添加這些

<uses-permission android:name="android.permission.CONFIGURE_SIP" /> 

<uses-feature android:name="android.software.sip" android:required="true" /> 
<uses-feature android:name="android.software.sip.voip" android:required="true" /> 
<uses-feature android:name="android.hardware.telephony" android:required="false" /> 

?它應該在支持SIP的設備上工作。

並添加接收器的onCreate

IntentFilter filter = new IntentFilter(); 
filter.addAction("android.SipDemo.INCOMING_CALL"); 
callReceiver = new IncomingCallReceiver(); 
this.registerReceiver(callReceiver, filter); 
+0

Thanks.I編輯您的suggetions.B代碼,但仍然無法正常工作。 – Noufal

+0

您是否看到任何調試錯誤消息? – Gina

+0

我從application.i得到了一些積極的迴應。我在@override onRingingBack(SipAudioCall調用)中獲得了一個日誌。但不知道任何最終調用者會收到該調用。哪個sip賬戶適合測試。 – Noufal