Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-19679] Android: Added additional type support for IntentProxy

GitHub Issuen/a
TypeNew Feature
PriorityMedium
StatusClosed
ResolutionFixed
Resolution Date2015-12-03T03:47:42.000+0000
Affected Version/sn/a
Fix Version/sRelease 5.2.0
ComponentsAndroid
Labelsandoid, intent, module_android, notable, qe-manualtest, qe-testadded, shortcut
ReporterCollin Price
AssigneeAshraf Abu
Created2015-10-05T18:52:39.000+0000
Updated2016-02-25T09:27:35.000+0000

Description

Issue Description

Currently it is not possible to create a launcher shortcut programmatically using the Titanium platform. Titanium allows for the creation of an Android intent using Ti.Android.createIntent but the implementation of the putExtra method is incomplete. It currently only supports Java primitives. Creating a shortcut requires an intent and an image to be set. Ideally the following example should work:
var currentIntent = Ti.Android.currentActivity.getIntent();
currentIntent.setAction(Ti.Android.ACTION_MAIN);

// Add custom metadata to read when your App is launched from the shortcut.
currentIntent.putExtra("shortcut", "gallery");

// Create an Intent
var shortcutIntent = Ti.Android.createIntent({
  action: "com.android.launcher.action.INSTALL_SHORTCUT",
});

// Title that will appear with the shortcut
shortcutIntent.putExtra(Ti.Android.EXTRA_SHORTCUT_NAME, "Gallery");

shortcutIntent.putExtra(Ti.Android.EXTRA_SHORTCUT_INTENT, currentIntent); // Not currently possible
shortcutIntent.putExtra("duplicate", false);

// Set the icon for the shortcut
var iconImage = Ti.Filesystem.getFile(Ti.Filesystem.resourcesDirectory, "appicon.png").read();
shortcutIntent.putExtra(Ti.Android.EXTRA_SHORTCUT_ICON, iconImage); // Not currently possible

// Adds the shortcut to the home screen.
Ti.Android.currentActivity.sendBroadcast(shortcutIntent);
I have created a pull request that adds the missing input types. https://github.com/appcelerator/titanium_mobile/pull/7073

Comments

  1. Ashraf Abu 2015-12-03

    This PR https://github.com/appcelerator/titanium_mobile/pull/7073 introduces a new feature to pass in an Intent and an Image.
  2. Ashraf Abu 2015-12-03

    PR reviewed, tested and merged.
  3. Lokesh Choudhary 2016-02-01

    Verified the implementation. Now "putExtra" supports images as well. Closing. Environment: Appc Studio : 4.5.0.201601262138 Ti SDK : 5.2.0.v20160131224748 Ti CLI : 5.0.6 Alloy : 1.7.33 MAC Yosemite : 10.10.5 Appc NPM : 4.2.3-1 Appc CLI : 5.2.0-238 Node: 4.2.2 Nexus 5 - Android 5.1.1
  4. Fokke Zandbergen 2016-02-23

    [~msamah] [~lchoudhary] I try to add this to the 5.2 sample but the code in the description doesn't add an additional launcher shortcut for me (Android 6.0 device, 5.2.0.GA).
  5. Lokesh Choudhary 2016-02-23

    [~fokkezb], I had to use this permission in tiapp.xml for the launcher shortcut to get added :
       <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>
       
  6. Fokke Zandbergen 2016-02-24

    Thanks [~lchoudhary], I got it to work. I also found it's better to use Ti.App.Android.launchIntent then Ti.Android.currentActivity.getIntent() since the last one will not be useful if the primary window is no longer the current one. When the app starts I can use Ti.App.Android.launchIntent.getStringExtra() to see if the shortcut was used to launch it. However, if the app is already running the newintent event on either Ti.Android.currentActivity or the current Window/TabGroup's activity doesn't fire. Any idea?
  7. Collin Price 2016-02-24

    @fokkezb I actually had to abandon the launcher shortcut because I could not get newintent working. I figured it was related to the launcher shortcut but maybe this event is broken?
  8. Fokke Zandbergen 2016-02-25

    It looks like it. I'll open a ticket.
  9. Fokke Zandbergen 2016-02-25

    Here it is: TIMOB-20459

JSON Source