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.
Tested this on Mac OS (10.7.2) with the same issue for 1.8.0.1
Pull request ready https://github.com/appcelerator/titanium_mobile/pull/1125
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)
Reopening and closing this issue to update label and Fix Version field.
Anvil test case added. PR Link: https://github.com/appcelerator/titanium_mobile/pull/5380