原本想要實現的事情很簡單,就是收到asp server端的push後,app自己做一個Intent放進Notification後丟出去,然後使用者按下Notification的通知後,在app的webView中打開預先存在Intent中的網址。
事前GCM跟asp的準備當然要先搞定。然後開始準備來存取Intent物件。
第一個先嘗試用putExtra:
Ti.Android.currentActivity.addEventListener('resumed',function(e){ var intent = Titanium.Android.currentActivity.getIntent(); var _url = intent.getStringExtra("gotoURL"); //$.webview.url = _url; }); var intent = Ti.Android.createIntent({ action : Ti.Android.ACTION_MAIN, className : 'tw.idv.Justflyctivity', flags : Ti.Android.FLAG_ACTIVITY_RESET_TASK_IF_NEEDED | Ti.Android.FLAG_ACTIVITY_SINGLE_TOP }); intent.putExtra("gotoURL","http://justfly.idv.tw"); intent.addCategory(Ti.Android.CATEGORY_LAUNCHER); var pending = Ti.Android.createPendingIntent({ intent : intent, type : Ti.Android.PENDING_INTENT_FOR_ACTIVITY, flags : Ti.Android.FLAG_ACTIVITY_NO_HISTORY }); var notification = Titanium.Android.createNotification({ icon: Ti.App.Android.R.drawable.notification_icon, contentIntent : pending, contentTitle : e.data.title, contentText : _message[0], tickerText: _message[0], flags:Titanium.Android.ACTION_DEFAULT | Titanium.Android.FLAG_AUTO_CANCEL | Titanium.Android.FLAG_SHOW_LIGHTS }); Titanium.Android.NotificationManager.notify(1, notification); |
然後發現不管再怎麼試,_url都沒有東西。
繼續閱讀