Android Apps developer mobile app create desktop shortcuts _android

Source: Internet
Author: User

Preview Effect Chart:

Permissions Required:

 
 

Configuration file: Androidmanifest.xml

<activity
android:name= "com.myself.news.activity.GuideActivity"
android:label= "@string/title_ Activity_guide ">
<intent-filter>
<action android:name=" Com.myself.news.ACTION_HOME "/>
<category android:name= "Android.intent.category.DEFAULT"/>
</intent-filter>

In the application of the splash screen page The activity of the OnCreate method calls the Installshortcut ();

Code:

Create Shortcut
//Com.android.launcher.permission.INSTALL_SHORTCUT
private void Installshortcut () {
// To determine if a shortcut has been created
boolean iscreated = Sharedpreferencesutils.getboolean (this,
Globalconstantsutils.pref_is_ Shortcut_intalled, false);
Determine if the
if (!iscreated) {
//broadcast
Intent Intent = new Intent ()
has been created. Intent.setaction ("Com.android.launcher.action.INSTALL_SHORTCUT");
Icon
///Generate bitmap object based on resource file ID
intent.putextra (intent.extra_shortcut_icon, Bitmapfactory
. Decoderesource (Getresources (), r.drawable.ic_launcher));
Name
Intent.putextra (Intent.extra_shortcut_name, "mobile security Guardian");
Action
Intent actionintent = new Intent ();
Skip to homepage
actionintent.setaction (globalconstantsutils.action_home);
Intent.putextra (Intent.extra_shortcut_intent, actionintent);
Sendbroadcast (intent);
The tag has already created the shortcut, and the next time you no longer create
Sharedpreferencesutils.setboolean (this,
globalconstantsutils.pref_is_shortcut_ Intalled, True);
}

Constant Tool class Globalconstantsutils:

public static final String pref_is_shortcut_intalled = "is_shortcut_intalled";/whether a shortcut has been created public 
static final String action_home = "Com.myself.news.ACTION_HOME";//Jump to ACTION on main page


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.