Message Games On Android

broken image


In this tutorial, we're going to be building a realtime group chat for Android using the Scaledrone Java API Client. It will work very similarly to apps such as WhatsApp, Facebook Messager and LINE.

These iOS Android cross-platform games are not only popular but also wanted the most by the users. Top 16 iOS Android Cross-Platform Games Below are the top 16 apps that are considered in this regard to be the best and the most used cross-platform games. It is also to be noted that the numbering has been done based on the game's popularity. Using APKPure App to upgrade Scary Text Messages, fast, free and save your internet data. The description of Scary Text Messages Scary Text Stories App lets you read yarn scary text stories on your phone. These are gripping, edge-of-your seat thrillers that will keep you reading for hours. Private message box; Hide SMS. His secret texting app for android can conceal private. One of the key differences between iPhone and Android is Android devices can't use iMessage. That's true, but if you have the right software, the right kind of computer, and some technical savvy, or at least an appetite for experimentation, it's actually possible to set up iMessage for your Android phone. Google Brings Game-Changing Update for Messages: US Users Can Enjoy Rich Communication Services (RCS) on Android Google is rolling out a major update for messaging on its Android devices from Thursday and looks like the features are quite similar to the ones enjoyed by iPhone users on iMessage.

You can find the full source code on GitHub.

This tutorial will teach you:

  • How to build a fully functional group chat.
  • Designing the UI elements such as chat bubbles and text inputs.
  • How to use Scaledrone as the realtime backend of your app.
    The project might seem daunting at first, but the messaging code outside of the layout files is pretty short.

Setting up the project

Start by creating a new Android project. We are using Android Studio, but this tutorial will work with any IDE of choice.

Import the Scaledrone module

To add the Scaledrone dependency to your app, you need to add it to your build.gradle file.

For Android to allow us to connect to the internet, we need to add the internet permission to the manifests/AndroidManifest.xml file:

Defining the UI layout

To start with the UI layout let's build the empty state. It consists of:

An empty ListView into where the messages will go
An EditText where the user can type their message
And finally, an ImageButton as a button to send the message

The base layout is defined in /res/layout/activity_main.xml:

String constants are defined in /res/layout/activity_main.xml:

The icon for the send button is defined in /res/drawable/ic_send_black_24dp.xml:

Next up, chat bubbles!

Message Games On Android

Our chat app is going to have two type of chat bubbles: a bubble for messages sent by us and bubbles for messages sent by others.

Chat bubble sent by us

The messages sent by us will look dark and be aligned to the right. We're using a drawable to get the border radius effect.

/res/drawable/my_message.xml:

The message itself is just a simple TextView aligned to the right.

/res/layout/my_message.xml:

Chat bubble sent by others

The chat bubble sent by others within the group chat will be light and aligned to the left. In addition to the bubble itself, we will show an avatar (as a simple full-color circle) and the name of the user.

For the avatar let's define a circle shape under /res/drawable/circle.xml:

And for the bubble let's create a shape with curved corners and the sharp corner on the left. This goes in /res/drawable/their_message.xml:

Putting it together their message bubble layout under /res/layout/their_message.xml will look like this:

Hooking up the realtime messaging logic

We're finally done with the layout and can get to the interesting part!

Let's find the EditText view from our layout and extend Scaledrone's RoomListener so we could receive messages. Most of the methods will have minimal code in them, and we'll fill them up as the tutorial goes along.

Connecting to Scaledrone

If you don't have a Scaledrone account yet, open up Scaledrone.com and create a new free account. To successfully connect to Scaledrone you need to get your own channel ID from the Scaledrone's dashboard. To do that go to the dashboard and click the big green +Create Channel button to get started. You can choose Never require authentication for now. Copy the channel ID from the just created channel and replace CHANNEL_ID_FROM_YOUR_SCALEDRONE_DASHBOARD with it.

Connecting to Scaledrone can happen within the onCreate() method, right after we have set up the UI. Scaledrone gives us the ability to attach arbitrary data to a user (users are called members in Scaledrone lingo), we're going to be adding a random name and color.

You might have noticed that we named our name Scaledrone room observable-room. You can name the room anything you want, a single user can actually connect to an infinite amount of rooms to provider for all sorts of application scenarios. However in order for messages to contain the info of the sender the room name needs to be prefixed with observable-. Read more.

To create the MemberData let's implement the getRandomName() and getRandomColor() functions as well as the MemberData class itself.

For the sake of keeping this tutorial simple, we'll define a random username on the client side of the application. Later you can add fancy login functionality to your app. To create a random name, we pre-define two lists of random adjectives and nouns, then combine them randomly.

The random color function will be generating a random seven-character color hex such as #FF0000.

The MemberData Sims 4 game download for pc free. class is super minimal and will later be serialized into JSON and sent to users by Scaledrone.

Sending messages

To send (or publish) the message to the Scaledrone room we need to add a onClick() handler to the ImageButton in the activity_main.xml file.

Let's add the sendMessage() function to the MainActivity. If the user has input something we send the message to the same observable-room as we subscribed to above. After the message has been sent we can clear the EditText view for convenience.

Scaledrone will take care of the message and deliver it to everyone that has subscribed to the observable-room room in your channel.

Displaying messages

As seen in the layout file the messages are going to be displayed via ListView. To use a ListView you need to create a class that extends android.widget.BaseAdapter. This class is then used as the state of the ListView.

Let's define our MessageAdapter as well as the Message class itself. The Message class will hold all the needed info to render a single message.

The MessageAdapter defines how we render our rows within the ListView.

Receiving messages

Best Android Games All Time

Now that we can display and render our chat bubbles we need to hook up the incoming messages with the MessageAdapter that we just created. We can do that by going back to the MainActivity class and finishing the onMessage() method.

Scaledrone uses the popular Jackson JSON library for serializing and parsing the messages, and it comes bundled with the Scaledrone API client. Please see the Jackson docs for best practices on how to parse the incoming Scaledrone messages and users data.

And we're done!

Facebook Games On Messenger

Hopefully, this tutorial helped you build your very own chat app. You can find the full source code or run the working prototype on GitHub. If you have any questions or feedback feel free to contact us.

This tutorial only scratched what Scaledrone can do for you and is the ideal basis for any of your future realtime needs.

Texting Games For Kids

Best laptop for game development 2015. Looking to build the same app for iOS using Swift? Check out our iOS chat tutorial.

Last updated February 5th 2019. Now using Scaledrone client 0.6.0.





broken image