Monday, 22 January 2018

Android Simply Login Using Firebase UI

Hello everyone, today i gonna be post a nice tutorial relate with login process that provided by Firebase called Firebase UI.


What is Firebase UI ?

As simple as i can explain, Firebase UI will provide us the easy way  to creating login process even  login using Facebook, Google account, Email or Twitter

With Firebase UI you don't need create your login form or other API to do login, Firebase UI will handle it all.

Video Result

For achieve that goal, please follow the following steps :

Create Your Application On Firebase

Please go to firebase console and create your project

Create firebase project

After that, choose your platform, in this case choose Android Platform.

Choose platform

Add your SHA-1 key and your package name

Add package name and SHA-1

Download the google-service.json

Download google-service.json

After downloaded, place it inside your app folder. Please take a look at the following figure

App folder

Configuration Gradle

Make sure your gradles are similar with the following gradles :

build.gradle(Project : YourProjectName)

build.gradle(Module : App)

Create your Android Studio Project

You just need 1 XML layout and 1 java class to create login process using Firebase UI. Here they are :


Write the following code to create a simple view.

Run your project, and may it running well. Thank you.

Download the project here : LINK GITHUB

Wednesday, 8 November 2017

Insert Image From Android To Database (PHP + MySQL)

This article will show a simple tutorial about how to insert image from android to database. Insert image from android to database possible achieve by creating local database using PHP and MySQL.

So this tutorial using two projects, 1 PHP project and the other one is Android project. Don't forget to create your database to store the image that received from Android.

Image will be send from android by send its json to server. In php project, we also create a file that handle json from mobile (android).


We will save the file of image in the directory inside the php project. In database we just store the path of the image from php project.

For example
  • Users choose image obama.jpg from their android
  • In PHP project, there is a directory named imagefromandroid.
  • In database, just store its path, so it's become : imagefromandroid/obama.jpg.

Create Database

In this project i just create simple database, only one table. Please adjust your project and your database.


PHP Project

Create a directory that used to save the file of image that received from android. Take a look at the following image


I above figure, i create a directory where image from mobile android will stored name imagefromandroid. Also, we will use two php classes, Connection.php and insertImageFromMobile.php.


This file used to connect your PHP Project to your database. The code look like the follows :

This class used to handle data that received from mobile in json form. The code is look like the follows :

Android Project

There are several classes and xml files that we create in order to able to send image to the server or database.

This class created for handle response of retrofit. In other word, we able to see request process of retrofit to the endpoint.

This class will handle response message of request. The response message that will shown by this class are success or failed.

This class is an interface. In this class will declare endpoint of BASE URL.

This class contains the BASE URL that used in this project. And also in this class contains initialized of the retrofit

All class or method that used to send image to the server will called in this class. Full code of MainActivity :

Okay, that's all. Hope it helps you to learn how to insert image from android to database.

Monday, 6 November 2017

Android Displaying Multiple Markers From Database

This article will share you how to displaying multiple markers from database. Like the title data latitude and longitude will get from server (Server created with PHP and MySQL).

What is marker means?

Marker on Maps is a mark of a place on Google Maps. The main requirement in order to able to show the marker on Google maps are data latitude and longitude.

For example :

The coordinates of Badung Regency are -8.58193 (Latitude) and 115.177059 (Longitude). You also can check coordinates of your location on this web : Distancesto.

Ok, that's a short description about markers and its requirements, now i will share about creating the project.

To achieve the goal of this project, i create 2 projects, that are : 1 PHP project (for creating server) and 1 Android project (for client).

Creating Server

In this article i will create a simple server just for learning and not recommend to implementing in production project.

First you have to create your database structure and second create the php to connecting your project to your database.


I only use one table. And inside the table i have inserted the data of latitude and longitude. Take a look at the following image

Data LatLng

PHP Project

There are two files in php project. First class for connect to database and the second class for displaying data location in JSON.


Please adjust your username, password and your database name.


The above class will displaying data in json. Here is the output of the above class :

See also : Create file Json Object and Array Using PHP

Android Project

