Develop a Cryptocurrency Tracker on Android
Tags: crypto, android, tutorial, beginners
Published: 2021-07-09 11:50:31

<!-- wp:paragraph {"align":"center"} -->
<p class="has-text-align-center"><em>This guest post on the Applozic blog was written by Mr. Dennis Muasya. His specialty lies in designing and developing advanced applications for the Android platform. You can check out his personal <a rel="noreferrer noopener" href="http://dmuasya.unaux.com/" target="_blank">website</a></em> <em>or find him on <a rel="noreferrer noopener" href="https://twitter.com/DenoMtisyer" target="_blank">Twitter.</a></em></p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>Introduction</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>A cryptocurrency is a form of digital currency that uses cryptography, and its creation and transfer are based on open-source code. Cryptocurrencies had an initial boom in 2009 when Satoshi Nakamoto established the first cryptocurrency, Bitcoin. Since then it has become one of the most valuable types of cryptocurrencies accepted as payment for goods or services worldwide from businesses such as Amazon to Subway sandwich shops! There are now hundreds of types of cryptocurrencies available to trade online. Some popular ones include Ethereum, Ripple XRP (Ripple), Litecoin LTC (LiteCoin), Monero XMR (Monero), Dash DASH (Dash), and more.&nbsp;</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>In this age of the digital world, money is constantly changing and what has been popular in recent years are now being replaced by more advanced technologies. The payment industry especially feels these effects with how many people use cryptocurrencies for payments instead of traditional currencies backed up by governments. Japan, alone among other countries such as Venezuela who have also legalized it to some degree alongside others like Switzerland who offer cryptocurrency debit cards that provides access to both Bitcoin or Ethereum funds from your crypto wallet whether you're at home on a laptop or abroad using an ATM card connected over Bluetooth wireless technology without going through any banks whatsoever if they even exist where you currently happen to be located when wanting cash transactions back down south across borders not just domestically but internationally too while fiat currency can't</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>In this article, we will create a Bitcoin Tracker App Project in Android using Java and XML. Using a Bitcoin API, the application will display current Bitcoin rates in various regions. There are numerous free APIs accessible, and we will be using CoinMarketCap's API for this project. The API will return a JSON file, which we will parse to meet our requirements. In this app, there will be only one activity. A sample GIF is provided below to give you an idea of what we'll be doing in this article. Why should we confine ourselves to only code? Why not broaden it to include everyday utility chores for us?</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>In light of this, I've created the app to demonstrate the capabilities of tracking different cryptocurrencies in real-time on Android smartphones.</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>App Preview</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>It's usually a good idea to have a visual and practical understanding of what you're doing and how it works, so check out the image below to see how this app works:</p>
<!-- /wp:paragraph -->

<!-- wp:gallery {"ids":[null,2146]} -->
<figure class="wp-block-gallery columns-2 is-cropped"><ul class="blocks-gallery-grid"><li class="blocks-gallery-item"><figure><img src="https://lh5.googleusercontent.com/GUuvaVilXRRCiipeK4kt2sK6hfGBUYBaMJOrp4RzUTAY_Y_y7LW8xKFWohNDfrENmfBwpefI9zfw-rjubqRzQkbfcWunJ-3zfkoO6EWPCbasxScu_MG1qLkc60ZJsSAPd1wnbHY0" alt="" data-id=""/></figure></li><li class="blocks-gallery-item"><figure><img src="https://www.applozic.com/blog/wp-content/uploads/2021/06/WhatsApp-Image-2021-06-04-at-9.09.29-AM-461x1024.jpeg" alt="" data-id="2146" data-full-url="https://www.applozic.com/blog/wp-content/uploads/2021/06/WhatsApp-Image-2021-06-04-at-9.09.29-AM.jpeg" data-link="https://www.applozic.com/blog/?attachment_id=2146" class="wp-image-2146"/></figure></li></ul><figcaption class="blocks-gallery-caption"><em>Screenshots of the CryptoTracker Android app</em></figcaption></figure>
<!-- /wp:gallery -->

<!-- wp:paragraph -->
<p>The GitHub repository for this project can be found <a href="https://github.com/Dmuasya/CryptoTracker">here</a>.</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>Glossary</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p><strong>Cryptocurrency</strong> is a digitized medium of trade that uses encryption techniques to regulate the generation of units and verify transactions as well as control the transfer of digital currencies. It's impossible to counterfeit, so it has become an attractive currency for many people who are wary of their local economy or want more privacy in their financial dealings. Today, there are over 1,000 different varieties of cryptocurrency in use, with Bitcoin being the most popular by far.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>The <strong>CoinMarketCap API</strong> is an open-source project that provides a simple interface for retrieving market data. The API supports 38 exchanges, with more coming soon. Bitcoin (BTC), Ethereum (ETH), Bitcoin Cash (BCH), Ripple (XRP), Litecoin (LTC), and many other cryptocurrencies are currently supported.&nbsp; A list of all the coins can be found on <a href="https://github.com/CoinMarketCap/api#supported-coins" data-type="URL" data-id="https://github.com/CoinMarketCap/api#supported-coins">this page</a>.</p>
<!-- /wp:paragraph -->

