Android Development Tutorial http://www.android-development-tutorial.net Hub of Android Development Sun, 20 Mar 2016 07:55:50 +0000 en-US hourly 1 https://wordpress.org/?v=4.6.1 Adding Interstitial Ad in Android Application – Video Tutorial http://www.android-development-tutorial.net/adding-interstitial-ad-in-android-application-video-tutorial/ http://www.android-development-tutorial.net/adding-interstitial-ad-in-android-application-video-tutorial/#respond Sat, 19 Mar 2016 10:50:07 +0000 http://www.android-development-tutorial.net/?p=3265 Interstitial Ads are full screen ads that cover whole interface of that their hosts app. To increase revenue from your android app, adding interstitial ad is the best option from admob network. As previously, we discussed about integrating admob ad banner in android app, similarly today we will integrate Interstitial ad in android application.

interstitial ad sample

In this tutorial, we will simply create a project where only one single button will be added. When the user hit button, it will show full ad screen which is Interstitial ad. So here we will integrate it as example and thus you can get clear ideas to add in your real android application.

Interstitial Ad Video Tutorial Here

Lets Get Started

  • Create a Project
  • Download Google Play Services Library
  • Copy & Paste a Project

Create a Project

First of all we should create a new project for this purpose. Keep in mind that all project name should exactly accurate and same as mentioned below.

  • Application Name : Interstitial Ad
  • Activity Name : MainActivity
  • Layout Name : activity_main
  • Package Name : net.android_development_tutorial.interstitialad

And then simply hit the Finish button to build your project.

Download Google Play Services Library

It is important to download latest Google Play Services Library from SDK Manager. There are two ways to find SDK Manager. The first one is SDK Manager icon in the toolbar as you can see in screenshot below.

sdk manager icon

 The second one is when you navigate to Tools > Android > SDK Manager. Now find the Google Play Services in Extras tab and install them if you haven’t  already.

google play services

Copy & Paste the Project

We will add some coding here to construct interstitial ad in MainActivity.Java | Copy and Paste the following coding in your project.

Please Note : You will need to get Admob publisher Ad Unit Id from your own account. The listed below one is default one from admob.

package net.android_development_tutorial.interstitialad;

import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.Button;

import com.google.android.gms.ads.AdListener;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.InterstitialAd;

public class MainActivity extends AppCompatActivity {
    InterstitialAd mInterstitialAd;
    Button mNewGameButton;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        mNewGameButton = (Button) findViewById(R.id.new_game);

        mInterstitialAd = new InterstitialAd(this);
        mInterstitialAd.setAdUnitId("ca-app-pub-3940256099942544/1033173712");

        mInterstitialAd.setAdListener(new AdListener() {
            @Override
            public void onAdClosed() {
                requestNewInterstitial();

            }
        });

        requestNewInterstitial();

        mNewGameButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mInterstitialAd.isLoaded()) {
                    mInterstitialAd.show();
                }
            }
        });

        FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
        fab.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
                        .setAction("Action", null).show();
            }
        });
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    private void requestNewInterstitial() {
        AdRequest adRequest = new AdRequest.Builder()
                .build();

        mInterstitialAd.loadAd(adRequest);
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}

Now Lets add button in activity_main.xml when user click on it, it show interstitial ad.

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:context="net.android_development_tutorial.interstitialad.MainActivity">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/AppTheme.AppBarOverlay">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="?attr/colorPrimary"
            app:popupTheme="@style/AppTheme.PopupOverlay" />



    </android.support.design.widget.AppBarLayout>

    <Button
        android:layout_marginBottom="55dp"
        android:id="@+id/new_game"
        android:text="Click Here"
        android:layout_marginTop="250dp"
        android:layout_marginLeft="150dp"
        android:layout_width="wrap_content"
        android:layout_height="90dp" />


    <android.support.design.widget.FloatingActionButton
        android:id="@+id/fab"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom|end"
        android:layout_margin="@dimen/fab_margin"
        android:src="@android:drawable/ic_dialog_email" />

</android.support.design.widget.CoordinatorLayout>

