<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