2012-08-03 52 views
1

我有几天试图注册sip电话的问题。下面是我的代码,有人可以告诉我sip注册中有什么问题吗?无法让SipDemo注册sip语音电话

public class SipRegistration extends Activity { 

    public String sipAddress; 
    public SipManager manager = null; 
    public SipProfile profile = null; 
    public SipAudioCall call = null; 
    private EditText user, pass, domaine; 
    // private SipAudioCall.Listener listener; 
    protected static final String TAG = null; 
    private Button register; 
    private SipRegistrationListener listener; 

    @Override 
    public void onCreate(Bundle savedInstanceState) { 

     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); 
     user = (EditText) findViewById(R.id.main_edtUser); 
     pass = (EditText) findViewById(R.id.main_edtPassword); 
     domaine = (EditText) findViewById(R.id.main_edtDomain); 
     register = (Button) findViewById(R.id.main_btnRegister); 

     register.setOnClickListener(new OnClickListener() { 

      public void onClick(View v) { 
       // TODO Auto-generated method stub 
       initializeLocalProfile(); 

      } 
     }); 
    } 


    /** 
    * Logs you into your SIP provider, registering this device as the location 
    * to send SIP calls to for your SIP address. 
    * 
    * @return 
    */ 
    public boolean initializeLocalProfile() { 
     if (manager == null) { 
      manager = SipManager.newInstance(this); 
     } 

     Log.e("On build profile.......", ""); 



     String username = user.getText().toString(); 
     String domain = domaine.getText().toString(); 
     String password = pass.getText().toString(); 

     if (username.length() == 0 || domain.length() == 0 
       || password.length() == 0) { 
      return true; 
     } 
     Log.e("@@@@@@@@", "username \n" + username); 
     Log.e("@@@@@@@@@", "domain \n" + domain); 
     Log.e("@@@@@@@", "password \n" + password); 

     try { 
      SipProfile.Builder builder = new SipProfile.Builder(username, 
        domain); 
      builder.setPassword(password); 
      profile = builder.build(); 
      Log.e("profile Password", "" + builder.build()); 

      // Intent i = new Intent(); 
      // i.setAction("android.SipDemo.INCOMING_CALL"); 
      // PendingIntent pi = PendingIntent.getBroadcast(this, 0, i, 
      // Intent.FILL_IN_DATA); 
      // manager.open(profile, pi, null); 
      manager.open(profile); 
      Log.e("Profile:", "" + profile); 
      // Log.e("Intent:", "" + pi); 

      // Log.e("Listner:", "" + listener); 
      listener = new SipRegistrationListener() { 

       public void onRegistering(String localProfileUri) { 
        // TODO Auto-generated method stub 
        updateStatus("Registering with SIP Server..."); 
        Log.e("Registration Running..........", ""); 
        try { 
         manager.register(profile, 3000, listener); 
        } catch (SipException e) { 
         // TODO Auto-generated catch block 
         e.printStackTrace(); 
        } 
       } 

       public void onRegistrationDone(String localProfileUri, 
         long expiryTime) { 
        // TODO Auto-generated method stub 

        updateStatus("Ready"); 
        Log.e("Registration Done..........", ""); 
       } 

       public void onRegistrationFailed(String localProfileUri, 
         int errorCode, String errorMessage) { 
        // TODO Auto-generated method stub 

        updateStatus("Registration failed. Please check settings."); 
        Log.e("Registration failed..........", ""); 

       } 

      }; 

      if (manager.isRegistered(profile.getUriString())) { 
       Log.e("SipManager is ready for calls", ""); 
       return true; 
      } else 
       return false; 

     } catch (Exception ex) { 

      Log.e("---Error-- initializeProfile: " + ex.getMessage(), ""); 
      return false; 

     } 

    } 

    // This listener must be added AFTER manager.open is called, 
    // Otherwise the methods aren't guaranteed to fire. 

    public void updateStatus(final String status) { 
     // Be a good citizen. Make sure UI changes fire on the UI thread. 
     this.runOnUiThread(new Runnable() { 
      public void run() { 
       TextView labelView = (TextView) findViewById(R.id.main_sipLabel); 
       labelView.setText(status); 
       Log.e("Registration Running..........", ""); 
      } 
     }); 
    } 
} 

回答

2

更改使用的真实设备(2.3)或以上

Sipmanger.port(); 

啜演示实际运行的端口号8891。 确保在清单文件中添加权限。

+0

嘿,我该如何设置我的端口号?我有这样的代码,但我不知道在哪里添加这个端口设置? – mehmetakifalp 2014-11-20 16:06:47

+0

什么是8891端口?我认为他应该使用5060的SIP UDP端口。这是默认值。我也有同样的问题。我的注册总是失败。我在'CSipSimple'应用程序上使用相同的SIP提供程序('getonsip'),并且在我的'SipDemo' android样本无法使用时成功注册。 @mehmetakifalp – Fer 2014-12-17 15:34:41