In build.gradle, add dependencies of Goolge Play Services.

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.2"

    defaultConfig {
        applicationId "net.android_development_tutorial.interstitialad"
        minSdkVersion 9
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    testCompile 'junit:junit:4.12'
    compile 'com.android.support:appcompat-v7:23.2.1'
    compile 'com.android.support:design:23.2.1'
    compile 'com.google.android.gms:play-services:8.4.0'
}
Now Finally modify AndroidManifest.xml with internet permission and include the Adactivity configuration changes.
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="net.android_development_tutorial.interstitialad">

    <!-- Include required permissions for Google Mobile Ads to run-->
    <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"
            android:label="@string/app_name"
            android:theme="@style/AppTheme.NoActionBar">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <!--Include the AdActivity configChanges and theme. -->
        <activity android:name="com.google.android.gms.ads.AdActivity"
            android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
    </application>

</manifest>

Run The App

Now Its time to run the project to see whether it show interstitial ad when a button get clicked. Of-course it does, the interstitial ad will look like as below snapshot.

interstitial ad sample

 If you still have some question or have issue while creating project, please let us know we will get to you asap. Thanks

]]>
http://www.android-development-tutorial.net/adding-interstitial-ad-in-android-application-video-tutorial/feed/ 0
How To Link Google Analytics With Android Apps [Video Tutorial] http://www.android-development-tutorial.net/link-google-analytics-with-android-apps/ http://www.android-development-tutorial.net/link-google-analytics-with-android-apps/#respond Mon, 18 Jan 2016 16:41:43 +0000 http://www.android-development-tutorial.net/?p=3255 Hey friends, In previous tutorial we discussed about uploading android app to Google playstore. Similarly, today we will Insha-Allah learn how to link google analytics with it to get more insight or statistics of your app. Actually linking with google analytics let us know about users of our app, countries of users, which app version users currently installed, total users installs vs number of unique installs including how they discover your app and what devices they use and many more insights and information you can get once if you have linked your app with google analytics.

linking google analytics with android app

Don’t know how to get linked with google analytics? Don’t worry about it here I will teach you in step by step even you can watch video tutorial as well.

Linking Google Analytics with Android App

Before linking your app, you will need login both Google Analytic and Google Play Developer Console accounts. Simply follow the steps below to start linking,

  • First of all  Sign in to your Google Analytics Account and select the Admin tab.
  • Under Account > Property click All Products.
  • Under Google Play, hit Adjust Link button.
  • Select the apps you want to see data for in this property.
    If you don’t have any apps selected, you cannot link Analytics to Google Play. At least one app must be selected for the accounts to be linked.
  • Configure the link, and click Apply.

Congratulation, you have successfully done all the steps and you are ready to catch all statistics / insights of your android app.

Remember : After couple of days, you will see statistics of your android in your Google Play Developers Console Account.

Watch Video Tutorial Here

Final Words

This is how to link Google Analytics with android app so if you have found this post helpful then please don’t forget to subscribe us as well share us with your friends on social media website. Thanks for your time 🙂

]]>
http://www.android-development-tutorial.net/link-google-analytics-with-android-apps/feed/ 0
Uploading Android App To Google PlayStore – Video Tutorial http://www.android-development-tutorial.net/uploading-android-app-to-google-playstore-video-tutorial/ http://www.android-development-tutorial.net/uploading-android-app-to-google-playstore-video-tutorial/#respond Thu, 14 Jan 2016 17:17:36 +0000 http://www.android-development-tutorial.net/?p=3244 Hey android developer brothers, Do you really want to know how to upload android app to Google Play? If yes then here you are on right place. Before uploading, you will need to have Google Play Developer Console account where you will upload android app to playstore and that account will cost you $25 for first signing up. If you have already an account but troubling with uploading an apk then don’t worry about it, I will show you how to upload android app to Google Play Developer Console. Follow the steps below to upload your app to Google Play,

Generate Signed Apk

The very first thing is to generate singed apk of your android app because Google Play only accept release version of apk not the debug version apk. So after generating signed apk, you will have app-release.apk which is acceptable by Google play. Read the following post to complete this step,

Read : Generate Signed Apk Using Android Studio Tutorial

Uploading Android App

Once you generate signed apk, now its time to uploading it to Google PlayStore. Here is few steps to be done.

  • Login to Google Play Developer Console account.
  • Click on Add new application.
  • Write Title of your app and click on Upload APK
  • Click on Upload your first APK to Production and browse your app-release.apk file from Android Studio Projects.
  • Depending on you android app size, uploading will takes some time and once its completed, move to next options as follow,

Store Listing : In the store listing option, you will need to give product details and some basics things in order to proceed next step. Fields marked with * need to be filled before publishing.Following are the fields,

  • Title
  • Short description
  • Full description
  • Screenshots
  • Hi-res icon
  • Feature Graphic
  • Application type
  • Category
  • Content rating
  • Email
  • Privacy Policy