<!-- wp:paragraph -->
<p>If you are an Android developer and need to get cryptocurrency prices, the CoinMarketCap API is a great place to start. With this API, you can pull data from multiple exchanges and aggregators in one call. This enables developers to build apps that compare cryptocurrencies across markets or display pricing graphs over time for any currency pair.</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>Steps:</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>Before we start developing, it's a good idea to go over the technologies we'll be using so you don't become confused as we go.</p>
<!-- /wp:paragraph -->

<!-- wp:list -->
<ul><li><strong>Retrofit </strong>is a Java and Android-based REST client. It makes retrieving and uploading JSON (or other structured data) using a RESTful web service extremely simple.</li><li><strong>RecyclerView </strong>– Android layouts for better content organization on the screen<br>Create a new Android Studio project named "CryptoTracker." If you're just getting started, go to any of my prior tutorials on how to set up a new AS project.</li></ul>
<!-- /wp:list -->

<!-- wp:paragraph -->
<p>After you've done creating a new project, install the technology's dependencies.<br>Install the dependencies for the technologies we discussed after you've finished building a new project. Add the following to your app-level build.gradle file:</p>
<!-- /wp:paragraph -->

<!-- wp:heading -->
<h2>Step 1: Adding required dependencies</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>We'll add the following libraries:</p>
<!-- /wp:paragraph -->

<!-- wp:list -->
<ul><li>To handle REST-API requests, use OKHttp.</li><li>GSon is a tool for quickly parsing and converting JSON data.</li><li>Image fetching and caching in asynchronous mode have been retrofitted (essentially making this project doable in under 30 minutes).</li></ul>
<!-- /wp:list -->

<!-- wp:paragraph -->
<p>Add the following dependencies to the project-level build to get started:</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>dependencies {
   implementation fileTree(dir: 'libs', include: &#91;'*.jar'])
   implementation 'com.android.support:appcompat-v7:28.0.0-rc01'
   implementation "com.android.support:support-core-utils:28.0.0-rc01"
   implementation 'com.android.support.constraint:constraint-layout:1.1.2'
   implementation 'com.android.support:recyclerview-v7:28.0.0-rc01'
   implementation 'com.google.code.gson:gson:2.8.2'


   implementation('com.squareup.retrofit2:retrofit:2.1.0') {
       exclude module: 'okhttp'
   }
   implementation 'com.squareup.retrofit2:converter-gson:2.3.0'
   implementation 'com.squareup.okhttp3:logging-interceptor:3.9.1'
   implementation 'com.squareup.okhttp3:okhttp:3.10.0'
}

</code></pre>
<!-- /wp:code -->

<!-- wp:heading -->
<h2>Step 2: Adding permissions to the manifest</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>To use the above libraries, we must add the following permission to our AndroidManifest.xml:</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>   &lt;uses-permission android:name="android.permission.INTERNET" />

</code></pre>
<!-- /wp:code -->

<!-- wp:heading -->
<h2>Step 3: Creating the activity_main.xml file</h2>
<!-- /wp:heading -->

<!-- wp:paragraph -->
<p>In our layout format, we must first add the activity main.xml. This is the location where all of our models will be placed. Because this will span my entire operation, I've set the width and height to match_parent. You have the option of selecting the measurements that best suit your requirements. We're utilizing a RecyclerView, as you may have observed, so we'll need to develop a layout for the RecyclerView Item.</p>
<!-- /wp:paragraph -->

<!-- wp:code -->
<pre class="wp-block-code"><code>&lt;?xml version="1.0" encoding="utf-8"?>
&lt;android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
   xmlns:tools="http://schemas.android.com/tools"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   tools:context=".MainActivity">

   &lt;android.support.v7.widget.RecyclerView
       android:id="@+id/my_recycler_view"
       android:layout_width="match_parent"
       android:layout_height="match_parent"
       android:scrollbars="vertical" />

&lt;/android.support.constraint.ConstraintLayout></code></pre>
<!-- /wp:code --> 

##Continue this Tutorial on Applozic Blog!
We have the detailed tutorial with code snippets available on [Applozic blog](https://www.applozic.com/blog/how-to-develop-a-cryptocurrency-tracker-on-android/) for you to continue with your development!

[Click here](https://www.applozic.com/blog/how-to-develop-a-cryptocurrency-tracker-on-android/) to learn how to:
* Create the crypto_list_item.xml file
* Create the MainActivity.java file
* Create the CryptoListAdapter.java file
* See your app in action!