Advertisement
Guest User

Untitled

a guest
Nov 24th, 2014
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. Intent shortcutIntent = new Intent(this.getApplicationContext(),
  2. Shortcut_Activity.class);
  3.  
  4. shortcutIntent.setAction(Intent.ACTION_MAIN);
  5.  
  6. Intent addIntent = new Intent();
  7. addIntent
  8. .putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
  9. addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, name);
  10. addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
  11. Intent.ShortcutIconResource.fromContext(this.getApplicationContext(),
  12. R.drawable.ic_shortcut));
  13. addIntent.putExtra("ID", id); //THIS IS THE EXTRA DATA I WANT TO ATTACH
  14. addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
  15. this.getApplicationContext().sendBroadcast(addIntent);
  16.  
  17. void returnShortcut(int rowId, String shortcutName) {
  18. Intent i = new Intent(this, ShowInfoActivity.class);
  19. i.setData(ContentUris.withAppendedId(BASE_URI, rowId));
  20. Intent shortcut = new Intent();
  21. shortcut.putExtra(Intent.EXTRA_SHORTCUT_INTENT, i);
  22. shortcut.putExtra(Intent.EXTRA_SHORTCUT_NAME, shortcutName);
  23. setResult(RESULT_OK, shortcut);
  24. finish();
  25. }
  26.  
  27. private void addShortcut() {
  28. //Adding shortcut for MainActivity
  29. //on Home screen
  30. Intent shortcutIntent = new Intent(getApplicationContext(),
  31. HOMESHORTCUT.class);
  32. //Set Extra
  33. shortcutIntent.putExtra("extra", "shortCutTest ");
  34.  
  35. shortcutIntent.setAction(Intent.ACTION_MAIN);
  36.  
  37. Intent addIntent = new Intent();
  38. addIntent
  39. .putExtra(Intent.EXTRA_SHORTCUT_INTENT, shortcutIntent);
  40. addIntent.putExtra(Intent.EXTRA_SHORTCUT_NAME, "HelloWorldShortcut");
  41. addIntent.putExtra(Intent.EXTRA_SHORTCUT_ICON_RESOURCE,
  42. Intent.ShortcutIconResource.fromContext(getApplicationContext(),
  43. R.drawable.ic_launcher));
  44.  
  45. addIntent.setAction("com.android.launcher.action.INSTALL_SHORTCUT");
  46.  
  47. getApplicationContext().sendBroadcast(addIntent);
  48.  
  49.  
  50. }
  51. //GET Extra in HOMESHORTCUT activity.
  52. @Override
  53. protected void onCreate(Bundle savedInstanceState) {
  54. super.onCreate(savedInstanceState);
  55. mTextExtra=new TextView(this);
  56. Bundle bundel=getIntent().getExtras();
  57. String getExString=getIntent().getExtras().getString("extra");
  58. mTextExtra.setText(getExString);
  59. setContentView(mTextExtra);
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement