Browse By

Android Application Shortcut on Home Screen

In last post we learn how to digitally sign android application. In this tutorial we will see how to create Android Application Shortcut on Home Screen, programmatically !!!  Application shortcut  plays very important role, it helps user to access his favorite application easily. To put application on Home screen, user has to long press on application icon to make it visible on Home screen. Isn’t it wonderful when user install your application, application automatically create shortcut on home screen ?
Today we are going to learn how to create android application shortcut on home screen. To perform this task we will use intent class provided by android. We also need to provide below permission to create shortcut .

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

To perform this application we will follow below steps:

  1. We will create preference value ‘isFirstTime’  to check that application is being started first time. If it is first time then we will create  Application short cut.
  2. We will create Explicit Intent pointing to our application. which will be used when someone click on shortcut icon and it will launch our application.
  3. We will create implicit intent with help of
    to create shortcut on Home Screen.
  4. We will set application name with help of EXTRA_SHORTCUT_NAME
  5. We will also provide shortcut application icon with help of EXTRA_SHORTCUT_ICON_RESOURCE
  6. We will send broadcast to fire this implicit intent.
  7. Last but very important we will provide permission <uses-permission android:name=”” /> in AndroidMenifest.xml file.

Let’s do it practically..

Direct Download Full Source Code



Android Application Shortcut on Home Screen

Create New Android Project

  1. Create a new project and fill the required details File ⇒ New ⇒ Android Project
  2. Now open MainActivity class and put below code for creating shortcut.
    package com.vrs.pulse7.shortcutdemo;
    import android.content.Intent;
    import android.content.SharedPreferences;
    import android.os.Bundle;
    public class Pulse7ShortCutDemoActivity extends Activity {
    	// Create Preference to check if application is going to be called first
    	// time.
    	SharedPreferences appPref;
    	boolean isFirstTime = true;
    	/** Called when the activity is first created. */
    	public void onCreate(Bundle savedInstanceState) {
    		// Get preference value to know that is it first time application is
    		// being called.
    		appPref = getSharedPreferences("isFirstTime", 0);
    		isFirstTime = appPref.getBoolean("isFirstTime", true);
    		if (isFirstTime) {
    			// Create explicit intent which will be used to call Our application
    			// when some one clicked on short cut
    			Intent shortcutIntent = new Intent(getApplicationContext(),
    			Intent intent = new Intent();
    			// Create Implicit intent and assign Shortcut Application Name, Icon
    			intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
    			intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "Pulse7 Shortcut Demo");
    							getApplicationContext(), R.drawable.logo));
    			// Set preference to inform that we have created shortcut on
    			// Homescreen
    			SharedPreferences.Editor editor = appPref.edit();
    			editor.putBoolean("isFirstTime", false);
  3. Now open AndroidManifest.xml and set below permission for creating shortcut.
    <uses-permission android:name="" />
  4. Now execute application. Application shortcut will be created only once.

    Android Application Shortcut on Home Screen

    Android Application Shortcut on Home Screen

I hope you like this article. Share your views to to improve content. Happy Coding !!!

Download Full Source Code