<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Samyak on Medium]]></title>
        <description><![CDATA[Stories by Samyak on Medium]]></description>
        <link>https://medium.com/@samyak-jain?source=rss-1044133cfe0e------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*ns66kKwJxLLYtOzKrWe1WA.jpeg</url>
            <title>Stories by Samyak on Medium</title>
            <link>https://medium.com/@samyak-jain?source=rss-1044133cfe0e------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 12:25:54 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@samyak-jain/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Building Scalable UI for Android using Agora]]></title>
            <link>https://medium.com/agora-io/building-scalable-ui-for-android-using-agora-1f1ca8053d74?source=rss-1044133cfe0e------2</link>
            <guid isPermaLink="false">https://medium.com/p/1f1ca8053d74</guid>
            <dc:creator><![CDATA[Samyak]]></dc:creator>
            <pubDate>Wed, 23 Dec 2020 11:32:30 GMT</pubDate>
            <atom:updated>2021-03-08T18:02:26.279Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-xOdL3ykeB5JwgvYHOJdcA.png" /></figure><p>One of the biggest challenges facing any developer is building applications that can scale. Making a video-conferencing application that can scale is especially challenging because video data is pretty heavy. And as the number of participants rises, it becomes increasingly difficult to make sure that your application can keep up.</p><p>In this tutorial, I use Agora to build an application that can scale to up to 17 users by optimizing the bandwidth usage of the video streams.</p><blockquote>TLDR: You can get the source code for the demo on <a href="https://github.com/AgoraIO-Community/Scalable-UI-Android">GitHub</a>.</blockquote><h3>Prerequisites</h3><ol><li><a href="https://developer.android.com/studio">Android Studio</a></li><li>An Agora developer account (see <a href="https://www.agora.io/en/blog/how-to-get-started-with-agora?utm_source=medium&amp;utm_medium=blog&amp;utm_campaign=building_scalable_ui_for_android_using_agora">How To Get Started with Agora</a>)</li><li>Basic knowledge of Kotlin and Android Development</li></ol><h3>Project Setup</h3><ol><li>Open Android Studio, create a project, and select the template as “Empty Activity”:</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*CVMbJJ5ru5D_rOL5GNcqhQ.png" /></figure><p>2. Give a suitable name for your application and click Finish.</p><p>3. Add the necessary dependencies to your app build.gradle file:</p><pre>implementation &#39;io.agora.rtc:full-sdk:3.1.3&#39;<br>implementation &#39;androidx.recyclerview:recyclerview:1.1.0&#39;</pre><p>4. Add the relevant permissions to your manifest:</p><pre>&lt;uses-permission android:name=&quot;android.permission.INTERNET&quot; /&gt;<br>&lt;uses-permission android:name=&quot;android.permission.RECORD_AUDIO&quot; /&gt;<br>&lt;uses-permission android:name=&quot;android.permission.CAMERA&quot; /&gt;</pre><p>All done! It’s time to start building the application.</p><h3>Build</h3><p>Now we build the application. I’ll show you how to build the UI for the local video and then put all the remote views in a grid layout by using a RecyclerView.</p><p>The structure for the Kotlin files is pretty simple:</p><pre>.<br>├── MainActivity.kt<br>└── ui<br>    └── RemoteViewAdapter.kt</pre><p>I’ll discuss the RemoteViewAdapter more later on.</p><h4><strong>Setting Up the Main Activity</strong></h4><p>We’ll first do some basic setup of the main activity so that you can see how this activity is structured:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/72f0fdeab0f1f21b5ed28bd9a278374f/href">https://medium.com/media/72f0fdeab0f1f21b5ed28bd9a278374f/href</a></iframe><p>This is a basic skeleton of the project. The App ID should be familiar if you followed the guide I have linked to above. The Channel can be any string. The important bit is that if any client wants to talk to another client, they have to be on the same channel. For the token, you can get a temporary token by following <a href="https://docs.agora.io/en/Agora%20Platform/token?platform=Android&amp;changePlatformAlert=Android#generate-a-token">this guide</a>. For production use cases, you need to <a href="https://docs.agora.io/en/Video/token_server">set up a token server</a>.</p><p>The workflow of the application looks like this:</p><ol><li>We check if the required permissions are already granted.</li><li>If the condition is true, we call the <em>initializeApplication</em> method, which will contain the bulk of our work.</li><li>If the condition is false, we request the permissions. Android then brings up the permission overlay.</li><li>After the user interacts with it, the <em>onRequestPermissionsResult</em> callback is called. We can then call <em>initializeApplication</em> if the permissions are granted.</li></ol><h4><strong>Asking for the Relevant Permissions</strong></h4><p>First, we write the logic for checking if the required permissions are already granted:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a8a2aa6c15f16f0de62d22c20d038e8e/href">https://medium.com/media/a8a2aa6c15f16f0de62d22c20d038e8e/href</a></iframe><p>We then write the logic for the method that is called when we want to request the permissions:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/3392b4437b4a35b196983075d41e61b2/href">https://medium.com/media/3392b4437b4a35b196983075d41e61b2/href</a></iframe><p>Finally, we write the logic for the callback that is executed when the user has interacted with the permission overlay:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/7bb8aeb3fb5be2b3eb9675ae39b0c30f/href">https://medium.com/media/7bb8aeb3fb5be2b3eb9675ae39b0c30f/href</a></iframe><p>If all the required permissions are granted, we call the <em>initializeApplication</em> method. However, if they are not granted, we call <em>finish</em> to destroy the activity.</p><h4><strong>Setting Up the Layout</strong></h4><p>Before we jump into implementing the final method of the application, let’s finish designing the UI. For the sake of simplicity, I’ve kept the UI minimal.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ad533f848fbeb7cdcaeb827a2d48f1ad/href">https://medium.com/media/ad533f848fbeb7cdcaeb827a2d48f1ad/href</a></iframe><p>The FrameLayout here is the container into which the SurfaceView for the local video is injected. SurfaceView is where Agora usually renders its streams on Android. The RecyclerView will be used to display a grid of videos of the remote users. The Guideline is used here to divide the percentage of screen real estate used by each component.</p><h4><strong>Setting Up the RtcEngine</strong></h4><p>It’s time to start implementing the <em>initializeApplication</em> method. Here we have the core application logic:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e483f85db2c89ede19e0d8a3985533ac/href">https://medium.com/media/e483f85db2c89ede19e0d8a3985533ac/href</a></iframe><p>We also need to make sure to add the following property to our activity:</p><pre>private var mRtcEngine: RtcEngine? = null</pre><p>So, the first thing we do is create an RtcEngine object by giving it our App ID (which we discussed above and an event handler (which we will discuss soon). We do some basic configuration such as enabling the video and setting parameters like resolution, FPS, bitrate, and orientation. We set up our local video and then join the channel. And we enable dual-stream.</p><p><em>Note: This guide does not implement token authentication which is recommended for all RTE apps running in production environments. For more information about token based authentication within the Agora platform please refer to this guide: </em><a href="https://bit.ly/3sNiFRs"><em>https://bit.ly/3sNiFRs</em></a></p><p>Dual-stream is an Agora feature that allows a client to publish two streams at the same time. One stream is for a higher resolution and bitrate, and the other stream is for a lower resolution and bitrate. With this dual-stream setup, when a remote client subscribes to your stream, they can switch to a lower stream based on their bandwidth requirements.</p><p>Now let’s set up the remote videos.</p><h4><strong>Setting Up the Remote Videos</strong></h4><p>We will now make a grid layout of videos. We use RecyclerView to do this because we can’t load all the remote users into memory at the same time. Using RecyclerView allows us to lazy-load the required streams.</p><p>First, we create our adapter:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f4560bd8ac261d81abd887846661b3aa/href">https://medium.com/media/f4560bd8ac261d81abd887846661b3aa/href</a></iframe><p>We are doing three main things:</p><ol><li>Creating the ViewHolder in <em>onCreateViewHolder</em> method</li><li>Setting up the remote video in the <em>onBindViewHolder</em> method</li><li>Muting the remote video in the <em>onViewRecycled</em> method</li></ol><p>Now that we have created our RecyclerView adapter, we can set up the RecyclerView in our <em>initializeApplication </em>method:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6b89b29917d4f2c667f9a5f592adadb2/href">https://medium.com/media/6b89b29917d4f2c667f9a5f592adadb2/href</a></iframe><p>We use the GridLayoutManager to get our RecyclerView to use a grid layout. We set the span count to 2 so that we have a total of two rows in the grid. We set the orientation to horizontal.</p><p>Now we create an instance of the adapter we just wrote. Make sure to add the following properties to the activity:</p><pre>private lateinit var remoteViewAdapter: RemoteViewAdapter<br>private var uidList = ArrayList&lt;Int&gt;()</pre><p>We write the contents of the callbacks in the IRtcEngineEventHandler:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/a2ab86dc3e47dd1a15704ea8b40f4ad5/href">https://medium.com/media/a2ab86dc3e47dd1a15704ea8b40f4ad5/href</a></iframe><p>In the <em>onUserJoined</em> callback, we are doing the following:</p><ul><li>Muting the remote video stream.</li><li>Adding the UID of the remote video to a list of UIDs that we use as the dataset of the RecyclerView. We need to make sure that the data is not accessed by multiple threads at the same time, so we use a mutex to maintain a lock.</li><li>Checking if the number of remote users has grown to four to know whether to switch to using the lower stream in dual-stream mode.</li><li>Notifying the RecyclerView adapter that a new item is added.</li></ul><p>In the <em>onUserOffline</em> callback, we are doing the following:</p><ul><li>Getting the index of the UID to remove and then removing the UID from the list of UIDs that we are maintaining</li><li>Removing the remote video stream from being rendered into the SurfaceView</li><li>Switching back to the higher stream in the dual-stream mode if the number of remote users shrinks to three</li><li>Notifying our RecyclerView adapter to remove the item</li></ul><p>We need to add the following properties to our activity:</p><pre>private val handler = Handler(Looper.getMainLooper())<br>private val lock = ReentrantLock()</pre><h4>Cleaning up</h4><p>Finally, it is time to write the onDestroy method. We clean up all the resources relevant to Agora here:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/013cc081252884ed293bd2ace86647de/href">https://medium.com/media/013cc081252884ed293bd2ace86647de/href</a></iframe><p>There you go! You should now have everything necessary to run the application.</p><h3>Testing</h3><p>Before you build the app, make sure you did the following:</p><ul><li>You added your App ID to the APP_ID variable.</li><li>You added your channel name to CHANNEL.</li><li>If your project has App Certificate enabled, you used your token in the TOKEN variable.</li><li>You followed all the instructions correctly, like adding the correct dependencies to the build.gradle, adding the permissions to your manifest, and so on.</li></ul><p>After you build the app, you should see something like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/606/1*zc6r-YR7rgRB9P8G3-g_KA.jpeg" /></figure><h3>Done!</h3><p>Congratulations! You have learned how to make an application that has all the necessary optimizations to have scalable video-conferencing capabilities.</p><p>You can get the entire codebase from this <a href="https://github.com/AgoraIO-Community/Scalable-UI-Android">repository</a>.</p><p>If you want to test the app with a web client, you can use the following hosted demo, which has dual stream enabled: <a href="https://agora-scalableui-android-test.netlify.app/">demo</a></p><h3>Other Resources</h3><p>For more information about Agora.io applications, take a look at the <a href="https://docs.agora.io/en/Video/start_call_android?platform=Android">Agora Video Call Quickstart Guide</a> and <a href="https://docs.agora.io/en/Video/API%20Reference/java/index.html">Agora API Reference</a>.</p><p>To learn more about dual stream, you can take a look at our guide on <a href="https://docs.agora.io/en/Interactive%20Broadcast/fallback_android?platform=Android">stream fallback</a>.</p><p>I also invite you to join the Agora.io Developer Slack community.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1f1ca8053d74" width="1" height="1" alt=""><hr><p><a href="https://medium.com/agora-io/building-scalable-ui-for-android-using-agora-1f1ca8053d74">Building Scalable UI for Android using Agora</a> was originally published in <a href="https://medium.com/agora-io">Agora.io</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to add Live Broadcasting and Chat to your Android app using Agora.io]]></title>
            <link>https://medium.com/agora-io/how-to-add-live-broadcasting-and-chat-to-your-android-app-using-agora-io-be278c48a4a?source=rss-1044133cfe0e------2</link>
            <guid isPermaLink="false">https://medium.com/p/be278c48a4a</guid>
            <category><![CDATA[android]]></category>
            <category><![CDATA[coding]]></category>
            <category><![CDATA[api]]></category>
            <category><![CDATA[chat]]></category>
            <category><![CDATA[broadcasting]]></category>
            <dc:creator><![CDATA[Samyak]]></dc:creator>
            <pubDate>Wed, 24 Apr 2019 21:20:07 GMT</pubDate>
            <atom:updated>2021-03-08T13:34:54.889Z</atom:updated>
            <content:encoded><![CDATA[<h3>Add Live Broadcasting and Messaging to your Android app using Agora.io</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/630/1*dfAd0ZEti1paMsU0kcH-7g.png" /></figure><p>Implementing live broadcasting can prove to be a very difficult task especially if scalability is an important concern. Agora makes our lives much easier by providing an easy to use SDK that also gives developers the low-level control of exactly how we want the streaming service to work.</p><p>Using the Agora platform, you don’t have to worry about the technical networking details since it is abstracted away when using the SDK. You enjoy features like low latency of ~200 ms and smart network traffic routing.</p><p>In this tutorial, we’ll be making a simple android app that allows you to join a live broadcast (either as a host or audience) and also create a chat room where all the participants can talk to one another.</p><p>Let’s get started!</p><h3>Step 1. Create an Agora.io Account</h3><p>Navigate to the <a href="https://sso.agora.io/en/signup/">Agora.io Dashboard</a> and create a new account and log in.</p><p>Navigate to ‘Projects’ tab and create a new project by clicking the Add New Project button.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1000/1*-DU6CVwUrFS6R60ZJkq9-w.png" /></figure><p>You will be able to see your App ID for this project. This will be used to authenticate your requests while using the SDK.</p><h3>Step 2. Clone the Sample App from Github</h3><p>I won’t be going over the UI building part of the app so if you want to follow along with the tutorial, I have created a simple UI for our application. You can head over to GitHub to get the <a href="https://github.com/samyak-jain/agora_broadcast_tutorial">sample app</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rNMpX9hmtIxGk2n2VDEv_g.png" /></figure><p>If you want the complete app, you can switch to the <a href="https://github.com/samyak-jain/agora_broadcast_tutorial/tree/completed">completed branch</a> of the repo.</p><h3>Step 3. Add your App ID to the project</h3><p>Open the project in Android Studio. Go to the “strings.xml” file and add your App ID to the “private_app_id” resource.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*-uCdiHPOSTW2gOXhBuwJMg.png" /></figure><p>Make sure to then sync your Gradle files.</p><p>Now, it’s time to start the fun part. We’re gonna start coding up the required files needed to make the broadcast.</p><h3>Step 4. Getting into the Code</h3><p>Our ‘activity’ java files will be having the following directory structure</p><pre>.<br>├── activity<br>│   ├── LoginActivity.java<br>│   └── MessageActivity.java<br>├── adapter<br>│   └── MessageAdapter.java<br>├── MainActivity.java<br>├── model<br>│   ├── MessageBean.java<br>│   └── MessageListBean.java<br>├── sginatutorial<br>│   └── AGApplication.java<br>├── utils<br>│   ├── Constant.java<br>│   └── ToastUtils.java<br>└── VideoActivity.java</pre><h3>AGApplication.java</h3><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/6695f558a8e027a9ab97231f8a066d51/href">https://medium.com/media/6695f558a8e027a9ab97231f8a066d51/href</a></iframe><p>We have made sure to extend the Application class since we want this to run before any activity has begun. In this snippet, we also instantiate the Signaling SDK in this class.</p><p>The Agora Signaling SDK allows us to easily add chat into your application.</p><h3>MainActivity.java</h3><p>Now, let’s create a file called MainActivity.java. This file contains the logic of what the users see when they first open the app.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b22798239af0212de6ec7df0fd9190b7/href">https://medium.com/media/b22798239af0212de6ec7df0fd9190b7/href</a></iframe><p>The main UI elements include a radio button and a text box. The radio button allows the user to decide whether they want to be a host or an audience for the broadcast. The text box allows the user to input the channel name they wish to join.</p><p>Let’s define some constants first which will be useful when sending data to the next activity.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/80639cc32e2da32536b1478d03031d93/href">https://medium.com/media/80639cc32e2da32536b1478d03031d93/href</a></iframe><p>We’ll be adding 2 methods to our class.</p><p>The first method will be called when the user chooses an option from the radio buttons. We will be setting a variable accordingly. We will be setting it to a value that will determine whether the user is a broadcaster or an audience.</p><p>We then implement a function that is called when the user submits the details. Here we will be getting all the details we need and sending them over to the next activity.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/50718b3b880ece7a5ade219b436c993d/href">https://medium.com/media/50718b3b880ece7a5ade219b436c993d/href</a></iframe><h3>VideoActivity.java</h3><p>Next, we create the activity that will be following the MainActivity called VideoActivity.java file. This is the file that will be containing the code for the live broadcasting.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ea71a2031df360f9ec84352d14fbc7a3/href">https://medium.com/media/ea71a2031df360f9ec84352d14fbc7a3/href</a></iframe><p>So first, we are adding some variables that we will be using throughout the class.</p><p>We then modify the onCreate method to get the data that we had passed in from the previous activity.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2b2fec98304673fb0822fff71e22dd1c/href">https://medium.com/media/2b2fec98304673fb0822fff71e22dd1c/href</a></iframe><p>We now define the initAgoraEngineAndJoinChannel method that will call all the other methods needed in the lifecycle of the broadcast. We also define the event handler that will decide what methods to call when a remote user joins or leaves or when the remote feed is muted.</p><p>We then define the initalizeAgoraEngine method that will create an instance of RtcEngine class</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/5b2477adf48c8e351cded5fd703a5856/href">https://medium.com/media/5b2477adf48c8e351cded5fd703a5856/href</a></iframe><p>We implement some useful methods that allow we use when the audio or video is mute. We also implement a method which is needed to show the remote feed. I have already created the FrameLayout. We steam the remote video in that.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/437880c214405c9455dd8455e144bd4e/href">https://medium.com/media/437880c214405c9455dd8455e144bd4e/href</a></iframe><p>We now implement the setupVideoProfile method for the VideoActivity that allows you to configure the video that you will be streaming in the app. You can set the Frame rate, Video Resolution etc…</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/dbdbd47c6d04e36e696dacff7fe0dec3/href">https://medium.com/media/dbdbd47c6d04e36e696dacff7fe0dec3/href</a></iframe><p>Similar to how we implemented the function to set up the remote video, we implement the same to set up the local video.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e4b73d0b824cc9ee28f40f4409f8e885/href">https://medium.com/media/e4b73d0b824cc9ee28f40f4409f8e885/href</a></iframe><p>We then implement some simple methods for joining and leaving the channel.</p><p><em>Note: This guide does not implement token authentication which is recommended for all RTE apps running in production environments. For more information about token based authentication within the Agora platform please refer to this guide: </em><a href="https://bit.ly/3sNiFRs"><em>https://bit.ly/3sNiFRs</em></a></p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/be15f45b8b4d44b1bd6829e0b5e4c2b2/href">https://medium.com/media/be15f45b8b4d44b1bd6829e0b5e4c2b2/href</a></iframe><p>We then add the onDestroy method for releasing the resources that we have used.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/9f60d8b80c12789df2648f0b0bf78e15/href">https://medium.com/media/9f60d8b80c12789df2648f0b0bf78e15/href</a></iframe><p>We also add some methods for toggling the camera from front to rear and a method to end the call.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/03577d7801d085445eb8cde608cc6774/href">https://medium.com/media/03577d7801d085445eb8cde608cc6774/href</a></iframe><p>We then add a method called onChatClicked that will be invoked when we hit a chat button. This will allow users in the broadcast to chat among themselves. So we will be starting another activity for that.</p><h3>LoginActivity.java</h3><p>This is the activity that will deal with the Agora Signaling API that is used for chat applications.</p><p>Under the activity folder, create a new class called LoginActivity.java</p><p>We need to first define some variables we’ll be using throughout the class and we’ll also need to define the onCreate method where we can get the data that were passed in from the previous activity.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/68180ef0d262bf5aaff570b393bae095/href">https://medium.com/media/68180ef0d262bf5aaff570b393bae095/href</a></iframe><p>We then add methods to Join the Signaling channel and also a method to log in. We need to add them to the LoginActivity class.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/baf395df7f8302ce6641582855e9293e/href">https://medium.com/media/baf395df7f8302ce6641582855e9293e/href</a></iframe><p>Next, we make the callback handler for simple tasks like logging in, logging out, etc…</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/e66a02f269cb19c40b133b6015f421f2/href">https://medium.com/media/e66a02f269cb19c40b133b6015f421f2/href</a></iframe><p>We then add an onResume method where we call the callback. We also add a method called onActivityResult where we’ll be releasing the resources. We also add a couple of more methods to release the resources.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/4c62942b3cbbb2fa34bdb6d4b9e3587b/href">https://medium.com/media/4c62942b3cbbb2fa34bdb6d4b9e3587b/href</a></iframe><h3>Final Step: Build your app</h3><p>Now that this is done, build your application and you should see something like this</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/818/1*xGxss7no9lOR79yyiCdOIg.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/978/1*rgG60sL7Idw0X5oCzJO5Dg.png" /></figure><p>If you have any questions, head over to the <a href="https://join.slack.com/t/agoraiodev/shared_invite/enQtNDI1NzExNzQ0NDcwLTlmMGRiYzZlNzAwZjBhNTVhOThlMzk1NjhjNTA4Zjc1YzM4MWMzNDQzYzRlMmFiMWZhN2E5ZDVlMTkyMGYwY2U">Agora Slack Channel</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=be278c48a4a" width="1" height="1" alt=""><hr><p><a href="https://medium.com/agora-io/how-to-add-live-broadcasting-and-chat-to-your-android-app-using-agora-io-be278c48a4a">How to add Live Broadcasting and Chat to your Android app using Agora.io</a> was originally published in <a href="https://medium.com/agora-io">Agora.io</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Angelhacks Bangalore — Unsting]]></title>
            <link>https://medium.com/agora-io/angelhacks-bangalore-unsting-6ad351e57d52?source=rss-1044133cfe0e------2</link>
            <guid isPermaLink="false">https://medium.com/p/6ad351e57d52</guid>
            <category><![CDATA[drones]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[video-chat]]></category>
            <category><![CDATA[android]]></category>
            <dc:creator><![CDATA[Samyak]]></dc:creator>
            <pubDate>Sat, 27 Oct 2018 00:01:47 GMT</pubDate>
            <atom:updated>2018-10-27T00:01:47.557Z</atom:updated>
            <content:encoded><![CDATA[<h3>The Story of Team unSting: Why &amp; How</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hVsJ4G3FsWUnkcNoM1hUhA.png" /></figure><p>During AngelHack Bangalore this year, our team came up with an idea that would allow us to give back to our community which was devastated by the Chennai floods in 2016. Schools were cancelled for a long time because they were used for housing those who had lost their homes. Our teachers, who helped the relief effort, told us stories of countless people who struggled due to the disaster.</p><p>When we listened to the speakers at AngelHack, all of these memories came back to us and our thoughts aligned. We were inspired to come up with a solution that would aid relief efforts during natural disasters.</p><p>The basic idea consists of deploying several autonomous drones simultaneously. They move together to form a hexagonal grid structure, which allows the drones to maximize area while using the minimum number of drones possible. The drones then use several sensor readings, like those from the camera and heat sensors, to detect pockets of people.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/625/1*EXzKovPzwqqlO58eCLyCqw.png" /></figure><p>Since we came up with the solution at the time of the hack we didn’t have actual drones to use, so we did two things to overcome this hurdle:</p><ul><li>Made a simulation using Unity that shows how the hexagonal mapping and aerial movement would actually look when it is deployed on a drone.</li><li>Used Android Things to run the drone’s algorithms. Since all Android applications can be deployed into Android Things, we used our phones as simulators for the drones.</li></ul><p>Now that we’ve explained how the drones work, let’s dive a little deeper into what makes our platform really special.</p><p>We detect people using a real time object detection algorithm called YOLO (You Only Look Once). This is one of the most recent advancements in the field of computer vision and allows us to find people and their numbers efficiently and accurately. Since it is computationally expensive, the operation cannot be performed on the drone itself. Rather, we use the Agora Platform to stream the camera feed in real time to our servers so that the algorithm can work on the server. (We ran into a major hurdle during AngelHack here too! More on that later 😀)</p><p>We also gather and show data as such:</p><ul><li>Locations of volunteers (using the Volunteer Android app).</li><li>The number of people who are in distress and require help, along with their locations. These data points, we believe, will be invaluable to volunteers who might not know where people need help.</li></ul><p>We also implemented a system of chatting where volunteers can chat, which can help with logistics.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/606/1*MI-6bnpHEi_frKd3rjJwYQ.png" /></figure><p>The important components of our projects:</p><ul><li>A volunteer app powered by Agora</li><li>Streaming video from the drone through the Agora Android SDK</li><li>A server receiving the stream through the Agora Web SDK</li><li>A central dashboard that monitors all the identified data points</li></ul><p>Since we opted to use Android Things, deploying the code in Android (drones simulation) was a breeze. But the server side was a whole other story. Agora’s services greatly reduced our need to write our own video servers and clients for different platforms because Agora had implementations for most platforms. Their services were also easier to implement and had several advantages including:</p><ul><li>Secure communication</li><li>Low latency</li><li>Cross-platform capabilities</li></ul><p>This was very important to us since we were using YOLO on the incoming stream and we had decided to leverage Agora’s platform for smooth integration of the video servers into our deep learning algorithms.</p><p>The most important part of the project was the use of Android in the drones for getting the live camera feed. This allowed us to port the application to an Android Things kit which could be integrated with the drone. Since we didn’t have a drone at that point we made an Android app which we can later port into a drone. The stream from the Android app was read by the server which then applied the YOLO deep learning algorithm to locate humans in each frame of the video stream. Then a few techniques were applied in order to approximate the physical geospatial location of the people from the video feed. We wrote an algorithm which can estimate the location of an object in an aerial image given the bounding boxes and the coordinates of the drone. It was pretty accurate and took factors like the radius of curvature of the Earth into account. The most challenging part was relaying the video feed to the servers that had these algorithms because during the time of development, there was no Agora Server SDK available.</p><p>We tackled the problem in a two-part strategy:</p><ol><li>We strung together a web application that would receive the stream from the Android app and render it in the page using Agora’s Web SDK. This was a normal usage of the web SDK and we deployed it in a static file host.</li><li>In the Python server, we wrote a script that would emulate the browser using Chrome WebDriver and extracted the frames from it. We used the Puppeteer library by Google to accomplish this. Puppeteer gave us a headless chrome instance in which we loaded the previously coded web application and periodically took automated screenshots of the frames and fed them into the deep learning algorithm. All of this was done asynchronously to boost performance.</li></ol><pre>from pyppeteer import launch from PIL<br>import Image<br>import numpy as np<br>async def main(execpath):<br>browser = await launch({&#39;executablePath&#39;: execpath})<br>page = await browser.newPage()<br>await page.goto(&#39;<a href="http://unsting-relay.netlify.com&/#39;">http://unsting-relay.netlify.com&#39;</a>) # Points to Web SDK<br>frames_cnt = 0<br>while(True):<br>initial = time.time()<br>img = await page.screenshot()<br>image = Image.open(io.BytesIO(img)).convert(&#39;RGB&#39;)<br>img = np.array(image)<br>img = np.roll(img, 1, axis=-1)<br>pred = yolo(img) # We pass each frame to perform yolo<br>if len(pred) &gt; 0:<br>img = np.roll(img, 1, axis=-1) view(img, pred)<br>update_locations(pred)<br>await browser.close()</pre><p>We were essentially running client side code on the server. Once the frames were loaded into the Python environment, the rest of the process was comparatively straightforward. We integrated our backend system with the dashboard and volunteer app components of our project.</p><p>All of our hard work was worth it and there is no doubt that making such a product would have been almost impossible without the platform, infrastructure or the guidance that we received from Agora during the hack. We received good support from Agora via their Slack workspace. They really encouraged us to explore the platform. Agora’s adaptive solution fit our needs and allowed us to create our application. We learned so much from Sid, who explained how Agora is completely customizable in every aspect and allows you to even reduces resolution in order to maintain frame rate in a high-latency network. For our project, we wanted all our frames to be captured even on high latency. The resolution tradeoff was viable for us since YOLO tracks humans pretty well even on low resolution images. Our end product was a great start for a really cool project idea and has lots of room for improvement and polish. We are currently concentrating our efforts to make this idea into a sustainable reality.</p><p>In the end, we want our product to be a complete solution that is able to aid people every step of the way. That is why we are further expanding the project. One of the components we are working on is a blockchain-based supply chain that can be used by organizations to track donations that will go to people desperately in need. This supply chain will ensure that the donations that are given by people are guaranteed to reach the people who need it and remove the possibility of corruption from middlemen. This is especially important in developing countries like India where such cases of corruption are very widespread. We are also building alert mechanisms into our product to allow first responders to react to situations faster. This is done using predictive analysis based on weather and disaster data. By doing some time series analysis, it might be possible to help in disaster prediction, which could be a tremendous help to organizations that are trying to help people that are potentially facing disasters.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=6ad351e57d52" width="1" height="1" alt=""><hr><p><a href="https://medium.com/agora-io/angelhacks-bangalore-unsting-6ad351e57d52">Angelhacks Bangalore — Unsting</a> was originally published in <a href="https://medium.com/agora-io">Agora.io</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>