I need to develop the VOIP application between 2 android devices.
As I know there is a SIP protocol used for this purpose but it requires registation to SIP server and access to internet for SIP signaling.
Is any way to create VOIP application in android without internet access?

- 1,973
- 10
- 10

- 947
- 3
- 15
- 39
-
Do you mean like a sort of walkie-talkie? There are ways to do peer to peer with wifi and bluetooth, would that fulfill your needs? – MikeIsrael Jun 24 '12 at 12:42
-
Yes. Actually I need ONE to MANY walkie-talkie, with wifi. Kind of conference without access to Internet – Costa Mirkin Jun 24 '12 at 12:49
-
SIP does not require internet access, nor does it require anything more than the user agents themselves. (These things are _useful_ but not _required_.) – Frank Shearar Jun 24 '12 at 21:29
-
@FrankShearar Can please describe how is it possible? see my question: http://stackoverflow.com/questions/25520246/local-voip-call-with-sip – user2808671 Aug 27 '14 at 09:42
-
how is it now @CostaMirkin ? – gumuruh Aug 29 '14 at 03:44
5 Answers
Of course it is possible! Why you would need the internet? As long as you are both connected to the same network that is fine! Below is the java and xml for a working app.
On start up it will provide you with your own local port, for example "52022".. this is random every time and unfortunately that can't be helped. We then enter the IP address of the other phone and THEIR randomly generated port number and press connect. They do exactly the same and hooray you're connected! This test app obviously requires you to be close by to exchange port numbers, but in my proper app I was easily able to request each port number before connecting. Hope this helps!
public class MainActivity extends Activity {
AudioGroup m_AudioGroup;
AudioStream m_AudioStream;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
StrictMode.ThreadPolicy policy = new StrictMode.ThreadPolicy.Builder().permitAll().build();
StrictMode.setThreadPolicy(policy);
try {
AudioManager audio = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
audio.setMode(AudioManager.MODE_IN_COMMUNICATION);
m_AudioGroup = new AudioGroup();
m_AudioGroup.setMode(AudioGroup.MODE_NORMAL);
m_AudioStream = new AudioStream(InetAddress.getByAddress(getLocalIPAddress ()));
int localPort = m_AudioStream.getLocalPort();
m_AudioStream.setCodec(AudioCodec.PCMU);
m_AudioStream.setMode(RtpStream.MODE_NORMAL);
((TextView)findViewById(R.id.lblLocalPort)).setText(String.valueOf(localPort));
((Button) findViewById(R.id.button1)).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
String remoteAddress = ((EditText)findViewById(R.id.editText2)).getText().toString();
String remotePort = ((EditText)findViewById(R.id.editText1)).getText().toString();
try {
m_AudioStream.associate(InetAddress.getByName(remoteAddress), Integer.parseInt(remotePort));
} catch (NumberFormatException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
m_AudioStream.join(m_AudioGroup);
}
});
((Button) findViewById(R.id.button2)).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
m_AudioStream.release();
}
});
} catch (Exception e) {
Log.e("----------------------", e.toString());
e.printStackTrace();
}
}
public static byte[] getLocalIPAddress () {
byte ip[]=null;
try {
for (Enumeration<NetworkInterface> en = NetworkInterface.getNetworkInterfaces(); en.hasMoreElements();) {
NetworkInterface intf = en.nextElement();
for (Enumeration<InetAddress> enumIpAddr = intf.getInetAddresses(); enumIpAddr.hasMoreElements();) {
InetAddress inetAddress = enumIpAddr.nextElement();
if (!inetAddress.isLoopbackAddress()) {
ip= inetAddress.getAddress();
}
}
}
} catch (SocketException ex) {
Log.i("SocketException ", ex.toString());
}
return ip;
}
}
Layout file:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity" >
<TextView
android:id="@+id/lblLocalPort"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/localPort" />
<EditText
android:id="@+id/editText2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:ems="10"
android:hint="@string/iPHint"
android:inputType="phone" />
<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:ems="10"
android:hint="@string/portHint"
android:inputType="number" >
<requestFocus />
</EditText>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp">
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/connect" />
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/Disconnect" />
</LinearLayout>
</LinearLayout>
EDIT: The IP address method stopped working at API 22, use below code:
private byte[] getLocalIPAddress() {
byte[] bytes = null;
try {
// get the string ip
WifiManager wm = (WifiManager) getSystemService(WIFI_SERVICE);
String ip = Formatter.formatIpAddress(wm.getConnectionInfo().getIpAddress());
// convert to bytes
InetAddress inetAddress = null;
try {
inetAddress = InetAddress.getByName(ip);
} catch (UnknownHostException e) {
e.printStackTrace();
}
bytes = new byte[0];
if (inetAddress != null) {
bytes = inetAddress.getAddress();
}
} catch (Exception e) {
e.printStackTrace();
Toast.makeText(this, R.string.phone_voip_incompatible, Toast.LENGTH_SHORT).show();
}
return bytes;
}

