Home » Android » java – How to send text message in android via sip

java – How to send text message in android via sip

Posted by: admin June 15, 2020 Leave a comment

Questions:

I am developing a application in android in which I want to send text message using sip/xmpp(session initiation protocol) can anyone give me code for it and any guidelines about its development and testing on any free sip provider.

How to&Answers:

Update having re-read
Sorry, I failed to realise that the question related only to text messaging. SIP itself doesn’t support text messaging, SIMPLE or MSRP extensions enable that. You need to find a stack that you are happy working with, here is one example Doubango and their demo product IMSDroid but Google ‘Android MSRP’ for plenty of other options. I still don’t know anything about XMPP,but check out this thread for a great list of libraries and uses.
End update

What have you tried so far? For the SIP (voice) part of your question here is the documentation on the Android Developers site with all you need to know and here is a free SIP provider: Getonsip.

Reduced code sample, largely lifted from Android developer site.

Essentially you need to make sure minSDK is set to 9 as the SIP library was not added until 2.3. Add the services to your manifest:

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

Optionally add the uses-feature voip directive if you want your app to not install on devices where it will not work.

<uses-feature android:name="android.hardware.sip.voip" />

Create a SipManager:

android.net.sip.SipManager manager = SipManager.newInstance(this);

Create a profile with which to make/receive calls through your provider:

android.net.sip.SipProfile.Builder builder = new SipProfile.Builder(username, domain);
builder.setPassword(password);
android.net.sip.SipProfile sipProfile = builder.build();

If all you care about is making calls:

manager.open(profile);

To make a call you u work with a listener:

SipAudioCall.Listener listener = new SipAudioCall.Listener() {

    @Override
    public void onCallEstablished(SipAudioCall call) {
        call.startAudio();
        call.setSpeakerMode(true);
        call.toggleMute();
        ...
    }

    @Override
    public void onCallEnded(SipAudioCall call) {
        // Do something.
    }
};

Now, as long as you have the SIP address of your peer you can use:

SipProfile friendProfile = ...;
manager.makeAudioCall(sipProfile.getUriString(), friendAddress, listener, 30);

That should get you started. Unfortunately I have no experience with XMPP.