Building An Android App With Java


How To Build An Android Chat App In Java

Developing Android Apps with Java: Build a Flashlight App

Nabil Kazi


There is a tremendous increase in chat applications in the market. The current Covid-19 situation worldwide also played its part in this. Many companies are leveraging existing applications to manage their internal communication. We also saw a rise in custom chat applications. More and more communication applications are being released each day. There cannot be a better time to learn and build one yourself!


If you have never heard of CometChat, the headline on itâs website sums up nicely in one line. Text chat & video calling for your website and apps. It has 2 variants, CometChat Go and CometChat Pro.

  • Go is used for drag and drop chat plugin for your websites and no-code solutions.
  • Pro gives you access to its APIs, SDKs, Components to build your solution with bare minimum development. You can read more about CometChat Pro here.

What weâll cover in this article?

Weâll be building an Android chat application in Java from scratch. From adding CometChat SDK to live chatting!

Below is the overview of what weâll be doing –

  • Adding the CometChat SDK and configuring our project.
  • Implementing user registration
  • Setting up conversations & chat screens
  • Live chat in action!

We would be leveraging CometChatâs Android UI Kit to build our chat app. Iâll show you how this makes the development a breeze!

Letâs start buildingâ¦

Step 1 – Setting up CometChat

Weâll outline the steps from the above document –

So, a typical flow would be â

Change The Background Color Of The Layout

