How to Make a Internet Speed Test Android App - Android Studio 2.2.2
We all surf internet more than the time we used to sleep. But how much of them have faster connection? I don't want to stuck you :) Let's take about what we're discussing this time, today here we're to build one of the best apps on android and that is a app that can determine your internet speed. We use the famous website fast.com to test internet speed using WebView in our android app.
Want to do manually? Here we go.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.sabithpkcmnr.myapplication.MainActivity">
<WebView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/webview"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
We have added a <WebView to open the speed tester website which is mobile friendly.
Hope that was a great tutorial for you
Thanks for your time!
Sabith Pkc Mnr
You can watch the entire tutorial with exact vocal explanation from our official YouTube Channel
Want to do manually? Here we go.
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.sabithpkcmnr.myapplication.MainActivity">
<WebView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/webview"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
We have added a <WebView to open the speed tester website which is mobile friendly.
MainActivity.java
package com.sabithpkcmnr.myapplication;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MainActivity extends AppCompatActivity {
WebView wv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
wv=(WebView)findViewById(R.id.webview);
wv.setWebViewClient(new WebViewClient());
wv.loadUrl("https://www.fast.com");
wv.getSettings().setJavaScriptEnabled(true);
}
}
package com.sabithpkcmnr.myapplication;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class MainActivity extends AppCompatActivity {
WebView wv;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
wv=(WebView)findViewById(R.id.webview);
wv.setWebViewClient(new WebViewClient());
wv.loadUrl("https://www.fast.com");
wv.getSettings().setJavaScriptEnabled(true);
}
}
We have shown the WebView in the MainActivity and gave it a url that is wv.loadUrl("https://www.fast.com");
Finally we have to bring the permission for our android app to use internet.
We add user-permission to AndroidManifiest.xml
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
AndroidManifiest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sabithpkcmnr.myapplication">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.sabithpkcmnr.myapplication">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
Here's a screenshot how it look like on real device!
Hope that was a great tutorial for you
Thanks for your time!
Sabith Pkc Mnr
No comments: