Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-6928] Android: Intents - missing createPendingIntent() and createNotification() methods

GitHub Issuen/a
TypeBug
PriorityHigh
StatusClosed
ResolutionFixed
Resolution Date2012-01-23T16:14:40.000+0000
Affected Version/sRelease 1.8.0.1
Fix Version/sSprint 2012-01, Release 2.0.0, Release 1.8.1
ComponentsAndroid
Labelsmodule_android, qe-testadded, regression
ReporterShawn Lipscomb
AssigneeBill Dawson
Created2011-12-29T10:39:24.000+0000
Updated2014-02-25T11:26:07.000+0000

Description

Problem

A call to Ti.Android.createPendingIntent() or Ti.Android.createNotification() fails with the following errors:
 
Uncaught TypeError: Object [object Object] has no method 'createPendingIntent'
Uncaught TypeError: Object [object Object] has no method 'createNotification'
The code runs fine in SDK 1.8.0.v20110913141920 (also using V8). This problem completely kills any app that uses notifications.

Test case

var win1 = Ti.UI.createWindow({  
  backgroundColor:'#fff',
  windowSoftInputMode:Ti.UI.Android.SOFT_INPUT_STATE_ALWAYS_HIDDEN,
  exitOnClose:true,
  navBarHidden:true
});
 
var btn1 = Ti.UI.createButton({
  title:'Make Notification',
  width:'auto',
  top:100
});
function DoBtn1Click()
{
  NewNotification(2,Ti.App.name,'I am workin here',null,null,true);
}
btn1.addEventListener('click',DoBtn1Click);
win1.add(btn1);
 
win1.open();
 
function NewNotification(ID, AppTitle, Content, Icon, Ticker, OnGoing)
{
  var AppIntent=Ti.Android.createIntent({
                  flags: Ti.Android.FLAG_ACTIVITY_CLEAR_TOP | Ti.Android.FLAG_ACTIVITY_SINGLE_TOP,
                  className:'org.appcelerator.titanium.TiActivity',
                  packageName:Ti.App.id
                });
  AppIntent.addCategory(Ti.Android.CATEGORY_LAUNCHER);
  var NotificationClickAction=Ti.Android.createPendingIntent({
                                activity:Ti.Android.currentActivity,
                                intent:AppIntent,
                                flags:Ti.Android.FLAG_UPDATE_CURRENT,
                                type:Ti.Android.PENDING_INTENT_FOR_ACTIVITY
                              });
  var NotificationMembers = {contentTitle: AppTitle,
                             contentText: Content,
                             when: 0, // This will keep the time from showing on the notification
                             contentIntent: NotificationClickAction
                            };
  if (Icon != null)
    NotificationMembers.icon='images/'+Icon;
  else // default to barber pole
    NotificationMembers.icon=Ti.Android.R.drawable.progress_indeterminate_horizontal;
 
  if (Ticker != null)
    NotificationMembers.tickerText = Ticker;
 
  if ((OnGoing != null) && (OnGoing))
    NotificationMembers.flags = (Ti.Android.FLAG_ONGOING_EVENT | Ti.Android.FLAG_NO_CLEAR);
 
  Ti.Android.NotificationManager.notify(ID, Ti.Android.createNotification(NotificationMembers));
}

Relevant Q&A:

[1.8.0.1 - createPendingIntent missing from Ti.Android](http://developer.appcelerator.com/question/129961/) Another commenter reports the same problem (slightly different error msg) with Rhino.

Comments

  1. Eli Mor 2011-12-29

    Tested this on Mac OS (10.7.2) with the same issue for 1.8.0.1
  2. Bill Dawson 2012-01-04

    Pull request ready https://github.com/appcelerator/titanium_mobile/pull/1125
  3. Wilson Luu 2012-01-12

    Closing bug. Verified fix on: SDK build: 1.9.0.v20120111233134 Runtime: V8, Rhino Titanium Studio, build: 1.0.8.201201111843 Device: Droid 3 (2.3.4)
  4. Neeraj Gupta 2012-01-23

    Reopening and closing this issue to update label and Fix Version field.
  5. jithinpv 2014-02-25

    Anvil test case added. PR Link: https://github.com/appcelerator/titanium_mobile/pull/5380

JSON Source