I will create the project by using the default template of Android Studio. Fyi, i use Android Studio Versi 2.2.2, not the latest version.

First, click start a new android project

Create New Project
Second, name your project by filling field Application name and Company domain.

Name the project

Third, select your platform, in this case just check the phone and tablet.

Select the platform

Fourth, select the template that you want to use. Related with this project, just select Google Maps Activity.


Fifth, give name your activity, layout and title by filling the field Activity name, Layout name, Title.

Attribute name

After that, click button finish.

Library Gradle

I have added some libraries. Modify your gradle to be the same as bellow :

Generate API_KEY

In order to able to display Google Maps in your project, you have to generate the API_KEY in Google Developer Console. You can user the existing project, or create new project.

First, generate API_KEY by clicking button GET A KEY

image via

Second, you can use the existing project or create new project.

image via

Third, copy your API_KEY and place in meta-data androidManifest.

image via

Confuse? Take a look at the following meta-data in AndroidManifest file :


Please adjust your AndroidManifest to be same as below :

Okay, until here, you have done preparing your requirement for creating Google Maps in your application. Next we will create several java classes.

Create two classes as model to handle the data from json

This class used to handle one object data from json. The code look like the follows :

Because json that we will receive is an array, means more than one object, then one object in class LocationModel will created as list with class ListLocationModel.

If you confuse with json format array and json format object, please continue read here : Create file json format array and json format object using PHP MySQL.

Class Client and Interface

The following are two classes that define the main URL (client) and its part (endpoint).

if you clearly see the URL, it contains digits, right? These digits is the IP of my computer that connected with my local internet (Tethering from my phone).

Class Logging Interceptors

Class MainActivity

This class is the main class that used to displaying all data makers on Google Maps. The full code is show as bellow :

Okay, that's all. Running your project and hope works well.

Download project by clicking the following image

Thursday, 2 November 2017

Create JSON Object And Array Using PHP MySQL

If you want to transfer your data to another client (mobile or server) you have to create your own JSON. JSON or JavaScript Object Notation is a file that used to transfer data between clients/server or between two different programming languages.

JSON have two types, they are :

  • JSON type Object
  • JSON type Array
What the different of these type?

JSON Type Object

JSON Type Object has characteristic always using mark {}, please take a look at the following sample json :

JSON type Array

We can call a json as an array is the JSON use the mark [] in its data. Why this json use the mark []? Because the data that will be send is more that one object. Please take a look at the following sample :

If you will transfer data more that one object, use the JSON type array. But, if you just transfer only one object, use JSON type Object as its format.

Create JSON Array using PHP and MySQL 

First, you have to preparing your data and has been saved in your MySQL database. In this project i will using data in my database and look like the follows :

Create your connection to connect the database and your project. Here is the code :


After you connection has works well. Now create your JSON type Array


Running the above file, and you will show your data as list in json.

Create JSON type Object Using PHP and MySQL

Here is the file that you can use to create JSON type Object.

The above json will catch data type object from android and will send its data to database. I have been implemented it and has been post the project in this blog. Please open this : Tutorial insert data from android using retrofit to Server (PHP + MySQL).

That's all. Hope this article helps you. Thank you.

Tuesday, 3 October 2017

Implementing Load More When Woking On Blogger's API

In this tutorial, i will share a tutorial about how to implementing load more and pagination function in Blogger API using retrofit.

When you working with API Blogger, you will face an endpoint that contains much data in list.

The URL that contains a lot of data in list is :
That URL will display output json look like the following image :

Output List Json

If you run the URL above, the result will give you only 10 datas in first page. Take a look at attribute items.

To get the next page you have to request it again (load more) and display the result as pagination. To implementing the pagination (request the next page), you can use the attribute nextPageToken. As long as the attribute nextPageToken exist, it means the data still exist in the next page.

Request the first page

Just request the first data in normal URL (without params nextPageToken). In this case i request the data using retrofit :

On the code above, I request the first page and set the data into the adapter. Don't forget to save the value of nextPageToken.

In load more function, i check the nextPageToken is exist or not. Is exist, then request the next page.

Request the next page