Content Rating : In this option, you will need to fill content rating form questions. As they said, “The rating system includes official ratings from the International Age Rating Coalition (IARC) and its participating bodies”.

Pricing & Distribution : In this option, you can set price if your application is paid or can offer it for free. You can also distribute your app worldwide or in particular countries as you wish. There are two other fields marked with * which can be ticked before publishing app to Google PlayStore.

After following all above steps, Hit the Publish app button and you are done. Remember that Google Play team will take review on it and if the team found no violation, then it will be published to Google PlayStore in next few hour. Therefore people can download it and that’s how to publish android app on Google PlayStore.  If you are still facing any trouble, watch video tutorial below.

Uploading Android App Video Tutorial

Final Words

This is how to upload android app to Google Play and if you like this post, don’t forget to share it with your friends and also subscribe us for more updates. If you have any question or query, ask me via commenting below and we will give you response as soon as possible and we love to reply back and hear from you. Thank you for your time 🙂

 

]]>
http://www.android-development-tutorial.net/uploading-android-app-to-google-playstore-video-tutorial/feed/ 0
Integrating Admob Banner in Android App – Video Tutorial http://www.android-development-tutorial.net/integrating-admob-banner-in-android-app-video-tutorial/ http://www.android-development-tutorial.net/integrating-admob-banner-in-android-app-video-tutorial/#respond Thu, 07 Jan 2016 17:41:03 +0000 http://www.android-development-tutorial.net/?p=3234 In this android development video tutorial, I will be showing you how to add admob banner in android app. Admob is a mobile advertising company parent organization of Google. Admob is almost work like Google Adsense where you have to put the live ads on your property and earn decent money through your android app. How to create admob account? Its very easy just you have to sign up the admob account with Gmail account or if you have already Google Adsense account then you will only sign in with existing adsense account.

AdMob-Logo

Ok now let’s start adding admob banner in android app which is one of difficult task to achieve for beginner but don’t worry I will teach you step by step along with video tutorial.

Watch Video Tutorial Here

Step By Step Guide

For better understanding, let’s take an example to add admob banner in your project,

Open your android app (project) and let the gradle building finished.

First of all we need to add latest dependencies of ‘Android Gms Play Services-ads’. Open Gradle Script > build.gradle (Module: app) and add dependencies

compile 'com.google.android.gms:play-services-ads:8.1.0'

apply plugin: 'com.android.application'

android {
    compileSdkVersion 23
    buildToolsVersion "23.0.1"

    defaultConfig {
        applicationId "com.topitideas.myfirstapp"
        minSdkVersion 9
        targetSdkVersion 23
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }
}

dependencies {
    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:23.0.1'
    compile 'com.google.android.gms:play-services-ads:8.1.0'
}

Open the AndroidManifest.xml file and add the following code in exact place shown below

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

 <!--Include the AdActivity configChanges and theme. -->
        <activity android:name="com.google.android.gms.ads.AdActivity"
            android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.topitideas.myfirstapp" >

    <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:theme="@style/AppTheme" >
        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <!--Include the AdActivity configChanges and theme. -->
        <activity android:name="com.google.android.gms.ads.AdActivity"
            android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
    </application>

</manifest>

 

Now in MainActivity.java, add the following code to get admob banner or to load Ad.

AdView mAdView = (AdView) findViewById(R.id.adView);
        AdRequest adRequest = new AdRequest.Builder().build();
        mAdView.loadAd(adRequest);

package com.topitideas.myfirstapp;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdView;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        AdView mAdView = (AdView) findViewById(R.id.adView);
        AdRequest adRequest = new AdRequest.Builder().build();
        mAdView.loadAd(adRequest);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}

 

Finally, in activity_main.xml, do some changes and add piece of coding.

<RelativeLayout"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
  ">

    <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_alignParentBottom="true"
        ads:adSize="BANNER"
        ads:adUnitId="ca-app-pub-3940256099942544/6300978111">
    </com.google.android.gms.ads.AdView>

<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" android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">

    <TextView android:text="@string/hello_world"
        android:textSize="30sp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

    <com.google.android.gms.ads.AdView
        android:id="@+id/adView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_alignParentBottom="true"
        ads:adSize="BANNER"
        ads:adUnitId="ca-app-pub-3940256099942544/6300978111">
    </com.google.android.gms.ads.AdView>

</RelativeLayout>

 

Note : Keep in mind that you will generate your own [ ads:adUnitId ] from your admob account. This is just example ad unit by admob.

