Add Remove application shortcut icon on home screen in android

How to automatically show app shortcut icon just after the app installation finished on Home window in android.

Each time when a application installs inside android mobile phone then by default it will not create its App shortcut icon on home screen but creating shortcut on home screen will make the application more easily accessible because user can easily locate the app. So here is the complete step by step tutorial for Add Remove application shortcut icon on home screen in android.

android-project-download-code-button

How to Add Remove application shortcut icon on home screen in android.

Note: Please add INSTALL_SHORTCUT and UNINSTALL_SHORTCUT permission to your AndroidManifest.xml file.

 <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
 <uses-permission android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT" />

Code for MainActivity.java file.

 package com.addappshortcuticononhomescreen_android_examples.com;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

public class MainActivity extends Activity {

 Button buttonAdd, buttonRemove;
 Intent intent, intent2 ;
 
 @Override
 protected void onCreate(Bundle savedInstanceState) {
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_main);
 
 buttonAdd = (Button)findViewById(R.id.button1);
 
 buttonRemove = (Button)findViewById(R.id.button2);
 
 intent = new Intent(getApplicationContext(), MainActivity.class);
 
 intent2 = new Intent();
 
 buttonAdd.setOnClickListener(new View.OnClickListener() {
 
 @Override
 public void onClick(View v) {
 // TODO Auto-generated method stub
 
 AddApplicationShortcutIcon();
 
 }
 });
 
 buttonRemove.setOnClickListener(new View.OnClickListener() {
 
 @Override
 public void onClick(View v) {
 // TODO Auto-generated method stub
 
 RemoveApplicationShortcutIcon();
 
 }
 });
 
 }
 
 public void AddApplicationShortcutIcon(){
 
 intent.setAction(Intent.ACTION_MAIN);
 
 intent2.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent);
 
 intent2.putExtra(Intent.EXTRA_SHORTCUT_NAME, "AddAppShortcutIconOnHomeScreen-Android-Examples.com");
 
 intent2.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
 Intent.ShortcutIconResource.fromContext(getApplicationContext(),
 R.drawable.ic_launcher));

 intent2.setAction("com.android.launcher.action.INSTALL_SHORTCUT"); 

 getApplicationContext().sendBroadcast(intent2);
 
 }
 
 public void RemoveApplicationShortcutIcon(){
 
 intent2.putExtra(Intent.EXTRA_SHORTCUT_INTENT, intent);
 
 intent2.putExtra(Intent.EXTRA_SHORTCUT_NAME, "AddAppShortcutIconOnHomeScreen-Android-Examples.com");
 
 intent2.setAction("com.android.launcher.action.UNINSTALL_SHORTCUT");
 
 getApplicationContext().sendBroadcast(intent2);
 
 }
 
}

Code for activity_main.xml layout file.

 <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: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.addappshortcuticononhomescreen_android_examples.com.MainActivity" >

 <Button
 android:id="@+id/button1"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_alignParentTop="true"
 android:layout_centerHorizontal="true"
 android:layout_marginTop="136dp"
 android:text="Click Here to Add application shortcut icon on home screen in android" />

 <Button
 android:id="@+id/button2"
 android:layout_width="wrap_content"
 android:layout_height="wrap_content"
 android:layout_alignLeft="@+id/button1"
 android:layout_below="@+id/button1"
 android:text="Click Here to Remove application shortcut icon on home screen in android" />

</RelativeLayout>

Code for AndroidManifest.xml file.

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

 <uses-sdk
 android:minSdkVersion="14"
 android:targetSdkVersion="21" />

 <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
 <uses-permission android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT" />
 
 
 <application
 android:allowBackup="true"
 android:icon="@drawable/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>
 </application>

</manifest>

Screenshots:

Add Remove application shortcut icon on home screen in android

App-Shortcut-2

Click here to download Add Remove application shortcut icon on home screen in android project with source code.

Leave a Reply

Your email address will not be published. Required fields are marked *