Just recently, I got a Kindle Fire HD 8.9 with LTE for very cheap price from Woot.com, one of amazon.com companies. My idea is that once you own a product, you should be able to do whatever you want. Sure it does void warranty and you might not be able to get it replaced/repaired but for a very cheap tablet I decided to take that risk. This tablet has a lot of potential given the LTE connection but because of the restricted OS that amazon has, we generally can’t do much outside of Amazon ecosystem when it comes to apps.

This tablet in particular uses Android 4.0.4, one of the KitKat versions and is considered a legacy system or OS. It was really hard to find a good solution to root and change things especially when most of the links out there no longer work and the codes were not maintained well. So in this tutorial I will try my best to provide you with all the links and downloads that are available to root your device and install latest TWRP and some custom roms.

Important: I am personally not liable if something goes wrong in the process. It’s up to you to take the risk!

Make sure the “Allow Installation of Applications from Unknown Sources” is turned On

Go back and select Security

Make sure the “Enable ADB” is turned On

Achieve Root Access

Getting a root access on this device is relatively easy. You just have to install the latest version of KingRoot app and try the root process. If it fails, just uninstall the app, restart the tablet, install the app and try again. Now, I have heard couple of bad things about KingRoot. It shows as threat when scanning with AVG app and says that it is a kind of an adware. But I have not found any other good rooting method that actually works. There are other apps like KingRoot but all of these apps seems to come from China 🙂 So it’s up to you to decide.

Make sure you have adb running. Just run this command in your cmd or terminal as an administrator. Your backup files should be available to you in C: drive under KFHD89 folder.

Installing Unlocked Bootloader, TWRP and Custom ROM

Since this tablet uses a legacy OS it was really hard to find the proper flashing tool to flash Recovery partition. The only apk that seems to work is called FireFlash. Also you do need the TWRP image to flash into the recovery partition.

Important: Amazon OS seems to delete the Recovery partition every time you reboot the device (or keep it in stand-by mode for a long period of time)

What you need:

FireFlash 1.1 APK

Unlocked Bootloader image file

TWRP image file

Go ahead and follow these steps:

Install the FireFlash APK and open it

Make sure you select (as shown in the image below)

Flash kfh8-u-boot-prod-8.1.4.bin (check the box) it will have some red text below saying your tablet doesn’t have 8.1.4. If not, it means you already have 8.1.4 bin and you will not be able to check the check box which is all right.

It should now show a popup saying Flashing and complete the flash process

You will see a report window when done. Go ahead and hit ok.

Now immediately, tap on the Reboot into recovery button. This is important because Amazon OS tends to wipe the recovery partition from time-to-time.

Your tablet will restart and you will see Kindle Fire logo with the text Fire in red color. You should now boot into Recovery Mode with TWRP.

If for some reason you restart or decide to go to recovery mode later, just flash the recovery partition with recovery auto update disabled using FireFlash and reboot into recovery.

To know that your bootloader is unlocked, whenever you restart your tablet you’ll see Kindle Fire logo with Fire text in blue color.

Install Custom ROM

In order to install custom ROMs, make sure you have the correct rom that supports your device. It is usually in a .zip format. Once you choose the ROM that you want, just boot into recovery and in TWRP select the zip file and flash it. Make sure to wipe data, cache and davlik to restore to factory settings.

Now I heard that ROM from LiquidSmooth (they closed a while ago) is the best ROM out there for Kindle Fire HD 8.9 (both LTE and non-LTE) but I couldn’t find it anywhere. It should have been available here as LS-KK-MileStone-3.2-jem.zip for non-LTE device and LS-KK-MileStone-3.2-jemlte.zip for LTE device, but the links don’t work. So if anyone come across this ROM please do let me know. I’ll host it somewhere so that others can download. For now, I prefer to stick to stock OS as that is by far the best os for this device but will have a root so that I can install launchers that need root access.

Troubleshoot using Fastboot Command

If anything fails or you are stuck in bootloop, there is still a chance that you can fully recover your device. Make sure you have fastboot running in pc/mac and you have a backup of all your partitions as mentioned above. Now to go to a stock firmware all you need to do is shut the tablet down, open up command prompt(cmd) in Windows or terminal in Mac and do the following:

Fastboot Flash Boot Partition

Shell

1

fastboot-i0x1949flash boot stock-boot.img

Type this and hit enter it should say <waiting for device> and then go ahead and plug your device into your pc/mac. This should flash your boot image.

Fastboot Flash Recovery Partition

Shell

1

fastboot-i0x1949flash recovery stock-recovery.img

Type this and hit enter. (Now if it doesn’t do anything and is stuck. Take the USB cable out and plug it in again. Type the code above and hit enter. Do the same for the following codes.)

Fastboot Flash System Partition

Shell

1

fastboot-i0x1949flash system stock-system.img

Type this and hit enter. It will take a while. Once done type the following.

Today, I am going to talk about something simple and useful in programming. For people who are professional programmers this might seem relatively easy but for someone who is trying to learn PHP or Java having a knowlege of how arrays work might be really useful. Especially when you have a large set of data and you need to display it in multiple columns.

