• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 package com.android.settings;
2 
3 import android.app.LauncherActivity;
4 import android.content.Intent;
5 import android.view.View;
6 import android.widget.ListView;
7 
8 public class CreateShortcut extends LauncherActivity {
getTargetIntent()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 
onListItemClick(ListView l, View v, int position, long id)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