Final Words

This is how simple is integrating admob banner ads in android app. If you found this post helpful then please do a favor by subscribing our blog for more futuristic android development tutorial. If you have any question related to this, ask via comment and we love to hear from you. Thanks buddy J

]]>
http://www.android-development-tutorial.net/integrating-admob-banner-in-android-app-video-tutorial/feed/ 0
Importing Drawable Folders & Images in Android Studio Tutorial http://www.android-development-tutorial.net/importing-drawable-folders-images-in-android-studio-tutorial/ http://www.android-development-tutorial.net/importing-drawable-folders-images-in-android-studio-tutorial/#comments Wed, 23 Dec 2015 05:01:34 +0000 http://www.android-development-tutorial.net/?p=3219 In this tutorial, InshaAllah we will learn how to create or import drawable folders & call some images from these folders in android studio. What exactly drawable folders used for? Well drawable folder is used for to store images or pictures when we need to show it on our android application. By default, drawable folders aren’t have been created while creating new project in android studio. So we have to create drawable folders manually if pictures are needed. Let’s see how to create folders and put pictures into them,

importing drawbale folders

First of all you will need to open your project and wait that android studio finish loading.

Now right click either on Java folder or res folder under project & select New > Android Icons Importer.

Recommended : How to Create Your First Android App – Hello World App

In the importer window, leave all the option by default and hit ok button. That’s it. Boom

importing drawbale folder android studio free

Now all you need to do is find your android project location in your system. By default, most of android studio projects are stored on C:// Users/username/AndroidStudioProjects.

Once you found the project, click on Your Project > app > src >main > res > drawable.

project location android studio

Here you may noticed there are many drawable folders, remember that these are the dimension of drawable folders. You can put high quality images or pictures in specific folders. This is because if you put all high quality pictures in low dimension folder then it may slow down your app performance. So it better to put pictures on appropriate drawable folders.

Remember that the image / pictures name should be start from lower case and the same name will have be written in coding otherwise it will give your errors. For example, best way to call your image from drawable folder & In xml layout is,

images importer android studio

android studio codingAll done, this is how to import drawable folders and images in android studio. If you found this post helpful, please share it with your friends because sharing is caring and don’t forget to subscribe our blog for more interesting tutorials.

Watch Video Tutorial Here

]]>
http://www.android-development-tutorial.net/importing-drawable-folders-images-in-android-studio-tutorial/feed/ 2
Generate Signed Apk Using Android Studio Tutorial http://www.android-development-tutorial.net/generate-signed-apk-using-android-studio-tutorial/ http://www.android-development-tutorial.net/generate-signed-apk-using-android-studio-tutorial/#respond Mon, 14 Dec 2015 14:53:17 +0000 http://www.android-development-tutorial.net/?p=3206 In this tutorial, we will learn how to generate signed Apk using android studio. Have you ever wonder why to generate signed apk of android app? What does it mean or where it could be use? Well, signed apk is very important when it comes to publishing app on google playstore. Whenever android app reached to an end, it is must to generate signed apk otherwise we can’t publish it on google playstore. So now let see how to get signed apk using android studio.

generate signed apk android studio

Generate Signed Apk Example

It is very easy to get signed apk just you need follow the following steps below,

Open then android studio & then your desire project. Wait for few minutes that your project finish loading.

Before making certain changes, create new folder (with any name) either on desktop or anywhere you want for key store. ( it will be the key store path )

In the left of android studio under project window, click Build Variants tab & change debug to release. (wait few moments to finish gradle building)

generate signed apk android

In the upper toolbar menu, click on Build > Generate Signed Apk & then click on Create New. Browse the folder that we have created earlier for key store path. Give any name & then click ok to create jks file.

generate signed apk android tutorial

Now type any of your password in all boxes along with alias name. Fill the certificate form & then click ok – Hit next button (that’s it)

generate signed apk tutorial

Wait for couple of minutes that android studio finish their loading after that pop up window will be appear which shows location of singed apk (release apk).

We have video tutorial for you, watch & enjoy

