Create shortcuts for apps in Android and android shortcuts

Source: Internet
Author: User

Create shortcuts for apps in Android and android shortcuts

 

(1) Use sending broadcast to create a shortcut: In this demo, the function is as follows: click a button on the interface to generate a shortcut, click the shortcut to go To the dialing page;

The generation process is as follows:

1: The following permissions: <uses-permission android: name = "com. android. launcher. permission. INSTALL_SHORTCUT"/>

2: Add Action to a new Intent in Activity:

_ Intent. setAction ("com. android. launcher. action. INSTALL_SHORTCUT ");

3. Other core codes are as follows:

Intent _ ReturnIntent = new Intent ();
// Sets the filter action for creating shortcuts
_ ReturnIntent
. SetAction ("com. android. launcher. action. INSTALL_SHORTCUT ");
// Set the name of the generated shortcut
_ ReturnIntent. putExtra (Intent. EXTRA_SHORTCUT_NAME,
"Broad ShortCut ");
// Set the generated shortcut icon
_ ReturnIntent. putExtra (Intent. EXTRA_SHORTCUT_ICON_RESOURCE,
Intent. Reset cuticonresource. fromContext (
LauncherActivity. this, R. drawable. ic_launcher ));
Intent _ Intent = new Intent (Intent. ACTION_CALL );
_ Intent. setData (Uri. parse ("tel: // 5556 "));
_ ReturnIntent. putExtra (Intent. EXTRA_SHORTCUT_INTENT, _ Intent );
// Send broadcast generation shortcut
SendBroadcast (_ ReturnIntent );
LauncherActivity. this. finish ();
}

Of course, the above permission should be added to the call:

<Uses-permission android: name = "android. permission. CALL_PHONE"/>

 

If you want to uninstall shortcuts, you need to add permissions to the layout file.

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

Then, import com. android. launcher. permission. UNINSTALL_SHORTCUT in intent.

(2) Use an Activity, and then click Menu> Add> select shortcut> select the shortcut of the created application on the Home page. The following results are displayed:

The procedure is as follows:

①: Register the Activity in the Androidmanifset. xml file.

②: Add <action/>

Take a look at the core code in the Activity:

Public class ShortCutSample extends Activity {
@ Override
Protected void onCreate (Bundle savedInstanceState ){
// TODO Auto-generated method stub
Super. onCreate (savedInstanceState );
If (getIntent (). getAction (). equals (
"Android. intent. action. CREATE_SHORTCUT ")){
Intent _ ReturnIntent = new Intent ();
// Set the shortcut name
_ ReturnIntent. putExtra (Intent. EXTRA_SHORTCUT_NAME,
"Jiangqq ShortCut ");
// Set the shortcut icon
_ ReturnIntent. putExtra (Intent. EXTRA_SHORTCUT_ICON_RESOURCE,
Intent. Reset cuticonresource. fromContext (this,
R. drawable. ic_launcher ));
Intent _ Intent = new Intent (Intent. ACTION_CALL );
_ Intent. setData (Uri. parse ("tel: // 10086 "));
// After the shortcut is created, click the icon to go to the page for dialing.
_ ReturnIntent. putExtra (Intent. EXTRA_SHORTCUT_INTENT, new Intent (
This, LauncherActivity. class ));
// Set the return value, which is generally OK,
SetResult (RESULT_ OK, _ ReturnIntent );
Finish ();
}
}

 

 

 

 

 

 

 


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.