How to Check PageRank and AlexaRank in Android

If you have implemented a Java program on desktop, why not bring it to mobile platform? In this tutorial, I will show how to transplant the Java program for PageRank and AlexaRank to Android platform. Let’s glance at the screenshot in advance.

Android Rank Checker

Android Project

Create a new Android project in Eclipse. To access Internet, you have to open AndroidManifest.xml and add

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

Create an UI layout, which includes TextView, EditText and Button.

<RelativeLayout 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" >

    <LinearLayout
        android:id="@+id/linearlayout"
        android:layout_width="match_parent"
        android:layout_height="60dp" >

        <TextView
            android:id="@+id/text"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="center"
            android:gravity="center"
            android:text="@string/url" />

        <EditText
            android:id="@+id/url"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_gravity="center"
            android:layout_weight="1"
            android:ellipsize="end"
            android:hint="@string/hint" 
            android:inputType="textUri"/>

        <Button
            android:id="@+id/btSearch"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_gravity="center"
            android:text="@string/check" />
    </LinearLayout>

    <TextView
        android:id="@+id/results"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_below="@+id/linearlayout"
        android:scrollbars="vertical"
        android:text="" />

</RelativeLayout>

In main Activity, we need to create an event listener for button and set check results in text view. In case of blocking UI, we should create a thread for network connection.

public void onClick(View v) {
		// TODO Auto-generated method stub
		String url = mURL.getText().toString();
		String tmpURL = url.trim();
		if (url != null && !url.equals("")) {
			if (!url.startsWith("http")) {
				tmpURL = "http://" + url;
			}
			final String finalURL = tmpURL;
			final String logURL = url;
			mProgressDialog = ProgressDialog.show(this,
					getString(R.string.process_dialog_title),
					getString(R.string.process_dialog_content));
			new Thread(new Runnable() {

				@Override
				public void run() {
					// TODO Auto-generated method stub
					final int pageRank = PageRank.get(finalURL);
					final int alexRank = AlexaRank.getAlexaRank(finalURL);
					runOnUiThread(new Runnable() {

						@Override
						public void run() {
							// TODO Auto-generated method stub
							mResults.append(logURL + ": PageRank = " + pageRank
									+ "; Alexa rank = " + alexRank + mNewline);
							mURL.setText("");
							mProgressDialog.dismiss();
						}

					});

				}

			}).start();
		}
	}

Run the application on your smartphone to have fun. Download the source code AndroidRankChecker.

Now, no matter where you are, you can instantly check PageRank and AlexaRank. Please feel free to contact me at {desmond at Dynamsoft dot com} if you have any questions.

How to Read and Write Excel Files in Java

Previously, I talked about how to check PageRank in Java. In this article, I will combine PageRank with Excel files. To operate Excel files in Java, I used Apache POI – the Java API for Microsoft Documents. Apparently, you can download the API package, and follow the relevant tutorials to learn how to use POI. When I first downloaded the Java library, I was astonished by how many jar files there were. I had no idea which ones would be useful for my project. Fortunately, I managed to filter out what I want.

Read more

How to Write a Simple Java Program to Check PageRank

In this article, I am not going to go in-depth about Java and Swing. The content I will share in this article is about how to combine slices of knowledge to make a simple java tool for checking PageRank. In my previous article, I talked about how to extract domain names from the urls that downloaded from Google Webmaster. Today, I will not only introduce a way to check the PR but also how to load an Excel file in Java to automatically test the batch of page PRs.

Read more