This is how to generate signed apk using android studio. If you found this post helpful then please subscribe our blog for more stuff. Let me know if you have any question using comments below.

]]>
http://www.android-development-tutorial.net/generate-signed-apk-using-android-studio-tutorial/feed/ 0
Android Custom ListView Example with Images [Video Tutorial] http://www.android-development-tutorial.net/android-custom-listview-example-with-images/ http://www.android-development-tutorial.net/android-custom-listview-example-with-images/#respond Thu, 03 Dec 2015 16:13:14 +0000 http://www.android-development-tutorial.net/?p=3187 In this android development tutorial, we will learn how to create awesome ListView for android app along with images (thumbnail). I think more than 90% android apps are consist of listview I have seen so far. I have been searching for a while to learn how to create custom listview or was trying to get some ready made code from somewhere for this purpose. Fortunately I got many beautiful listview example after searching and spending to many times on internet. If you are reading this tutorial, you are on right way just follow the below steps and get the code to create one of amazing listview.

android custom listview

Create New Project

  • You will need to create new project and Application Name should be ‘ListView’.
  • Activity to Mobile should be selected as ‘Blank Activity’.
  • Leave the Activity Name by default as ‘MianActivity’.
  • And rest of the things or configuration up to you whether you want to change it or not. (Will suggest you to leave it by default)
  • Once you done all things, hit Finish button to create project.

Related : How to Create Your First Android App – Hello World App

Implement Android ListView with Images

Ok so you have created the project with name of ‘ListView’. Now all you need is copy the code below and paste it on your project.

Create new Java Class with name of ‘CustomListAdapter.java’ and copy the code below & paste it over there.

CustomListAdapter.java

package net.android_development_tutorial.listview;

/**
 * Created by Saeed on 12/3/2015.
 */
import android.app.Activity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class CustomListAdapter extends ArrayAdapter<String> {

    private final Activity context;
    private final String[] itemname;
    private final Integer[] imgid;

    public CustomListAdapter(MainActivity context, String[] itemname, Integer[] imgid) {
        super(context, R.layout.mylist, itemname);
        // TODO Auto-generated constructor stub

        this.context=context;
        this.itemname=itemname;
        this.imgid=imgid;
    }

    public View getView(int position,View view,ViewGroup parent) {
        LayoutInflater inflater=context.getLayoutInflater();
        View rowView=inflater.inflate(R.layout.mylist, null,true);

        TextView txtTitle = (TextView) rowView.findViewById(R.id.item);
        ImageView imageView = (ImageView) rowView.findViewById(R.id.icon);
        TextView extratxt = (TextView) rowView.findViewById(R.id.textView1);

        txtTitle.setText(itemname[position]);
        imageView.setImageResource(imgid[position]);
        extratxt.setText("Description "+itemname[position]);
        return rowView;

    };
}

 

Similarly, create Layout resource file with name of ‘mylist.xml’ & copy the code below & paste it over there.

mylist.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >

    <ImageView
        android:id="@+id/icon"
        android:layout_width="60dp"
        android:layout_height="60dp"
        android:padding="5dp" />

    <LinearLayout android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical">

        <TextView
            android:id="@+id/item"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Medium Text"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:layout_marginLeft="10dp"
            android:layout_marginTop="5dp"
            android:padding="2dp"
            android:textColor="#33CC33" />
        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="TextView"
            android:layout_marginLeft="10dp"/>
    </LinearLayout>
</LinearLayout>

 

In MainActivity.java, we have to give item name along with pictures. Make sure you have put pictures in your drawable folder otherwise it will give error. In short, copy the code below and paste it in your MainActivity.java

MainActivity.java

package net.android_development_tutorial.listview;

import android.app.Activity;
import android.app.ListActivity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.Toast;


public class MainActivity extends AppCompatActivity {

    ListView list;
    String[] itemname ={
            "Car",
            "Camera",
            "Android",
            "Achievements",
            "Ball",
            "Barcode",
            "Basket",
            "Bike",
            "Book"

    };

    Integer[] imgid={
            R.drawable.ic_action_car,
            R.drawable.ic_action_camera,
            R.drawable.ic_action_android,
            R.drawable.ic_action_achievement,
            R.drawable.ic_action_ball,
            R.drawable.ic_action_barcode_2,
            R.drawable.ic_action_basket,
            R.drawable.ic_action_bike,
            R.drawable.ic_action_book,

    };
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);



        CustomListAdapter adapter=new CustomListAdapter(this, itemname, imgid);
        list=(ListView)findViewById(R.id.list);
        list.setAdapter((ListAdapter) adapter);

        list.setOnItemClickListener(new OnItemClickListener() {

            @Override
            public void onItemClick(AdapterView<?> parent, View view,
                                    int position, long id) {
                // When clicked, show a toast with the TextView text
                Toast.makeText(getApplicationContext(), "You clicked! Boom!!! =)",
                        Toast.LENGTH_LONG).show();

            }
        });
    }



    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}

 