- 2,207
- 1
- 22
- 36
-
I am getting this exception E/----------------------: java.net.SocketException: Invalid argument – Krishna Meena Jul 14 '16 at 07:31
-
It's been a while since i've used this and I am aware that the way to get an ip address has changed on the recent android updates. – Murphybro2 Jul 14 '16 at 08:55
-
Can you guide me how to make voice call over local wifi from one android device to another ? – Krishna Meena Jul 14 '16 at 10:57
-
See the edited code, switch out the ip address method for the new one – Murphybro2 Jul 14 '16 at 12:32
-
It is working now but after pressing connect nothing is happening. What should I do so that after pressing connect it should connect to another device and should be able to transfer voice. – Krishna Meena Jul 14 '16 at 13:48
-
have you exchanged both port numbers? So each phone knows to connect to the other phones port? – Murphybro2 Jul 14 '16 at 14:10
-
-
Hi Krishna, this is an old solution and I cannot guarantee it works with the current version of android. When I first created this post the code you see above was EVERYTHING that was needed to make it work. If it no longer works then something has changed since. – Murphybro2 Feb 03 '17 at 13:40
-
it works for me, make sure to have all the right permissions in the manifest and accepted after android 6 – Ultimo_m Jun 20 '19 at 14:54
-
-
@Murphybro2 :D if you know smth that does video streaming this simple I would be happy to hear – Ultimo_m Jun 20 '19 at 16:26
-
Thank you for providing this code. I'm having problems getting it to work on two android devices, is there any way we can get some communication going via Skype or Discord? – fihdi Nov 15 '19 at 14:48
actually SIP clients can talk peer-to-peer, they just need to know their IP addresses and UDP ports where they listen to SIP messages.
You can play around with normal SIP clients on two comuters (X-Lite for Windows, Twinkle for Linux, and some others exist too) and try establishing a call between them without server registration. It's quite possible.
Also you can run a minimalistic SIP server somewhere in local LAN. For example, FreeSWITCH can be minimized to a quite tiny footprint.

- 1,973
- 10
- 10
-
-
no, I don't think so. It's written in C, and android is java based – Stanislav Sinyagin Jun 24 '12 at 12:55
-
-
yes, but you can't install native-C applications on unrooted phone – Stanislav Sinyagin Jun 24 '12 at 14:03
-
for a point-to-multipoint communication, I woudl definitely recommend installing FreeSWITCH on a server in the same LAN. If your Wifi access point is strong enough, you can try installing it there too. Well, learning the platform will take another week anyway... – Stanislav Sinyagin Jun 24 '12 at 14:55
-
@StanislavSinyagin Can you please see my question about SIP? http://stackoverflow.com/questions/25520246/local-voip-call-with-sip – user2808671 Aug 27 '14 at 19:19
-
I'm not really familiar with Android programming. You need to learn the protocol and try various options – Stanislav Sinyagin Aug 27 '14 at 22:43
OK so if you are looking for some peer-2-peer communications, I think wifi is the way to go (better distance and speeds). If you can develop for only newer versions of Android then WI-FI Direct is the way to go, but that will only work on Android 4.0 and above
In order to have something run on below 4.0 you are going to have to go with a 3rd party library. I know Qualcomm has a library called alljoyn, but not sure how good it is.

- 2,871
- 2
- 22
- 34
-
-
once you have the connection you can run whatever service you want over it. If you are looking for a voip with p2p capability already built in, then I don't think you are going to find it. – MikeIsrael Jun 24 '12 at 13:01
-
-
@CostaMirkin the wifi-direct solution should allow you to have as many connections as you want. Did you read the resources at the other end of the links? – MikeIsrael Jun 24 '12 at 13:19
I think you can use JITSI for p2p voip service on multiple platforms including Andriod.
These are my findings about this project:-
- Do not need any server or internet connectivity.
- Users must be under a same network.
- Open Source.
- Android apk is available, most probably you can find it code on website or you can de-compile it.

- 936
- 6
- 15
It is not possible because VOIP call Pass through internet and via sip server.
for Example . if you want to call outside from your country via VOIP dailer, you must need internet access because it is not possible to communicate via Bluetooth.
Thanks.

- 6,213
- 2
- 27
- 37
-
But if I just want 2 phones connected using WIFI talk to each other without the internet connection? – Costa Mirkin Jun 24 '12 at 11:28
-
it is not possible because, you must to need a server to communicate each other..... – Md Abdul Gafur Jun 24 '12 at 11:30
-
But it for SIP only. Maybe there is some way to build VOIP application in Java vithout SIP? – Costa Mirkin Jun 24 '12 at 11:33
-
1VOIP can be built without SIP. You will just need to create your own protocol for voice data transfer. – James Cross Jun 24 '12 at 11:44
-
-
4All SIP user agents are, by definition, servers. There is no requirement in the protocol for anything beyond the SIP user agents themselves. – Frank Shearar Jun 24 '12 at 21:23