Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-14001] Android: Allow sending extra data to the intent when opening a notification

GitHub Issuen/a
TypeNew Feature
PriorityLow
StatusOpen
ResolutionUnresolved
Affected Version/sn/a
Fix Version/sn/a
ComponentsAndroid
Labelsn/a
ReporterDavide Cassenti
AssigneeUnknown
Created2013-05-28T16:26:35.000+0000
Updated2018-02-28T20:04:06.000+0000

Description

Description of the problem

When clicking on a notification, if we want to restore the app which is in background, is currently not possible to understand if the click comes from the notification or not, as we cannot send extra data

Use case

When clicking on a notification, you want to switch to a particular tab/page of the app. Opening a NEW intent would work (e.g. we can create the intent with extra data), but if we use the currently open one (Ti.Android.currentActivity.intent) there is not way to provide such information.

Comments

  1. Allen Yeung 2013-06-06

    [~dcassenti] Could you provide some clarification on what the issue is here? (A sample case would be helpful) Is there a reason why putExtra() would not work when you are creating a notification?
  2. Davide Cassenti 2013-06-06

    [~ayeung] The problem with putExtra is that, if you do not want to open a new intent, but re-opening the same one, you cannot use it. The idea would be to have something like:
       var activity = Ti.Android.currentActivity;
           var intent = activity.getIntent();
           intent.putExtra(Ti.Android.EXTRA_TEXT, "notification");
       
       var pending = Titanium.Android.createPendingIntent({
           intent: intent,
           flags: Titanium.Android.FLAG_UPDATE_CURRENT
       });
       
       var notification = Titanium.Android.createNotification({
           contentTitle: 'Something Happened',
           contentText : 'Click to return to the application.',
           contentIntent: pending
       });
       
       Ti.Android.NotificationManager.notify(1, notification);
       
    Using this code, you are putting the EXTRA information in the current intent, and resuming it from outside the notification will have no difference.
  3. Allen Yeung 2013-06-06

    I'm not sure I understand the issue. If you call putExtra() on the current intent, back out of the app, and then reopen it with the notification, then intent should have the extra that you placed there.
       var activity = Ti.Android.currentActivity;
       var intent = activity.getIntent();
       
       if (intent.hasExtra(Ti.Android.EXTRA_TEXT)) {
       	Ti.API.info('----------has intent----------');
       
       } else {
       	Ti.API.info('--------------------');
       }
       
       intent.putExtra(Ti.Android.EXTRA_TEXT, "notification");
       
       var pending = Titanium.Android.createPendingIntent({
       	intent : intent,
       	flags : Titanium.Android.FLAG_UPDATE_CURRENT
       });
       
       var notification = Titanium.Android.createNotification({
       	contentTitle : 'Something Happened',
       	contentText : 'Click to return to the application.',
       	contentIntent : pending
       });
       
       Ti.Android.NotificationManager.notify(1, notification);
       
  4. Davide Cassenti 2013-06-07

    [~ayeung] Correct, but the intent also has the EXTRA if you resume it NOT from the notification in that case. The code works fine if the intent is new, as the EXTRA is not added to the running one, and resuming without a notification will not 'open' the one with the EXTRA data. Hope it helps

JSON Source