Finally we are adding ListView in our activity_main.xml. Just copy & paste following code in

activity_main.xml

<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"
    android:background="#f1ff00"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">

    <ListView
        android:id="@+id/list"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true" >
    </ListView>


</RelativeLayout>

Watch Video Tutorial Here

Run your Android App

Now we have successfully created android Custom ListView just one step away. Run your app and Insha-Allah you will get what you wanted. Our custom ListView should looks like

android custom listviewI hope you did found this tutorial helpful and please let me know if you have any trouble while developing custom  android ListView. I will get back to you as quickly as I can. Thanks & enjoy Custom ListView 🙂

]]>
http://www.android-development-tutorial.net/android-custom-listview-example-with-images/feed/ 0
Create Android App for Your Website/Blog [Video Tutorial] http://www.android-development-tutorial.net/create-android-app-for-your-websiteblog-using-webview/ http://www.android-development-tutorial.net/create-android-app-for-your-websiteblog-using-webview/#comments Sun, 29 Nov 2015 15:52:27 +0000 http://www.android-development-tutorial.net/?p=3177 Do you really want to have an android app for your website or blog? Of-course, as every single person want to become an android developer similarly every webmaster keen to have android app for their website to get more and more audience/traffics. Many companies, organization and small business owners’ even webmaster have already published their android app on Google Play Store. Now it’s your turn buddy 🙂

create android app for blog

There are some online tools to create android app but they will cost you for this. In this tutorial I’m going to show you how to create free android app using android studio for free. If you already know basic of Java and Xml language & basic usage of android studio then you are good to go. For beginners, have look at previous android development tutorials to get started even with no knowledge.

Create Android App for Website or Blog

Using android studio, we will manually create android application for website/blog using web view. Make sure that your site is Mobile Friendly otherwise it will create bad impression on user. Let get started,

Open your android studio and create new project with application name of your website or (could be anything) i.e. Android Development Tutorial.

Target the lowest android devices, select blank activity and leave Activity name as MainActivity by default & hit finish button to build your project.

These were basics things to create simple project now we will add important things to create android app for our blog or website.

First of all we will implement splash screen to our project as we have learned in last tutorial. To implement splash screen, check it out,

Read : Android Splash Screen Tutorial Using Android Studio

We will use WebView to show our website / blog contents in our android app online. In short, following are the coding of android app development for website using webview.

Watch Video Tutorial Here

Make sure to change website URL with your web URL in following line in MainActivity.java

mWebView.loadUrl("http://www.android-development-tutorial.net");

MainActivity.java

package com.topitideas.adt;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.graphics.Bitmap;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Menu;
import android.view.MenuItem;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;


public class MainActivity extends Activity {

    private WebView mWebView;
    ProgressBar progressBar;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        mWebView = (WebView) findViewById(R.id.activity_main_webview);

        progressBar = (ProgressBar) findViewById(R.id.progressBar1);

        WebSettings webSettings = mWebView.getSettings();
        webSettings.setJavaScriptEnabled(true);
        mWebView.loadUrl("http://www.android-development-tutorial.net");
        mWebView.setWebViewClient(new HelloWebViewClient());


    }

    private class HelloWebViewClient extends WebViewClient{


        @Override
        public void onPageStarted(WebView view, String url, Bitmap favicon) {
            // TODO Auto-generated method stub
            super.onPageStarted(view, url, favicon);
        }

        @Override
        public boolean shouldOverrideUrlLoading(WebView webView, String url)
        {
            webView.loadUrl(url);
            return true;
        }

        @Override
        public void onPageFinished(WebView view, String url) {
            // TODO Auto-generated method stub
            super.onPageFinished(view, url);

            progressBar.setVisibility(view.GONE);
        }

    }


    @Override
    public boolean onKeyDown(int keyCode, KeyEvent event)
    { //if back key is pressed
        if((keyCode == KeyEvent.KEYCODE_BACK)&& mWebView.canGoBack())
        {
            mWebView.goBack();
            return true;

        }

        return super.onKeyDown(keyCode, event);

    }




    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }

    public void onBackPressed() {
        AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
                MainActivity.this);

        // set title
        alertDialogBuilder.setTitle("Exit");

        // set dialog message
        alertDialogBuilder
                .setMessage("Do you really want to exit?")
                .setCancelable(false)
                .setPositiveButton("Yes",new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog,int id) {
                        // if this button is clicked, close
                        // current activity
                        MainActivity.this.finish();
                    }
                })
                .setNegativeButton("No",new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog,int id) {
                        // if this button is clicked, just close
                        // the dialog box and do nothing
                        dialog.cancel();
                    }
                });

        // create alert dialog
        AlertDialog alertDialog = alertDialogBuilder.create();

        // show it
        alertDialog.show();
    }
}

