0
我成功地在我的項目中包括一個C2DM Module(Android的雲到設備消息傳遞框架),並已能夠成功註冊和接收Android推送通知。但是,我注意到,每隔一段時間,當我發送通知時,新的通知不會顯示在設備上。 今天,我插入我的設備並使用adb logcat,並注意到IntentService [c2dmBaseReceiver]實際上正在被觸發,並且它收到了我發送的消息,但回調函數並不是因爲V8 Runtime已被處置(請參閱以下內容從logcat的線)Appcelerator鈦V8運行時處置,而C2DM接收
D/C2DMReceiver(1069): (IntentService[C2DMBaseReceiver]) [369956,441456] Message received
D/C2DMReceiver(1069): (IntentService[C2DMBaseReceiver]) [1,441457] Message key: message value: This is a test notification
D/C2DMReceiver(1069): (IntentService[C2DMBaseReceiver]) [0,441457] Message key: title value: myAppName
D/C2DMReceiver(1069): (IntentService[C2DMBaseReceiver]) [2,441459] Message key: tickerText value: Notification Ticker
D/C2DMReceiver(1069): (IntentService[C2DMBaseReceiver]) [1,441460] Message key: from value: [email protected]
D/C2DMReceiver(1069): (IntentService[C2DMBaseReceiver]) [0,441460] Message key: collapse_key value: myApp Alert
W/V8Function(1069): Runtime disposed, cannot call function
這是我的回調
callback:function(e)
{
Ti.API.info('JS message event: ' + JSON.stringify(e.data));
var intent = Ti.Android.createIntent({
action: Ti.Android.ACTION_MAIN,
flags: Ti.Android.FLAG_ACTIVITY_NEW_TASK | Ti.Android.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED,
className: 'com.avivas.myApp.myAppActivity',
packageName: 'com.avivas.myApp'
});
intent.addCategory(Ti.Android.CATEGORY_LAUNCHER);
var pending = Ti.Android.createPendingIntent({
activity: Ti.Android.currentActivity,
intent: intent,
type: Ti.Android.PENDING_INTENT_FOR_ACTIVITY,
});
var notification = Ti.Android.createNotification({
contentIntent: pending,
contentTitle: e.data.title,
contentText: e.data.message,
tickerText: e.data.tickerText
});
Ti.Android.NotificationManager.notify(1, notification);
Titanium.Media.vibrate([0,300, 100, 300]);
}
我假設,因爲從C2DM回調函數是在JavaScript中,它不能執行,因爲V8引擎運行時已被釋放。 有沒有人可以證實這一點?另外,是否有任何解決方法,因爲我希望在收到通知時顯示通知?