@@ -85,18 +85,21 @@ public class MainActivity extends NativeActivity {
8585 public static native void runFile (String fileName );
8686
8787 public void addShortcut (final String path ) {
88- Intent intent = new Intent (getApplicationContext (), MainActivity .class );
89- intent .setAction (Intent .ACTION_MAIN );
90- Intent addIntent = new Intent ();
91- addIntent .putExtra (Intent .EXTRA_SHORTCUT_INTENT , intent );
92- addIntent .putExtra (Intent .EXTRA_SHORTCUT_NAME , "SmallBASIC" );
93- addIntent .putExtra (Intent .EXTRA_SHORTCUT_ICON_RESOURCE ,
94- Intent .ShortcutIconResource .fromContext (getApplicationContext (),
95- R .drawable .ic_launcher ));
96- addIntent .putExtra ("duplicate" , false );
97- addIntent .setAction ("com.android.launcher.action.INSTALL_SHORTCUT" );
98- getApplicationContext ().sendBroadcast (addIntent );
99- showToast ("The shortcut was created and has been placed on your home screen" , true );
88+ Intent shortcut = new Intent (getApplicationContext (), MainActivity .class );
89+ shortcut .setAction (Intent .ACTION_MAIN );
90+ shortcut .setData (Uri .parse ("smallbasic://" + path ));
91+ Intent intent = new Intent ();
92+ int index = path .lastIndexOf ('/' );
93+ String name = (index == -1 ) ? path : path .substring (index + 1 );
94+ intent .putExtra (Intent .EXTRA_SHORTCUT_INTENT , shortcut );
95+ intent .putExtra (Intent .EXTRA_SHORTCUT_NAME , name );
96+ intent .putExtra (Intent .EXTRA_SHORTCUT_ICON_RESOURCE ,
97+ Intent .ShortcutIconResource .fromContext (getApplicationContext (),
98+ R .drawable .ic_launcher ));
99+ intent .putExtra ("duplicate" , false );
100+ intent .setAction ("com.android.launcher.action.INSTALL_SHORTCUT" );
101+ getApplicationContext ().sendBroadcast (intent );
102+ showToast ("The shortcut " + name + " was created and has been placed on your home screen" , true );
100103 }
101104
102105 public int ask (final String title , final String prompt , final boolean cancel ) {
0 commit comments