activity_main.xml

<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"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">

    <ProgressBar
        android:layout_centerHorizontal="true"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:layout_gravity="center_vertical|center_horizontal"
        android:id="@+id/progressBar1"/>

    <TextView
        android:layout_below="@+id/progressBar1"
        android:layout_height="wrap_content"
        android:id="@+id/LoadingText"
        android:layout_width="fill_parent"
        android:text="Loading, Please Wait.."
        android:textSize="20sp"
        android:gravity="center_horizontal">
    </TextView>

    <WebView
        android:id="@+id/activity_main_webview"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>

</RelativeLayout>

SplashScreen.java

package com.topitideas.adt;

/**
 * Created by Saeed on 9/18/2015.
 */
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

/**
 * Created by vamsikrishna on 12-Feb-15.
 */
public class SplashScreen extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash);

        Thread timerThread = new Thread(){
            public void run(){
                try{
                    sleep(3000);
                }catch(InterruptedException e){
                    e.printStackTrace();
                }finally{
                    Intent intent = new Intent(SplashScreen.this,MainActivity.class);
                    startActivity(intent);
                }
            }
        };
        timerThread.start();
    }

    @Override
    protected void onPause() {
        // TODO Auto-generated method stub
        super.onPause();
        finish();
    }

}

splash.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="center"
    android:background="@drawable/splash"
    android:orientation="vertical">

</LinearLayout>

Now we will add piece of coding to AndroidManifest to get Internet Permission along with Splash Screen activity.

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.topitideas.adt" >
    <uses-permission android:name="android.permission.INTERNET"/>

    <application

        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.topitideas.adt.SplashScreen"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name="com.topitideas.adt.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="com.topitideas.tii.MAINACTIVITY" />

                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
        </activity>
    </application>

</manifest>
 

Now Run Your Android App

You are almost done everything, now one thing you need to do before running your app is to put image in drawable folder for splash activity. Now run your android app either on emulator or real device to see whether its work properly or not. Your app will looks like,

android app for website

I hope it will works perfectly Insha-Allah & if you have any trouble or question, leave it in below comments to serve you better.  Enjoy Your Website Android App 🙂

]]>
http://www.android-development-tutorial.net/create-android-app-for-your-websiteblog-using-webview/feed/ 1
Android Splash Screen Tutorial Using Android Studio http://www.android-development-tutorial.net/android-splash-screen-tutorial-using-android-studio/ http://www.android-development-tutorial.net/android-splash-screen-tutorial-using-android-studio/#comments Fri, 27 Nov 2015 16:03:15 +0000 http://www.android-development-tutorial.net/?p=3164 In this tutorial, we are going to create splash startup screen using android studio. Have you ever wondered how does splash screen appears before MainActivity (Home Screen)? You may notice when an application is first open, it show quick startup screen before launching main activity. This quick startup screen could be anything your app/ your company logo for few seconds but unfortunately, we don’t have ready-made code mechanism in android studio for this purpose as compared to iOS. So let create splash screen manually in this quick post.

splash screen android app

How to Create Splash Screen for android app?

To create splash screen project for your android app, copy and paste the codes below to your project to create one of amazing splash screen project.

Open the android studio, create New Project and give Application Name ‘SplashScreen’ to it.

Leave the activity name as by default ‘MainActivity’ and hit the finish button to build the project.

Now create new Java Class under Java folder by right clicking on your package name > New > Java Class. We can give name ‘ SplashScreen.java’ to it. Copy & paste following code.

SplashScreen.java

package com.topitideas.splashscreen;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;

/**
 * Created by Saeed on 9/12/2015.
 */
public class SplashScreen extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.splash);

        Thread timerThread = new Thread(){
            public void run(){
                try{
                    sleep(3000);
                }catch(InterruptedException e){
                    e.printStackTrace();
                }finally{
                    Intent intent = new Intent(SplashScreen.this,MainActivity.class);
                    startActivity(intent);
                }
            }
        };
        timerThread.start();
    }

    @Override
    protected void onPause() {
        // TODO Auto-generated method stub
        super.onPause();
        finish();
    }

}

 

