Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

How to Build a Bitcoin Tracker Android App?

  • Difficulty Level : Expert
  • Last Updated : 09 Feb, 2021

In this article, we will be building a Bitcoin Tracker App Project using Java and XML in Android. The application will display the current rates of Bitcoin in different countries using Bitcoin API. There are many free APIs available and for this project, we will be using API by Coinlayer. The API will return a JSON that we will parse according to our needs. There will be a single activity in this app. A sample GIF is given below to get an idea about what we are going to do in this article. 

Build a Bitcoin Tracker Android App Sample GIF

Step by Step Implementation

Step 1: Create a New Project

To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio. Note that select Java as the programming language.

Step 2: Before going to the coding section first you have to do some pre-task

Permission: Add internet permission in the AndroidManifest.xml file

<uses-permission android:name=”android.permission.INTERNET”/>

Change the style to NoActionBar in the themes.xml file: 

<style name=”AppTheme” parent=”Theme.AppCompat.NoActionBar”>

Get the API key: You need to create a free account on Coinlayer and get an API key for this project.

Add dependency: 

We need to add this dependency in the app gradle file to make HTTP requests

implementation ‘’

Add Currency list in string.xml:

We need to add the list of all currencies in the strings.xml. From here we will display it in the activity to the users. Add the below code in the strings.xml file.


    <string name="app_name">Am I Rich?</string>
    <string name="label_default_text">304.74</string>
    <string name="label_error_text">Error</string>
    <string name="base">Base Currency</string>
    <string name="imageview_desc">Bitcoin Logo</string>
    <string-array name="currency_array">

Step 3: Working with the activity_main.xml file

The XML codes are used to build the structure of the activity as well as its styling part. It contains an ImageView at the very top of the activity to display the logo of the app. Then it contains a TextView to display the bitcoin rate in the center of the activity. At last, we have a Spinner at the bottom of the activity to display the list of currencies from which the user can choose. This is a single activity application. Below is the code for the activity_main.xml file.


<?xml version="1.0" encoding="utf-8"?>
        android:textStyle="bold" />
        android:src="@drawable/bitcoin_image" />
            android:textStyle="bold" />
            android:spinnerMode="dropdown" />

Step 4: Create new layout resource files

For the spinner to display the list we also need to create a spinner item’s XML layout as well as its item’s layout for the adapter. Add the below codes in app> res > layout > spinner_dropdown_item.xml.


<?xml version="1.0" encoding="utf-8"?>
    android:textSize="30sp" />

spinner_item.xml file:


<?xml version="1.0" encoding="utf-8"?>
    android:textStyle="bold" />

Step 5: Working with the file

In the java file, we will create a function that will make HTTP requests from the URL. The URL will be consisting of the API key the base URL and the target currency code. First, we will create an adapter for the list of all the currencies and set it to the Spinner view in the main activity. Then we will call the function onItemSelectedListener and get the selected currency code. We will add this code to the URL along with its other parts. Then we will call the function that makes HTTP requests to get a JSON. We will parse the JSON object to get the required rate of the bitcoin of the selected currency. Below is the code for the file. Comments are added inside the code to understand the code in more detail.


import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.ArrayAdapter;
import android.widget.Spinner;
import android.widget.TextView;
import org.json.JSONException;
import org.json.JSONObject;
public class MainActivity extends AppCompatActivity {
    // Constants:
    // TODO: Create the base URL
    private final String BASE_URL = "";
    // Member Variables:
    TextView mPriceTextView;
    protected void onCreate(Bundle savedInstanceState) {
        mPriceTextView = (TextView) findViewById(;
        Spinner spinner = (Spinner) findViewById(;
        // Create an ArrayAdapter using the String array and a spinner layout
        final ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(this,
                R.array.currency_array, R.layout.spinner_item);
        // Specify the layout to use when the list of choices appears
        // Apply the adapter to the spinner
        // TODO: Set an OnItemSelected listener on the spinner
        spinner.setOnItemSelectedListener(new OnItemSelectedListener() {
            public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
                String publicKey = "cd9ebbd0c5c20340b9d638e409f41fb1";
                String finalUrl = BASE_URL + publicKey + "&TARGET=" + adapterView.getItemAtPosition(i) + "&symbols=BTC";
                Log.d("Clima", "Request fail! Status code: " + finalUrl);
                try {
                } catch (IOException e) {
                } catch (JSONException e) {
            public void onNothingSelected(AdapterView<?> adapterView) {
    // TODO: complete the letsDoSomeNetworking() method
    private void letsDoSomeNetworking(String url) throws IOException, JSONException {
        AsyncHttpClient client = new AsyncHttpClient();
        client.get(url, new JsonHttpResponseHandler() {
            public void onSuccess(int statusCode, Header[] headers, JSONObject response) {
                // called when response HTTP status is "200 OK"
                Log.d("Clima", "JSON: " + response.toString());
                try {
                    JSONObject price = response.getJSONObject("rates");
                    String object = price.getString("BTC");
                } catch (JSONException E) {
            public void onFailure(int statusCode, Header[] headers, Throwable e, JSONObject response) {
                // called when response HTTP status is "4XX" (eg. 401, 403, 404)
                Log.d("Clima", "Request fail! Status code: " + statusCode);
                Log.d("Clima", "Fail response: " + response);
                Log.e("ERROR", e.toString());


GitHub Link:

Want a more fast-paced & competitive environment to learn the fundamentals of Android?
Click here to head to a guide uniquely curated by our experts with the aim to make you industry ready in no time!

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!