So let’s talk about how to use PHP’s and Java’s inbuilt array funtion to slice a large array into smaller parts. For this tutorial, I am assuming you have some knowledge of how PHP and Java works. If not, there are hundreds of websites and books available to get basic understanding.

Scenario: I was given a task to list all the 52 US states in a page so that only the ones that are flagged as active in a table inside database is shown on the page. I had to show this in 3 columns.

#

State Name

Active Flag

1

Alabama

1

2

Alaska

1

3

Arizona

0

4

Arkansas

1

5

…

1

Result: The result should look something like this.

Alabama
Alaska
Arkansas
California
…

Kentucky
Louisiana
Maine
Maryland
…

North Dakota
Ohio
Oklahoma
Oregon
…

Now, the question might seem relatively easy. And we don’t necessarily need PHP or JAVA to solve this. We could also use something on client side like JavaScript. But, I’ll show how it’s done on the server side.

Query Database for Results:

We can get the list of active states from the database as follows:

Get data from database:

MySQL

1

SELECT*FROMstateswhereactive_flag=1order bystate_idasc;

For PHP you get the data as follows:

PHP

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

<?php

$servername="localhost";

$username="username";

$password="password";

$dbname="myDB";

// Create connection

$conn=newmysqli($servername,$username,$password,$dbname);

// Check connection

if($conn->connect_error){

die("Connection failed: ".$conn->connect_error);

}

$sql="SELECT * FROM states WHERE active_flag = 1 ORDER BY state_id ASC;";

$result=$conn->query($sql);

$states=array();

if($result->num_rows>0){

// output data of each row

while($row=$result->fetch_assoc()){

$states[]=$row;

}

}else{

echo"No Results Found";

}

$conn->close();

?>

The above code connects to the database and quries the result and puts it inside the $states[] array.

In Java, you can do the same utilizing Java’s inbuilt database connection library:

Java

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

Connection conn=null;

CallableStatement stmt=null;

ResultSet result=null;

ArrayList<String>states=newArrayList<String>();

try{

conn=getConnection();

stmt=conn.prepareCall("SELECT * FROM states WHERE active_flag = 1 ORDER BY state_id ASC;");

result=stmt.executeQuery();

while(result.next()){

Stringstate_name=result.getString("state_name");

states.add(state_name);

}

}catch(SQLExceptione){

LOG.log(Level.SEVERE,e.getMessage(),e);

}finally{

result.close();

stmt.close();

conn.close();

}

The above code puts the result inside states array. Here, getConnection() actually connects to the database. You can google and read about how to connect to database in Java to understand it much better. But, the idea is simple. We utilize Java’s SQL library to automatically connect to the database. You just define all the required connection settings in a properties file (below is just an example).

Java

1

2

3

protectedstaticConnection getConnection()throwsSQLException{

returnDriverManager.getConnection("**** Database Name ****");

}

Now that we have our results in an array. Let’s see how we can split the array into three sub arrays.

Array Count or Length

Before we do the actual splitting, we need to know the count of the total states in the array so that we can split the array evenly across the three arrays.

To do this, in PHP we use the inbuilt function count($array).

PHP

1

$states_count=count($states);

In Java we simply we utilize array.length property of an array.

Java

1

intstates_count=states.length;

Divisible by 3

Now that we know the array length, we need to know how to evenly distribute the states into three sets of list. The logic here is to make the length (or count) of the list divisible by 3 so that we can evenly distribute the states among three sets.

The concept of modulus is very helpful here. The modulo operation (or simply modulus) finds the remainder after division of one number by another. To check if a number is divisible by 3 or not we do the following:

First, we check to see if the number is even or odd.

If even, we add +1 and do the modulo operand on the length. This is done as number % divisor.If this outputs a number, besides 0, then we know the number is not divisible by divisor. Here we know length or count is even as $states_count % 2 gives us 0. If so, we loop and keep on adding 1 ($states_count++;)until we get a number that is divisible by 3 (loop until $states_count % 3 is not 0).

If odd, we test and see if this odd number is divisible by 3 ($states_count % 3 == 0). If the number is not divisible by 3 we keep adding 1 until we get a number that is divisible by 3.

In PHP

PHP

1

2

3

4

5

6

7

8

9

10

11

12

13

if($states_count%2==0){

do{

$states_count++;

}while($states_count%3!=0);

}else{

if($states_count%3==0){

//do nothing

}else{

do{

$states_count++;

}while($states_count%3!=0);

}

}

In Java

Java

1

2

3

4

5

6

7

8

9

10

11

12

13

if(states_count%2==0){

do{

states_count++;

}while(states_count%3!=0);

}else{

if(states_count%3==0){

//do nothing

}else{

do{

states_count++;

}while(states_count%3!=0);

}

}

Split Array in 3

Now that we have an array length that is divisible by 3, we can do the following to split the array.

In PHP we will use array_slice() method to slice into three parts. The syntax for array_slice() is