title: Android audio calls using android's sip
body: <p>I  developed an application for a customer to internet calling  using sip.For that he  provided me two valid sip user_id and password.  Am Using SIP API for SIP implementation.customer says that the call is not going.he don't get any notification about missed calls when he logged using his account.i cant find any mistakes in the code.please help me .the code is given below.</p>
  
  <pre><code>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();
                  }
              }
          }
  
      }
  </code></pre>
  
  <p>The permissions in manifest is given below</p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.USE_SIP" /&gt;
      &lt;uses-permission android:name="android.permission.INTERNET" /&gt;
      &lt;uses-permission android:name="android.permission.VIBRATE" /&gt;
      &lt;uses-permission android:name="android.permission.ACCESS_WIFI_STATE" /&gt;
      &lt;uses-permission android:name="android.permission.WAKE_LOCK" /&gt;
      &lt;uses-permission android:name="android.permission.RECORD_AUDIO" /&gt;
  
      &lt;uses-feature android:name="android.hardware.sip.voip" android:required="true" /&gt;
      &lt;uses-feature android:name="android.hardware.wifi" android:required="true" /&gt;
      &lt;uses-feature android:name="android.hardware.microphone" android:required="true" /&gt;
  </code></pre>
  
  <p>please help me .Thanks in Advance.</p>