1package com.android.settings; 2 3import android.app.LauncherActivity; 4import android.content.Intent; 5import android.view.View; 6import android.widget.ListView; 7 8public class CreateShortcut extends LauncherActivity { 9 @Override protected Intent getTargetIntent() { 10 Intent targetIntent = new Intent(Intent.ACTION_MAIN, null); 11 targetIntent.addCategory("com.android.settings.SHORTCUT"); 12 targetIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); 13 return targetIntent; 14 } 15 16 @Override protected void onListItemClick(ListView l, View v, int position, long id) { 17 Intent shortcutIntent = intentForPosition(position); 18 shortcutIntent.setFlags(Intent.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED); 19 Intent intent = new Intent(); 20 intent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE, 21 Intent.ShortcutIconResource.fromContext(this, R.drawable.ic_launcher_settings)); 22 intent.putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent); 23 intent.putExtra(Intent.EXTRA_SHORTCUT_NAME, itemForPosition(position).label); 24 setResult(RESULT_OK, intent); 25 finish(); 26 } 27} 28