To request the next page, you have to add params pageToken, and the value set from nextPageToken.

The URL to be :
The code is look like the follows :

That's all what i did to implementing load more pagination when request data using Blogger API. Hope it helps. Thank you.

Saturday, 2 September 2017

Tutorial Double Navigation Drawer Android (Left and Right)

Hello everyone, today i gonna show you a good tutorial about how to creating double navigation drawer on left and right side.

In usual, you must be develop and application using one navigation drawer on left side, right?  But sometimes your application or your client requires double menu on left and right side. You can implement the right menu using dialog similar like navigation drawer, but it maybe not good for the future of your apps. Just a suggestion, on that case, you should use a navigation drawer to handle the menu on the right side.

Double navigation drawer

In this tutorial i will show you how to create double navigation drawer. I think this tutorial isn't hard if you have been understand about how to create left navigation drawer.

Crate the left navigation drawer from Android Studio

Think if the your application requires a right navigatio drawer after you create the left navigation drawer, so i assume you are have been create the left navigation drawer.

But a will guide you how to create the navigation drawer from Android Studio, here it is :

Open you android studio android and name your project as DoubleNavigationDrawer :

Give your project name

After name the project, click button next.

Choose minumu SDK Version

In this case i choose the fault minumun SDK, that is API 16 for Android Jelly Bean. Klik button Next.

Choose Navigation Drawer Activity

Then choose Navigation Drawer Activity as your first class. This will create the left navigation drawer (without right navigation drawer), after that give your first xml dan class file name, take a look the below image

Give the class and xml file name

Give name for your first class and xml file. In this case, just click button next.

Untuk this steps, you have succeed create the left navigation drawer. Just run the project for make sure. The next step is create the right navigation drawer.

Create the right navigation drawer

To create the right navigation drawer you have to create another menu and also there is one layout you have to modify.

Create new menu for the right navigation's items

Create a new file for the right navigation's items in res/menu. Name the new file as activity_navigation_drawer_right. Here the code :

The code above will appears as items of right navigation.

After you create the right navigation's items, now modify your activity_main.xml ( or the xml file where you hosting you NavigationView).

You have to create the another NavigationView to host the right navigation's items. and change its gravity to END. Just take a look the following codes :

Ok all that should be set in the xml file has been set. Now time to modify your java class.

Modify your main_menu (res/menu)

Modify your main_menu.xml (menu that hosted in page where the navigation drawer will appears). Other word this menu will displaying the right navigation drawer. Here the code :

Modify the java class

Find your class where you hosting your DrawerLayout or your NavigationView. In this case i host them in

Create new method for displaying the right navigation. In my case I named it as displayRightNavigation(). Do like the following code :

Call the method inside onCreate() method.

And your onBackPressed() method, modify like following code :

Once again, modify your onOptionItemSelecte(MenuItem item) look like the follows :

Full Code Of Java Class

That's all about the tutorial. Run your project. Hope it works well, feel free to ask me by post your comment.

Download the project here : LINK GITHUB

Thursday, 31 August 2017

Android Validation Inside Custom Alert Dialog Builder

In a development process, Alert Dialog usually used for show a message from a running process. The message usually show as an error message, success message or notification message.

Custom Alert Dialog Validation

There are two Dialog that much used, they are AlertDialog and Dialog. Both can used for display a message.   You also able to modify the view inside AlertDialog or Dialog. For custom Dialog view, please read here : Android Custom Popup Using AlertDialog And Dialog

Cannot create a validation on EditText inside AlertDialog

My experience using custom alert Dialog is i can't create a validation form and use setError() for EditText. It's because i wrote my validation inside alertDialog.setPositiveButton(). If we need to create a validation, it should outside of that area.

Then how to do validation? Here it is, If you need to create a validation inside a custom AlertDialogBuilder, then please use the following code (at least works perfectly in my project):
Ok that's all a little explanation about how to do validation inside a custom Alert Dialog Builder. Hope it helps. Thank you.

Wednesday, 23 August 2017

Android Adding File Certificate To Retrofit 2.0+

