Skip to main content

How to Add Walkie-Talkie Functionality into Your Android App

· 4 min read
Kukuh Nomikusain

Walkie talkie devices

Texting while driving is very dangerous. Your eyes need to see your phone screen but at the same time they need to see the road. Your sight will not be in focus, and an unwanted accident could happen. Dangerous things can happen to yourself and also to other people.

But what if you need to communicate with your friends and family? Or maybe to your coworkers? You can use voice communication for that. Walkie talkie is one of the voice communications that can be used in that scenario. VoicePing app (https://voicepingapp.com) is a great option for it.

But what if you are an Android developer, and you want to implement walkie talkie functionality into your Android app? VoicePing Android SDK is the answer.

Solution: VoicePing Android SDK

VoicePing Android SDK is an Android library to bring walkie-talkie or push-to-talk functionality into your app. It’s free and open source. You can take a look at its code in this repo: https://github.com/SmartWalkieOrg/VoicePing-Walkie-Talkie-AndroidSDK . Its documentation is available on the website: https://opensource.voiceping.info/ .

By using VoicePing Android SDK, you can send voice messages instantly to 1 person, or to a group of people. It’s easy to integrate to your Android app. It uses Opus Codec that is very efficient in sending the voice to your desired target. It has low data consumption, so it’s suitable for mobile communication.

How to use it?

Now, let’s get into the real code. Open your favorite Android Studio and follow the instructions below.

Installation

To install this SDK in your Android project, you need to do the following steps,

  1. Add jitpack to your project-level gradle file:

    allprojects {
    repositories {
    ...
    maven { url "https://jitpack.io" }
    }
    }
  2. Add the module on your module-level gradle file:

    dependencies {
    implementation 'com.github.SmartWalkieOrg:VoicePing-Walkie-Talkie-AndroidSDK:1.0'
    }
  3. Sync gradle and use it

Initialization

After the SDK is successfully installed into your Android project, you can now start adding walkie-talkie functionality into your app. First, you need to initialize the library in your Application code.

class VoicePingClientApp : Application() {
override fun onCreate() {
super.onCreate()
VoicePing.init(this, "voiceping_sdk_server_url")
}
}

"voiceping_sdk_server_url" can be changed to the real VoicePing server URL. If you want to use our public server, you can change it to “wss://router-lite.voiceping.info”.

Login

Before start sending or receiving voice, you need to login to the SDK using the following code,

VoicePing.connect("your_user_id", "your_company", object : ConnectCallback {
override fun onConnected() {
// Do something
}

override fun onFailed(exception: VoicePingException) {
// Do something
}
})

“your_company” can be changed to your company’s name, or company’s website. Make sure that you insert the same company with your friend if you want to talk to each other. For now, VoicePing SDK doesn’t support talking to other users in another company.

“your_user_id” can be changed to your desired user ID. It should be unique and different from other users. If you insert the same user ID with another user, then the previous user would be disconnected or logged out.

Adding PTT button

To add PTT button, you can add the following code into your layout

<com.smartwalkie.voicepingsdk.VoicePingButton
android:id="@+id/voice_ping_button"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_marginTop="16dp" />

And then, you can set the target using the following code

binding.voicePingButton.receiverId = “receiver_id”
binding.voicePingButton.channelType = ChannelType.PRIVATE

Using custom PTT button

In case you don’t want to use VoicePing built-in PTT button, you can use a custom button. You can do something like this,

binding.voicePingButton.setOnTouchListener { _, motionEvent ->
val eventAction = motionEvent?.action ?: return@setOnTouchListener false
when (eventAction) {
MotionEvent.ACTION_DOWN -> {
VoicePing.startTalking("receiver_id", ChannelType.PRIVATE, null)
return@setOnTouchListener true
}
MotionEvent.ACTION_UP -> {
VoicePing.stopTalking()
return@setOnTouchListener true
}
}
return@setOnTouchListener false
}

Summary

By using VoicePing Android SDK, you can easily add walkie-talkie functionality into your Android app. You don’t need to spend months of work to get it implemented, you probably only need less than 1 hour. It’s open source, so in case you want to modify its underlying technology, you can do it yourself. No need to pay thousands of dollars to get what you want.