Similarly, create xml file under res folder by right clicking on layout > New > Layout resource file. We can give name ‘splash.xml’ to it. Copy & paste following code.

splash.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/your_image"
    android:orientation="vertical">

</LinearLayout>

 

Make sure you have put an image in your drawable folder & image name should be ‘your_image’ as we mentioned in xml file.

In AndroidManifest.xml, we have to add both activities SplashScreen.java & splash.xml by which our splash screen would be appear before MainActivity (Home Screen). After adding some codes, AndroidManifest.xml will be,

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:action_android="http://schemas.android.com/apk/res-auto"
    package="com.topitideas.splashscreen">

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".SplashScreen"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
        <intent-filter>
            <action android:name="com.topitideas.splashscreen.MainActivity"/>
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
        </activity>

    </application>

</manifest>

 

Keep in mind that MainActivity.java & activity_main.xml will not be modified. So leave both as it is by default. For precaution, coding will looks as following

MainActivity.java

package com.topitideas.splashscreen;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.
        getMenuInflater().inflate(R.menu.menu_main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        //noinspection SimplifiableIfStatement
        if (id == R.id.action_settings) {
            return true;
        }

        return super.onOptionsItemSelected(item);
    }
}

 

activity_main.xml

<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"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity">

    <TextView android:text="@string/hello_world"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />

</RelativeLayout>

 

That’s it, now run your app & Insha-Allah you will see a splash screen of few seconds showing an image before launching home screen. Your project about splash screen has been successfully completed once if you followed our above steps. If you have any trouble, watch our video tutorial below

Watch Video Tutorial

Related : Working with Emulator and Real Devices – Android Development Tutorial

]]>
http://www.android-development-tutorial.net/android-splash-screen-tutorial-using-android-studio/feed/ 12
How To Install and Configure Basics of Android Studio? Android Development Tutorial http://www.android-development-tutorial.net/how-to-install-and-configure-basics-of-android-studio/ http://www.android-development-tutorial.net/how-to-install-and-configure-basics-of-android-studio/#comments Tue, 24 Nov 2015 07:04:30 +0000 http://www.android-development-tutorial.net/?p=14 We know Android Studio is used for development of android application which is also called IDE (Integrated Development Environment) for android development. Before android studio, there was software named Eclipse which was used for same purpose but different between android studio and eclipse are about latest features and some important updates. I don’t know exact reason why eclipse was replaced with android studio, However, In this tutorial we are going to learn how to install android studio and their important tools and packages which helps us to get started with android developing.

Most complex thing in android development is setting up the android development environment and their tools, recommended packages etc. Here we have some clear points should be follow to make It easy for yourself.

Get the Android Studio

Click on Download Android Studio and Sdk Tools to begin downloading the android studio from their official website. Don’t worry about finding exact version for your operating system because they will automatically detect your operating system and will give you link for downloading android studio. You should have look at their requirements first before downloading and once you have successfully download it, begin to installing it on your system. (File size is approximately 1.05Gb)

Installing Android Studio

Welcome to Android Studio Wizard
Welcome to Android Studio Wizard

Now after downloading android studio, we have to install it on our system. Double click on downloaded file which should be named something like android-studio-bundle-141.215484-window.exe. After verifying the installer, your installation will be start and once you have successfully done all the steps then you will see Welcome to Android Studio wizard. Here you have to do following things to make things easy,

  • If you have an old android sample code, import it to android studio by click on “Import and android sample code”.
  • You can also import old project of your (Eclipse adt, Gradle etc.)
  • To install SDK tools and packages, click on Configure > SDK Manager and install recommended packages. ( Click on Recommended Packages )
  • You’re almost done but keep in mind that downloading SDK tools and packages will takes approximately hours to download and install it..

Android SDK Tools

Watch Video Tutorial for better understanding :

So this is the short and handy guide about downloading, installing and setting up the Android Studio on your operating system, In our next tutorials, we will be talking about how to create Hello World android app with detail and some other important requirements of using android studio for android application development.

Important Announcement

This is our quick announcement to let you know about some of the upcoming tutorials and posts related to android development. Insha-Allah we will trying our best to share our knowledge and experience about android development that we learned so far and more than you expecting right now. So I hope you people will surely enjoying our upcoming tutorials about android development and will be able to develop your own android app soon. Thank you brothers for reading and enjoy Android Studio for today. Good Bye 🙂

]]>
http://www.android-development-tutorial.net/how-to-install-and-configure-basics-of-android-studio/feed/ 1