Android app to create a mobile desktop shortcut

Source: Internet
Author: User

<linearlayout xmlns:android= "Http://schemas.android.com/apk/res/android"
Xmlns:tools= "Http://schemas.android.com/tools"
Android:layout_width= "Match_parent"
android:layout_height= "Match_parent"
android:orientation= "Vertical" >
<button
Android:id= "@+id/shortcut_btn"
Android:layout_width= "Match_parent"
android:layout_height= "Wrap_content"
android:text= "Shortcuts"
/>
<button
Android:id= "@+id/exit_btn"
Android:layout_width= "Match_parent"
android:layout_height= "Wrap_content"
android:text= "Exit App"/>
</LinearLayout>

---------------------------------------------------------------------------

public class Mainactivity extends Activity {

Private Button shortcutbtn;
Private Button exitbtn;
protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.activity_main);
SHORTCUTBTN = (Button) Findviewbyid (R.ID.SHORTCUT_BTN);
EXITBTN = (Button) Findviewbyid (R.ID.EXIT_BTN);
/** Creating a shortcut */
Shortcutbtn.setonclicklistener (New Onclicklistener () {
public void OnClick (View v) {
/** Create or delete SHORTCUT in intent set action to: Com.android.launcher.action.INSTALL_SHORTCUT
* Also remove the shortcut as: Com.android.launcher.action.UNINSTALL_SHORTCUT
*/
Intent addintent = new Intent ("Com.android.launcher.action.INSTALL_SHORTCUT");
/**android specifically provides Intent.ShortcutIconResource.fromContext to create a shortcut icon, and finally returns it through Setresult */
parcelable icon = Intent.ShortcutIconResource.fromContext (Mainactivity.this, R.drawable.ic_launcher);
Intent myintent = new Intent (mainactivity.this, Mainactivity.class);
/** Application Name */
Addintent.putextra (Intent.extra_shortcut_name, "Application Name");
/** Application Picture */
Addintent.putextra (Intent.extra_shortcut_icon_resource, ICON);
/** Application Startup intent*/
Addintent.putextra (Intent.extra_shortcut_intent, myintent);
Sendbroadcast (addintent);
}
});
/** Exit Application */
Exitbtn.setonclicklistener (New Onclicklistener () {
public void OnClick (View arg0) {
System.exit (0);
}
});
}


}

Android app to create a mobile desktop shortcut

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.