{"id":5182,"date":"2021-09-12T00:39:37","date_gmt":"2021-09-12T00:39:37","guid":{"rendered":"https:\/\/www.voxer.com\/blog\/?p=5182"},"modified":"2021-09-12T00:41:00","modified_gmt":"2021-09-12T00:41:00","slug":"how-to-add-live-audio-to-your-android-application","status":"publish","type":"post","link":"https:\/\/www.voxer.com\/blog\/how-to-add-live-audio-to-your-android-application\/","title":{"rendered":"How to add Live Audio to your Android Application"},"content":{"rendered":"<p><span style=\"font-family: helvetica, arial, sans-serif\">Integrating live audio communication and other modern messaging tools into your own Android application is easier than ever with Voxer SDK. Within minutes you can send audio and text messages to a group of users and enable Walkie talkie mode so that audio messages can be sent any time, even when your app is the background.<\/span><\/p>\n<p><span style=\"font-family: helvetica, arial, sans-serif\">Using the Voxer SDK, the complexity of adding synchronous and asynchronous communication is dramatically simplified. Here&#8217;s how you can add communication easily to your iOS application.<\/span><\/p>\n<h2><span style=\"font-family: helvetica, arial, sans-serif\">Import dependencies and add permissions<\/span><\/h2>\n<p><span style=\"font-family: helvetica, arial, sans-serif\">Lets start by adding the most recent Voxer SDK to the <strong>gradle.properties<\/strong> file by adding the <strong>authToken<\/strong> found in the Developer Portal.<\/span><\/p>\n<p><span style=\"font-family: helvetica, arial, sans-serif\">In your module&#8217;s gradle file add following to the dependencies:<\/span><\/p>\n<pre><span style=\"font-family: helvetica, arial, sans-serif\"><code>implementation 'com.github.Voxer:voxer_io_android_sdk:b847af72c4'\r\nimplementation 'org.jetbrains.kotlin:kotlin-stdlib:1.4.31'\r\nimplementation 'androidx.core:core-ktx:1.3.2'\r\nimplementation \"org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.4\"\r\nimplementation \"org.jetbrains.kotlinx:kotlinx-coroutines-core:1.3.9\"\r\n\r\n<\/code><\/span><\/pre>\n<p><span style=\"font-family: helvetica, arial, sans-serif\">In your app level gradle file, add following under repositories:<\/span><\/p>\n<pre><span style=\"font-family: helvetica, arial, sans-serif\"><code>maven { url '&lt;https:\/\/jitpack.io&gt;' }\r\n<\/code><\/span><\/pre>\n<p><span style=\"font-family: helvetica, arial, sans-serif\">In your app level gradle file add following under allprojects -&gt; repositories<\/span><\/p>\n<pre><span style=\"font-family: helvetica, arial, sans-serif\"><code>maven {\r\n                url '&lt;https:\/\/jitpack.io&gt;'\r\n                credentials { username 'jp_6025ebstlo9iolugpmh8vj0ki9' }\r\n            }\r\n<\/code><\/span><\/pre>\n<p><span style=\"font-family: helvetica, arial, sans-serif\">Next initialize the Voxer SDK by adding the following snippet:<\/span><\/p>\n<pre><span style=\"font-family: helvetica, arial, sans-serif\"><code class=\"language-jsx\">Voxer.getInstance(application)\r\n<\/code><\/span><\/pre>\n<p><span style=\"font-family: helvetica, arial, sans-serif\">Enable record permission to allow Voxer to record audio:<\/span><\/p>\n<pre><span style=\"font-family: helvetica, arial, sans-serif\"><code>uses-permission android:name=\"android.permission.RECORD_AUDIO\"\r\n<\/code><\/span><\/pre>\n<p><span style=\"font-family: helvetica, arial, sans-serif\">Now we can add authentication by logging into the Voxer network with:<\/span><\/p>\n<pre><span style=\"font-family: helvetica, arial, sans-serif\"><code>Voxer.getInstance(application).login (username,appId, appSecret) \r\n                { success -&gt;\r\n                  if (success) { \/\/handle successfull login }\r\n                  else         { \/\/handle login failure }\r\n                }\r\n<\/code><\/span><\/pre>\n<p>&nbsp;<\/p>\n<h2><span style=\"font-family: helvetica, arial, sans-serif\">Start a new conversation and send messages<\/span><\/h2>\n<p><span style=\"font-family: helvetica, arial, sans-serif\">Now that you have initialized the Voxer SDK and logged into the Voxer network, you can now start a chat and send text and audio messages.<\/span><\/p>\n<p><span style=\"font-family: helvetica, arial, sans-serif\">First start by creating a new chat with a unique list of users by adding the following:<\/span><\/p>\n<pre><span style=\"font-family: helvetica, arial, sans-serif\"><code>voxer.startConversationWith(otherUserIds, lifecycle, conversationStarterCallback)\r\n<\/code><\/span><\/pre>\n<p><span style=\"font-family: helvetica, arial, sans-serif\">Now you can send a text message with the following snippet:<\/span><\/p>\n<pre><span style=\"font-family: helvetica, arial, sans-serif\"><code>conversation.sendTextMessage(text, messageCallback)\r\n<\/code><\/span><\/pre>\n<p><span style=\"font-family: helvetica, arial, sans-serif\">To use the above API with an UI element you can use the following example:<\/span><\/p>\n<pre><span style=\"font-family: helvetica, arial, sans-serif\"><code>btnSendMessage.setOnClickListener {\r\n                val messageBody = etStartTyping.text.toString()\r\n                sendTextMessage(messageBody) {\r\n                btnSendMessage.hideKeyboard()\r\n                }\r\n                etStartTyping.setText(\"\")\r\n                }\r\n<\/code><\/span><\/pre>\n<p><span style=\"font-family: helvetica, arial, sans-serif\">To send an audio message use the following:<\/span><\/p>\n<pre><span style=\"font-family: helvetica, arial, sans-serif\"><code>conversation.startRecording( onRecordingStarted = { \/\/ refresh the list of messages },\r\n              messageCallbacks = MessageCallbacks())\r\n<\/code><\/span><\/pre>\n<p><span style=\"font-family: helvetica, arial, sans-serif\">To stop sending audio message add:<\/span><\/p>\n<pre><span style=\"font-family: helvetica, arial, sans-serif\"><code>conversation.stopRecording()\r\n<\/code><\/span><\/pre>\n<h2><span style=\"font-family: helvetica, arial, sans-serif\">Conclusion<\/span><\/h2>\n<p><span style=\"font-family: helvetica, arial, sans-serif\">Congratulations! You have now added live audio and text messaging to your application with a few lines of code using the Voxer SDK. If you don&#8217;t have access to a Voxer Developer Portal you can sign up to join the beta program here: <a href=\"https:\/\/get.voxer.com\/sdk\/\">https:\/\/get.voxer.com\/sdk\/<\/a><\/span><\/p>\n<p><span style=\"font-family: helvetica, arial, sans-serif\">Learn more about integrating live audio into your iOS applications <a href=\"https:\/\/www.voxer.com\/blog\/how-to-add-live-audio-to-your-ios-application-with-voxer-sdk\/\">here<\/a>.<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Integrating live audio communication and other modern messaging tools into your own Android application is easier than ever with Voxer..<\/p>\n","protected":false},"author":3,"featured_media":5184,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[179,4897,1,286819650],"tags":[641922,128577,3301,659313400],"yst_prominent_words":[659313435,659313431,659313430,659311642,659313451,659311948,659311949,659313434,659313433,659313436,659313432,659311801,659313392,659311837,659313409,659313402,659313407,659313391],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.voxer.com\/blog\/wp-json\/wp\/v2\/posts\/5182"}],"collection":[{"href":"https:\/\/www.voxer.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.voxer.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.voxer.com\/blog\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/www.voxer.com\/blog\/wp-json\/wp\/v2\/comments?post=5182"}],"version-history":[{"count":6,"href":"https:\/\/www.voxer.com\/blog\/wp-json\/wp\/v2\/posts\/5182\/revisions"}],"predecessor-version":[{"id":5189,"href":"https:\/\/www.voxer.com\/blog\/wp-json\/wp\/v2\/posts\/5182\/revisions\/5189"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.voxer.com\/blog\/wp-json\/wp\/v2\/media\/5184"}],"wp:attachment":[{"href":"https:\/\/www.voxer.com\/blog\/wp-json\/wp\/v2\/media?parent=5182"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.voxer.com\/blog\/wp-json\/wp\/v2\/categories?post=5182"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.voxer.com\/blog\/wp-json\/wp\/v2\/tags?post=5182"},{"taxonomy":"yst_prominent_words","embeddable":true,"href":"https:\/\/www.voxer.com\/blog\/wp-json\/wp\/v2\/yst_prominent_words?post=5182"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}