{"id":2077,"date":"2014-05-27T19:51:04","date_gmt":"2014-05-27T15:51:04","guid":{"rendered":"https:\/\/blog.alwawee.ru\/?p=2077"},"modified":"2014-07-28T22:35:33","modified_gmt":"2014-07-28T18:35:33","slug":"add-shortcut-home-screen-android-programatically","status":"publish","type":"post","link":"https:\/\/blog.alwawee.ru\/?p=2077","title":{"rendered":"How to add shortcut to Home screen in Android programmatically"},"content":{"rendered":"<p>I improved a little bit a solution that was found in <a href=\"http:\/\/stackoverflow.com\/questions\/6337431\/android-create-shortcuts-on-the-home-screen\/23893035#23893035\" title=\"http:\/\/stackoverflow.com\/questions\/6337431\/android-create-shortcuts-on-the-home-screen\/23893035#23893035\" target=\"_blank\">StackOverflow<\/a>. Now program saves in preferences whether a shortcut was already added and doesn&#8217;t add it in new launches of an app if user deleted it. This also saves a little bit time, since the code to add an existing shortcut doesn&#8217;t run anymore.<\/p>\n<pre>\r\nfinal static public String PREFS_NAME = \"PREFS_NAME\";\r\nfinal static private String PREF_KEY_SHORTCUT_ADDED = \"PREF_KEY_SHORTCUT_ADDED\";\r\n\r\n\r\n\/\/ Creates shortcut on Android widget screen\r\nprivate void createShortcutIcon(){\r\n\r\n    \/\/ Checking if ShortCut was already added\r\n    SharedPreferences sharedPreferences = getPreferences(MODE_PRIVATE);\r\n    boolean shortCutWasAlreadyAdded = sharedPreferences.getBoolean(PREF_KEY_SHORTCUT_ADDED, false);\r\n    if (shortCutWasAlreadyAdded) return;\r\n\r\n    Intent shortcutIntent = new Intent(getApplicationContext(), IntroActivity.class);\r\n    shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);\r\n    shortcutIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);\r\n\r\n    Intent addIntent = new Intent();\r\n    addIntent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);\r\n    addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, \"YourAppName\");\r\n    addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, Intent.ShortcutIconResource.fromContext(getApplicationContext(), R.drawable.ic_launcher));\r\n    addIntent.setAction(\"com.android.launcher.action.INSTALL_SHORTCUT\");\r\n    getApplicationContext().sendBroadcast(addIntent);\r\n\r\n    \/\/ Remembering that ShortCut was already added\r\n    SharedPreferences.Editor editor = sharedPreferences.edit();\r\n    editor.putBoolean(PREF_KEY_SHORTCUT_ADDED, true);\r\n    editor.commit();\r\n}\r\n<\/pre>\n<p>In <strong>Android Manifest<\/strong>: <\/p>\n<pre>\r\n<uses-permission android:name=\"com.android.launcher.permission.INSTALL_SHORTCUT\" \/>\r\n<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I improved a little bit a solution that was found in StackOverflow. Now program saves in preferences whether a shortcut was already added and doesn&#8217;t add it in new launches of an app if user deleted it. This also saves a little bit time, since the code to add an existing shortcut doesn&#8217;t run anymore. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[35],"tags":[188,68,69,70],"class_list":["post-2077","post","type-post","status-publish","format-standard","hentry","category-android","tag-android","tag-shortcut","tag-stackoverflow","tag-widget"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.6 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>How to add shortcut to Home screen in Android programmatically - Denis Kutlubaev<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/blog.alwawee.ru\/?p=2077\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to add shortcut to Home screen in Android programmatically - Denis Kutlubaev\" \/>\n<meta property=\"og:description\" content=\"I improved a little bit a solution that was found in StackOverflow. Now program saves in preferences whether a shortcut was already added and doesn&#8217;t add it in new launches of an app if user deleted it. This also saves a little bit time, since the code to add an existing shortcut doesn&#8217;t run anymore. [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/blog.alwawee.ru\/?p=2077\" \/>\n<meta property=\"og:site_name\" content=\"Denis Kutlubaev\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/alwaweemobile\" \/>\n<meta property=\"article:published_time\" content=\"2014-05-27T15:51:04+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2014-07-28T18:35:33+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/blog.alwawee.com\/?attachment_id=1982\" \/>\n<meta name=\"author\" content=\"Denis Kutlubaev\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Denis Kutlubaev\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/?p=2077#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/?p=2077\"},\"author\":{\"name\":\"Denis Kutlubaev\",\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/#\\\/schema\\\/person\\\/58f1f1f57155b48afab83ba53b3e26a7\"},\"headline\":\"How to add shortcut to Home screen in Android programmatically\",\"datePublished\":\"2014-05-27T15:51:04+00:00\",\"dateModified\":\"2014-07-28T18:35:33+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/?p=2077\"},\"wordCount\":70,\"commentCount\":3,\"keywords\":[\"Android\",\"Shortcut\",\"StackOverflow\",\"Widget\"],\"articleSection\":[\"Android\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/blog.alwawee.ru\\\/?p=2077#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/?p=2077\",\"url\":\"https:\\\/\\\/blog.alwawee.ru\\\/?p=2077\",\"name\":\"How to add shortcut to Home screen in Android programmatically - Denis Kutlubaev\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/#website\"},\"datePublished\":\"2014-05-27T15:51:04+00:00\",\"dateModified\":\"2014-07-28T18:35:33+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/#\\\/schema\\\/person\\\/58f1f1f57155b48afab83ba53b3e26a7\"},\"breadcrumb\":{\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/?p=2077#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/blog.alwawee.ru\\\/?p=2077\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/?p=2077#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/blog.alwawee.ru\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to add shortcut to Home screen in Android programmatically\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/#website\",\"url\":\"https:\\\/\\\/blog.alwawee.ru\\\/\",\"name\":\"Denis Kutlubaev\",\"description\":\"iOS Development\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/blog.alwawee.ru\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/blog.alwawee.ru\\\/#\\\/schema\\\/person\\\/58f1f1f57155b48afab83ba53b3e26a7\",\"name\":\"Denis Kutlubaev\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/346de75d27c818be0aa7fddeada2e50e30cc15b4da6b3b8110c5d766cd2afa34?s=96&d=mm&r=pg\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/346de75d27c818be0aa7fddeada2e50e30cc15b4da6b3b8110c5d766cd2afa34?s=96&d=mm&r=pg\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/346de75d27c818be0aa7fddeada2e50e30cc15b4da6b3b8110c5d766cd2afa34?s=96&d=mm&r=pg\",\"caption\":\"Denis Kutlubaev\"},\"description\":\"iOS Developer, creator of Tornado Browser and many other popular apps\",\"sameAs\":[\"http:\\\/\\\/dennis.alwawee.com\"],\"url\":\"https:\\\/\\\/blog.alwawee.ru\\\/?author=1\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to add shortcut to Home screen in Android programmatically - Denis Kutlubaev","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/blog.alwawee.ru\/?p=2077","og_locale":"en_US","og_type":"article","og_title":"How to add shortcut to Home screen in Android programmatically - Denis Kutlubaev","og_description":"I improved a little bit a solution that was found in StackOverflow. Now program saves in preferences whether a shortcut was already added and doesn&#8217;t add it in new launches of an app if user deleted it. This also saves a little bit time, since the code to add an existing shortcut doesn&#8217;t run anymore. [&hellip;]","og_url":"https:\/\/blog.alwawee.ru\/?p=2077","og_site_name":"Denis Kutlubaev","article_publisher":"https:\/\/www.facebook.com\/alwaweemobile","article_published_time":"2014-05-27T15:51:04+00:00","article_modified_time":"2014-07-28T18:35:33+00:00","og_image":[{"url":"http:\/\/blog.alwawee.com\/?attachment_id=1982","type":"","width":"","height":""}],"author":"Denis Kutlubaev","twitter_misc":{"Written by":"Denis Kutlubaev","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/blog.alwawee.ru\/?p=2077#article","isPartOf":{"@id":"https:\/\/blog.alwawee.ru\/?p=2077"},"author":{"name":"Denis Kutlubaev","@id":"https:\/\/blog.alwawee.ru\/#\/schema\/person\/58f1f1f57155b48afab83ba53b3e26a7"},"headline":"How to add shortcut to Home screen in Android programmatically","datePublished":"2014-05-27T15:51:04+00:00","dateModified":"2014-07-28T18:35:33+00:00","mainEntityOfPage":{"@id":"https:\/\/blog.alwawee.ru\/?p=2077"},"wordCount":70,"commentCount":3,"keywords":["Android","Shortcut","StackOverflow","Widget"],"articleSection":["Android"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/blog.alwawee.ru\/?p=2077#respond"]}]},{"@type":"WebPage","@id":"https:\/\/blog.alwawee.ru\/?p=2077","url":"https:\/\/blog.alwawee.ru\/?p=2077","name":"How to add shortcut to Home screen in Android programmatically - Denis Kutlubaev","isPartOf":{"@id":"https:\/\/blog.alwawee.ru\/#website"},"datePublished":"2014-05-27T15:51:04+00:00","dateModified":"2014-07-28T18:35:33+00:00","author":{"@id":"https:\/\/blog.alwawee.ru\/#\/schema\/person\/58f1f1f57155b48afab83ba53b3e26a7"},"breadcrumb":{"@id":"https:\/\/blog.alwawee.ru\/?p=2077#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/blog.alwawee.ru\/?p=2077"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/blog.alwawee.ru\/?p=2077#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/blog.alwawee.ru\/"},{"@type":"ListItem","position":2,"name":"How to add shortcut to Home screen in Android programmatically"}]},{"@type":"WebSite","@id":"https:\/\/blog.alwawee.ru\/#website","url":"https:\/\/blog.alwawee.ru\/","name":"Denis Kutlubaev","description":"iOS Development","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/blog.alwawee.ru\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/blog.alwawee.ru\/#\/schema\/person\/58f1f1f57155b48afab83ba53b3e26a7","name":"Denis Kutlubaev","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/346de75d27c818be0aa7fddeada2e50e30cc15b4da6b3b8110c5d766cd2afa34?s=96&d=mm&r=pg","url":"https:\/\/secure.gravatar.com\/avatar\/346de75d27c818be0aa7fddeada2e50e30cc15b4da6b3b8110c5d766cd2afa34?s=96&d=mm&r=pg","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/346de75d27c818be0aa7fddeada2e50e30cc15b4da6b3b8110c5d766cd2afa34?s=96&d=mm&r=pg","caption":"Denis Kutlubaev"},"description":"iOS Developer, creator of Tornado Browser and many other popular apps","sameAs":["http:\/\/dennis.alwawee.com"],"url":"https:\/\/blog.alwawee.ru\/?author=1"}]}},"_links":{"self":[{"href":"https:\/\/blog.alwawee.ru\/index.php?rest_route=\/wp\/v2\/posts\/2077","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.alwawee.ru\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.alwawee.ru\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.alwawee.ru\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.alwawee.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2077"}],"version-history":[{"count":0,"href":"https:\/\/blog.alwawee.ru\/index.php?rest_route=\/wp\/v2\/posts\/2077\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.alwawee.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2077"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.alwawee.ru\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2077"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.alwawee.ru\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2077"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}