Hello Friends,
Today I am going to share very useful code for creating application shortcut on Home-Screen in android. If we upload our application on Google store, google automatically creates shortcut of application, but if we want create our own launcher use broadcast receiver. Just copy paste below code and enjoy.
I am using shared-preference for checking app first time install, else it will create many shortcut every-time.
Note: don't forget to add permission in your manifest for create shortcut.
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
1)MainActivity.java
2)activity_main.xml
3)AndroidManifest.xml
Today I am going to share very useful code for creating application shortcut on Home-Screen in android. If we upload our application on Google store, google automatically creates shortcut of application, but if we want create our own launcher use broadcast receiver. Just copy paste below code and enjoy.
I am using shared-preference for checking app first time install, else it will create many shortcut every-time.
Note: don't forget to add permission in your manifest for create shortcut.
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
1)MainActivity.java
package
com.manish.home.shortcut;
import
android.app.Activity;
import
android.content.Context;
import
android.content.Intent;
import
android.content.SharedPreferences;
import android.os.Bundle;
import
android.preference.PreferenceManager;
/**
*
* @author manish
*
*/
public class MainActivity extends Activity {
Context
mContext=MainActivity.this;
SharedPreferences
appPreferences;
boolean isAppInstalled = false;
@Override
public void onCreate(Bundle
savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
/**
* check if application is running first time,
only then create shorcut
*/
appPreferences = PreferenceManager.getDefaultSharedPreferences(this);
isAppInstalled = appPreferences.getBoolean("isAppInstalled",false);
if(isAppInstalled==false){
/**
* create short code
*/
Intent
shortcutIntent = new Intent(getApplicationContext(),MainActivity.class);
shortcutIntent.setAction(Intent.ACTION_MAIN);
Intent
intent = new Intent();
intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "ShortcutDemo");
intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,Intent.ShortcutIconResource.fromContext(getApplicationContext(),
R.drawable.logo));
intent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
getApplicationContext().sendBroadcast(intent);
/**
* Make preference true
*/
SharedPreferences.Editor
editor = appPreferences.edit();
editor.putBoolean("isAppInstalled", true);
editor.commit();
}
}
}
<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">
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="Short Cut Demo!"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.manish.home.shortcut"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"
/>
<application
android:icon="@drawable/logo"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="com.manish.home.shortcut.MainActivity"
android:exported="true"
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>
Thanks,
Manish
Manish
Hi Manish,
ReplyDeleteThanks for posting this . I have been looking for 3 days.
Finally, I got. Thanks once again. :D
Thanks & your most welcome dear :)
DeleteThanks for posting this
ReplyDeleteYour Welcome and Thanks!
DeleteHello. How do if uninstall app?
ReplyDeleteI think it should automatic remove shortcut on uninstall app. is it?
Deletehey manish can i know how to put entries from one database and make it into a checkbox
ReplyDeleteexample:
-Enter Name: Manish
-Click save button
when viewed it would be on a checkbox
Hi Albert, You have very tough requirement. I think here some confusion i think you want checkbox with that data like-
Delete"Select your option from list-"
1)Milk
2)Fruit
3)etc
and in-front of all data you need a checkbox right?
please have a look here may be it will help you-
http://www.androidhub4you.com/2013/09/android-dynamic-check-box-example-check.html
I want to store something I entered into a database and retrieve it into a checkbox
ReplyDeleteEnter animal: dog
Enter animal: cat
Enter animal: bat
Then when i clicked a button it would save into database and at the same time would be called into a checkbox
Checkbox
��cat
��dog
��bat
when i check both dog and cat it would go to another layout
i dont need fixed array data rather i need it to save everything and put those values all the things i have entered into a checkbox. So what ever you type or enterd will be in the checklist/ checkbox. Thankyou sir i hope you can help me in my project
ReplyDeletei havent found the solution yet sir can u help me
ReplyDeleteAt-least create demo app from where you can get data and send me your demo app over my email then i can try if it is possible.
Deletesir i sent you in ur email manishupacc@gmail.com right? hope u can help new and young students like me
ReplyDeleteI am not getting what you have did in your demo app. please let me know you want checkbox values from sqlite or something else?
Deletei want all the name i entered in one edittext be viewed in a checkbox listview
DeletePlease check your email. I hv sent you demo app hope it will help you...
DeleteHello Manish sir, i wants to create shortcut at installation time.Please guide me.
ReplyDeleteHow to create shortcuts of all installing apps from launcher or app drawer????
ReplyDeletei want to make an app in which there is a grid view or listview in which all installed apps exist and after selecting any app shortcut should b appear on Home Screen.
plz help me.(sorry for my bad english)..Thanks in advanced.
Hi Saqib, I am not sure but it should be possible using package name of any application.
Deletei have done but there is one problem,only App package name is showing on homescreen app icon is not showing,android default icon is showing on homescreen with package name after long press on App.
DeleteIts seems getting launcher code is not working, please check it should work because i have a app lock app and in this app i am getting all the icons perfectlly.
DeleteHai sir I want to add grid view items into the listview using long press listener but listview placed in sliding drawer so i dont know how to do pls help me,my project about GoLauncher,Apex Launcher.
DeleteThank you ever so much!
ReplyDeleteyour welcome buddy.
DeleteThank you for sharing this!!
ReplyDeleteYour welcome!
Deletecode is running fine but no shortcut is created in homescreen??
ReplyDeletecode is running fine but no shortcut is created in homescreen??
ReplyDeleteDid you check all pages?
DeleteThank you .. it's really helpful .. thank you >.<
ReplyDeleteThanks.. But is there any way to create the shortcut without openning the application???
ReplyDeleteYou have to call that service to create shortcut so if you can call that without opening app you can create shortcut too.
DeleteBTW when you will upload your application on play-store shortcut automatically will be create.
Delete