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.