After the previous post about how to adding file certificate to Retrofit 1.7, today i gonna share a new tutorial about how to adding file certificate to Retrofit 2.0.

As you know, one of usage of file certificate is used to access HTTPS from HTTP. If your current host is HTTPS but you still access using HTTP , so by using file certificate it will be redirecting to HTTPS automatically.

Before you adding file certificate to Retrofit 2.0 make you using OKHTTP 3 for your client. So here is the method that you can use for adding file certificate to Retrofit 2.0 :

First import the following package :

Here the method that i use in my project, write the following method (you can modify the method as you wish) :

That's all, hope it helps and works. Thank you.

Tuesday, 22 August 2017

Android Add File Certificate To Retrofit 1.7

In current  project that you develop from the beginning you must be use the latest version of the library, for example library Retrofit.

In several case, you must be face a difficulty in Retrofit 1.7 how to add file certificate to Retrofit 1.7, right?

Because of this, i create this article and share my experience when i add file certificate to my apps using Retrofit 1.7

If you using Retrofit 1.7, make sure another support libraries are added, these libraries that i meant are :

compile 'com.squareup.okhttp:okhttp:2.0.0'
compile 'com.squareup.okio:okio:1.13.0'
compile 'com.squareup.okhttp:okhttp-urlconnection:2.0.0'

After that, write to the following code in your apps to adding file certificate to Retrofit 1.7 :

Above is some code snippet in my project. I don't how the model of your code, but you can modify my code above and implement in your project. If you are using Retrofit 1.7, then my code will works in your project.

That's all about how to adding file Certificate to Retrofit 1.7, hope it helps and works in your project. Thank you.

Wednesday, 16 August 2017

Java Determining words An Anagram Or Not

An anagram is direct word switch or word play, the result of rearranging the letters of a word or phrase to produce a new word or phrase, using all the original letters exactly once; for example, the word anagram can be rearranged into "nag a ram".

The original word or phrase is known as the subject of the anagram. Any word or phrase that exactly reproduces the letters in another order is an anagram. Someone who creates anagrams may be called an "anagrammatist",[1] and the goal of a serious or skilled anagrammatist is to produce anagrams that in some way reflect or comment on their subject.[source wiki]

Example :

ABC and BCA or ACB or BAC are Anagram


Because every single letter in the first word, is owned by the second word with the same amount. So if the first word contains the letter A of 1, then the second word must also have the letter A as much as 1. If in the first word contains the letter B of 2, then the second word must also have the letter B as much as 2, and so on

ABC and BBA or ABBC or ABCA or ABA or BAA are not an Anagram 

As like explained above example, in this second example, the letter on the first word and the second word are same, but the amount are different. That's make why in the second example is not an Anagram.

How the implementing on Java?

Here I will give you 2 different methods that can used to check two words is an anagram or not an anagram.

Method I

On this first method is to sort the first word and second word from the beginning to the end (alphabetical order a-z).

That used to sort is the Arrays.sort code (chars1). So from the input BCA will turn into ABC. The goal is let program easy to detect how many of each letter if it is in the order.

The result will like the follows :

CCABD and BACD, after the sort will be ABCCD and ABCA, then it is caught if the two words are not an anagram

What determines the amount is the same or not is in the if section ie Arrays.equals (chars1, chars2).

See also : How to Watch Youtube's Video From Own Android Application


Method II

On this second method I think is more complex than the first method because it plays more logic than the existing function in java.

The first is to check the number of first words and the second word must be the same, if the difference in number is already certain it is not Anagram.

See also :  Android - Get Value Of List Checkbox And Display It On Other Activity As A List

The second checks each letter between the first word and the second word, before determining whether it is an anagram or not
Result not an anagram

The last one determines the Anagram or not.

In this method can also find out which letters are causing the two words are not Anagram and how many.

What if there are upper and lower case letters?

No problem, if your case requires that the upper and lower case is the same then use the function .toLowerCase ().

If your case requires differentiating between uppercase and lowercase letters, the .toLowerCase () function should not be used.

How to use the method


Result an anagra

So that's all the tutorials, you can use any one of the method, both can determine the two words Anagram or not.