Creation of shortcuts for apps in Android

Source: Internet
Author: User

( i ) use the Send broadcast to create a shortcut : the demo example implements the following functions : in the interface there is a button, click the button to generate a shortcut, and then click on the shortcut to enter the phone call page ;

The build steps are as follows :

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

2: in Activity new one Intent join Action:

_intent.setaction ("Com.android.launcher.action.INSTALL_SHORTCUT");

3: The Other core code is as follows :

Intent _returnintent =NewIntent ();
// set Filter action to create shortcut
_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 icon for the generated shortcut
_returnintent.putextra (Intent.extra_shortcut_icon_resource,
Intent.ShortcutIconResource.fromContext (
Launcheractivity. This, R.drawable.ic_launcher));
Intent _intent =NewIntent (Intent.action_call);
_intent.setdata (Uri.parse ("tel://5556"));
_returnintent.putextra (Intent.extra_shortcut_intent, _intent);
// send broadcast generation shortcuts
Sendbroadcast (_returnintent);
Launcheractivity. This. Finish ();
}

of course, the above to join the call permission :

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

If we want to uninstall the shortcut, we need to add the permission in the layout file

<uses-permission android:name= "Com.android.launcher.permission.UNINSTALL_SHORTCUT"/>

Then the Com.android.launcher.permission.UNINSTALL_SHORTCUT is passed into the intent

( two ): use an Activity, and then click on the Home screen menu-> add Select Shortcut - Select the shortcut for the created application , see the following effect :

Create the steps below :

①: registering Activity in the androidmanifset.xml file

②: add <action/> below the intentfiler tab

Look at The core code in the Activity :

PublicclassShortcutsample extends Activity {
@Override
protectedvoidOnCreate (Bundle savedinstancestate) {
//TODO auto-generated method stub
Super.oncreate (savedinstancestate);
if(Getintent (). Getaction (). Equals (
"Android.intent.action.CREATE_SHORTCUT")) {
Intent _returnintent =NewIntent ();
// Set the name of the shortcut
_returnintent.putextra (Intent.extra_shortcut_name,
"Jiangqq ShortCut");
// set icon for shortcut
_returnintent.putextra (Intent.extra_shortcut_icon_resource,
Intent.ShortcutIconResource.fromContext ( This,
R.drawable.ic_launcher));
Intent _intent=NewIntent (Intent.action_call);
_intent.setdata (Uri.parse ("tel://10086"));
// when the shortcut is created, click the icon to jump to the page where you dialed the call
_returnintent.putextra (Intent.extra_shortcut_intent,NewIntent (
This, Launcheractivity.class));
// Set the return value , usually OK,
Setresult (RESULT_OK, _returnintent);
Finish ();
}
}


Creation of shortcuts for apps in Android

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.