Android shortcuts (2) Add shortcuts to desktops

Source: Internet
Author: User

Effect: on the desktop, press the shortcut icon and click "add shortcut ".

1: add


StartActivity (new Intent (ShortCutsActivity. this,
InstallMenuShortcut. class ));

2: Create InstallMenuShortcut


Package com. wop. ShortCuts;

Import android. app. Activity;
Import android. content. Context;
Import android. content. Intent;
Import android. OS. Bundle;
Import android. OS. Parcelable;

Public class InstallMenuShortcut extends Activity {
Private Context mContext;

@ Override
Public void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
// The shortcut Intent to add
Intent addShortcut = new Intent ();
MContext = this;
AddShortcut. putExtra (Intent. EXTRA_SHORTCUT_NAME, mContext
. GetResources (). getString (R. string. app_name ));
Parcelable icon = Intent. Reset cuticonresource. fromContext (this,
R. drawable. ic_launcher); // icon of the ic_launcher shortcut
AddShortcut. putExtra (Intent. EXTRA_SHORTCUT_ICON_RESOURCE, icon );
Intent ootStartIntent = new Intent (mContext, ShortCutsActivity. class); // The ShortCutsActivity shortcut must start the first Activity of the program
OotStartIntent. addFlags (Intent. FLAG_ACTIVITY_NEW_TASK );
AddShortcut. putExtra (Intent. EXTRA_SHORTCUT_INTENT, ootStartIntent );
SetResult (RESULT_ OK, addmediacut );
Finish ();
}
}

3: Add Manifest: www.2cto.com

<Activity
Android: label = "@ string/app_name"
Android: name = ". InstallMenuShortcut">
<Intent-filter>
<Action android: name = "android. intent. action. CREATE_SHORTCUT"/>
</Intent-filter>
</Activity>


 


It is taken from birds and birds without waiting for a day or night.

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.