Give your new activity a different background color than the first activity:

  • In colors.xml, add a new color resource:
  • < color name="screenBackground2"> #26C6DA< /color> 
  • In the layout for the second activity, fragment_second.xml, set the background of the ConstraintLayout to the new color.
  • In the Attributes panel:

    Or in XML:

    Your app now has a completed layout for the second fragment. But if you run your app and press the Random button, it may crash. The click handler that Android Studio set up for that button needs some changes. In the next task, you will explore and fix this error.

    Fix Errors If Necessary

    If you edited the XML for the layout directly, you might see some errors.

    The errors occur because the buttons have changed their id and now these constraints are referencing non-existent views.

    If you have these errors, fix them by updating the id of the buttons in the constraints that are underlined in red.

    Don’t Miss: Kroger Coupon App For Android

    Developing An App Using Java For Android

    For expert level users of Java, programming for Android will not be difficult. Let us understand how one can go about developing an application using a step-by-step approach.

  • Creating an Android project in the Eclipse IDE. Here you specify certain project options such as name of the project, what Android version the project will run on, app name, class name, package name and so on.
  • Configure the project and select a launcher icon. This means you are providing workspace details and selecting the appropriate size of the launcher icon.
  • Creating activities is a very important aspect of app development. This activity is nothing but different activities a user gets to do on-screen. After you are done with selecting the type of activities, the project is now open with relevant resource files for you to begin the actual Java for android coding.
  • The user experience elements and the look of your app is defined using the activity_main.xml file in the /res/layout folder from the package. In this file, you will modify the string attributes and add views for the app. You can also add radio buttons or text fields based on the app requirement and design. By right-clicking on the element you added, you can select properties and modify them based on your layout.

    How To Get Started With Java

    [News] Java& Android Development For Beginners Free Download » Free ...
  • Before downloading these tools, try Java out on is an online based coding environment where you can get started coding within minutes! Here is our guide for how to get started with Java on
  • Java JDK’s latest version can be . When installing, select all the default options.
  • Android Studio is a program that enables users to create applications for Android devices. Make sure your computer fulfills the minimum requirements since the software is quite resource intensive. Download it here.
  • Don’t Miss: Bluetooth Hci Snoop Log Android

    How To Get Started With Java Programming

    If you plan on developing Java apps on your desktop computer, then you will need to download and install the JDK.

    You can get the latest version of the JDK directly from Oracle. Once youve installed this, your computer will have the ability to understand and run Java code. However, you will still need an additional piece of software in order to actually write the code. This is the Integrated Development Environment or IDE: the interface used by developers to enter their code and call upon the JDK.

    When developing for Android, you will use the Android Studio IDE. This not only serves as an interface for your Java code, but also acts as a bridge for accessing Android-specific code from the SDK. For more on that, check out our guide to Android development for beginners.

    For the purposes of this Java tutorial, it may be easier to write your code directly into a Java compiler app. You can download these for Android and iOS, or even find web apps that run in your browser. These tools provide everything you need in one place and let you start testing code.

    Introduction To Java For Android Application Development

    Android-based smartphones are in vogue due to the flexibility they offer for customization. Unlike Apples iOS, Google Android offers better user experience in terms of applications. The Android application development kit is an open-source Linux-based operation system, which has its own middleware and key applications. The platform for app development in Android is Java. This means that you use the Java library and code the applications in Java, C, and C++ programming language. But, the most widely used programming language for android application development is Java.

    Read Also: Tap To Pay On Android

    Change Text Display Properties

  • With textview_first still selected in the Component Tree, in the layout editor, in the list of attributes, under Common Attributes, expand the textAppearance field.
  • Change some of the text appearance properties. For example, change the font family, increase the text size, and select bold style.
  • Change the text color. Click in the textColor field, and enter g.
  • A menu pops up with possible completion values containing the letter g. This list includes predefined colors.

  • Select and press Enter.
  • Below is an example of the textAppearance attributes after making some changes.

  • Look at the XML for the TextView. You see that the new properties have been added.
  • Run your app again and see the changes applied to your Hello World! string
  • Explore Width And Height Properties

    How To Create Your First Android Application with Java

    Now that you have a new screen background color, you will use it to explore the effects of changing the width and height properties of views.

  • In fragment_first.xml, in the Component Tree, select the ConstraintLayout.
  • In the Attributes panel, find and expand the Layout section.
  • The layout_width and layout_height properties are both set to match_parent. The ConstraintLayout is the root view of this Fragment, so the “parent” layout size is effectively the size of your screen.

    Tip: All views must have layout_width and layout_height properties.

  • Notice that the entire background of the screen uses the screenBackground color.
  • Select textview_first. Currently the layout width and height are wrap_content, which tells the view to be just big enough to enclose its content
  • Change both the layout width and layout height to match_constraint, which tells the view to be as big as whatever it’s constrained to.
  • The width and height show 0dp, and the text moves to the upper left, while the TextView expands to match the ConstraintLayout except for the button. The button and the text view are at the same level in the view hierarchy inside the constraint layout, so they share space.

  • Explore what happens if the width is match_constraint and the height is wrap_content and vice versa. You can also change the width and height of the button_first.
  • Set both the width and height of the TextView and the Button back to wrap_content.
  • Also Check: Seizure Tracker App For Android

    Building Java Apps For Android

    • Article

    To build your first Android app, follow these steps:

  • Connect to your repository service account .
  • Select a repository and a branch where your app lives.
  • Choose the Android project you want to build.
  • Set up your first build.
  • Note

    For the app to run on a real device, the build needs to be code signed with a valid certificate.


    Due to the recent shutdown of JCenter, certain apps may experience Gradle Task failures when building with App Center. Please view the migration guide provided by Gradle. As a workaround, all instances of jcenter can be removed from the build.gradle file, and replaced with jcenter . Read more about the JCenter Shutdown here.

    Where To Find Help And Support On Your Android App Building Journey

    Android is the most widely used operating system worldwide, and there are plenty of places to get help and support.

    Here are some of the best places to look while on your app building journey.

    Stack Overflow: This is a forum for developers where you can get answers to your app development questions.

    There is also a comprehensive database of Android-related problems that have already been solved. Check out the Android-related questions here.

    Official Android Documentation: Google provides a ton of material about how to create Android apps using Android Studio.

    Once you know the basics of creating an Android app, this is a great tool to help you learn new features and troubleshoot issues. Check it out here.

    Image: Austin Distel/Unsplash

    Reddit Learn Java: This is an active community of people learning Java. Its an excellent place to browse and ask questions about the programming language. Join in the conversation here.

    Reddit Android Dev: This is a large community of Android App Developers. It has plenty of advice about how to get started with building apps. Join the community here.

    GitHub Android: GitHub has plenty of Android code samples that show best practices in different aspects of Android.

    Your Local Area Developer Group: If youre looking for in-person help, many cities around the world have active Android developer groups.

    Also Check: Best Text To Speech App Android

    Create The Applications Directory Structure

    To automate the process of creating these directories, execute the following shell script.

    Bourne-Again Shell / Korn Shell:

    Windows Shell :

    Save the file as mkpdir.bat or and execute the file from the projects root directory as root .

    # *.nixchmod +x ./
    # Windowsmkpdir

    Notice that we created directories for embedded and desktop. We will produce a desktop build, because it takes no additional work to do so. However, we will not produce any builds for embedded devices.

    Create Your Javafx Application

    Build Your First Android App in Java

    Navigate to /src/< platform> /java and begin developing your JavaFx application! Application resources are stored in /src/< platform> /resources.

    You can start with a simple Hello World application or look at the source code that I have put together here. OnyxFx is an application I made, following these instructions, that makes REST calls over HTTP to the OnyxFxAPI. The API, in turn, is a web scraper that will return the statistical data for the NBA® player and season the client specifies. It returns the data as JSON, which is then parsed and displayed to the screen of the mobile app. Feel free to edit it!

    Keep in mind that although you can share source code, you should include custom edits in each copy of the source, should you want to make device specific changes.

    Also note that the underlying compiler does not fully support all Java 8 APIs. If you look very closely at my source code, you will notice that in the iOS version of the source code, I have removed unsupported API such as java.util.function.BiConsumer and java.util.Map.replace.

    Don’t Miss: Top 10 Offline Games For Android

    Do You Need To Learn To Code

    First, you need to learn to code if you want to create an app from scratch. If you dont want to learn to code, you can use an app builder to create one based on a template.

    In the first section of this article, well focus on how you can learn the basics required to code your first app.

    At the end, well show you how you can create an Android app using AppInstitutes drag and drop platform.

    With our app builder, you can create an app in just a few hours. Its the perfect choice for people who dont have the time to learn a programming language needed to code.

    Get Your Ui Ready For The Next Task

    The next task is to make the buttons do something when they are pressed. First, you need to get the UI ready.

  • Change the text of the TextView to show 0 .
  • Change the id of the last button you added, button2, to count_button in the Attributes panel in the design editor.
  • In the XML, extract the string resource to count_button_text and set the value to Count.
  • The buttons should now have the following text and ids:


    Read Also: Video Chat Apps Android To Iphone

    Java App Development Course For Beginners

    Has Java piqued your interest? Join our live online Java classes led by an expert instructor! Our Java classes are very well designed from basic to advanced levels, which enables students to learn Java language concepts all the way through developing apps. The concepts learned in each session will be used to create real-time projects.

    Task: Explore The Layout Editor

    Build an Android App in Java: (1/4) Start with a Map in Mapbox SDK

    Generally, each screen in your Android app is associated with one or more fragments. The single screen displaying “Hello first fragment” is created by one fragment, called FirstFragment. This was generated for you when you created your new project. Each visible fragment in an Android app has a layout that defines the user interface for the fragment. Android Studio has a layout editor where you can create and define layouts.

    Layouts are defined in XML. The layout editor lets you define and modify your layout either by coding XML or by using the interactive visual editor.

    Every element in a layout is a view. In this task, you will explore some of the panels in the layout editor, and you will learn how to change property of views.

    Also Check: How To Add Call On Android

    Adjust The Next Button

    You will adjust the button labeled Next, which Android Studio created for you when you created the project. The constraint between it and the TextView looks a little different, a wavy line instead of a jagged one, with no arrow. This indicates a chain, where the constraints link two or more objects to each other, instead of just one to another. For now, you’ll delete the chained constraints and replace them with regular constraints.

    Java Fundamentals By Pluralsight

    Many learners I come across focus too much on syntax and libraries. They try to memorize these instead of focusing on the principles Java is built upon. Pluralsight introduces you to design patterns that help you code while keeping an eye on the big picture.

    Take this course once you have completed core Java concepts and are ready to start coding. You would learn smart ways to write programs and organize your object according to their usage.

    Recommended Reading: Best Premium Vpn For Android

    How To Make A Cross

    Did you know that you can use Java to make cross platform mobile apps? Yes, pinch yourself, you read that right the first time! Ill teach you the basics of how to use your existing Java knowledge to create performant apps on Android and iOS in 12 easy steps. We will do this all using JavaFX as the GUI toolkit.

    But first, some more foreground. You will need to meet the subsequent requirements to be able to build an application for both Android and iOS. However, if you do not desire to build an iOS application, you can feel free to develop on any x64 bit machine that supports Java SE 8. This project will be a Git repository built with gradle. But you do not need to create a Git repository.

    The following are the requirements:

    • A JDK 1.8 Compliant JVM
    • Android Command Line Tools
    • XCode 9.2
    • Gradle 4.2
    • Git Large File Storage
    • Preferably at least 4G RAM

    Impatient? Want to see an end result? Check out the completed project below.

    My development environment will be Fedora Linux 28 and macOS High Sierra. Now that weve got that out of the way, lets dig in.

    Edit The Welcome Message In The Main Activity

    Create Android App With Java
  • Navigate to the activity_main.xml tab if it is not already open.
  • Make sure that the Design tab is open on the activity_main.xml display.
  • In the project file system on the left side of the window, open the values folder.
  • In the values folder, double-click the strings.xml file.
  • In this file, find the line “Hello world!”.
  • After the “Hello world!” message, add “Welcome to my app!”
  • Navigate back to the activity_main.xml tab.
  • Make sure that your centered text now reads “Hello world! Welcome to my app!”
  • Don’t Miss: Mcafee Security App For Android

    Build An Android App With Html Css And Javascript In Android Studio

    Android is a mobile operating system based on a modified version of the Linux kernel and other open-source software, designed primarily for touchscreen mobile devices such as smartphones and tablets. Yes, you read it right in the title of this article. In this article, we are going to build an Android App with HTML, CSS, and JavaScript in Android Studio.

    Share post:


    More like this

    Invaders From The Planet Moolah Android App

    Midas Golden...

    How To Create Resume On Android Phone

    Build Free...

    How To Develop An App For Android Free

    Android App...

    Remote Control Android Phone Over Wifi

    Best Remote...