[TITANIUM]的Intent與Notification

原本想要實現的事情很簡單,就是收到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","https://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都沒有東西。
閱讀全文

[繚乱三国演義]最強同盟決定戰

曹純繚乱三国演義從即日起到1/27舉行第一回的最強同盟決定戰。

活動說明大致如下:

  • 五人以上的同盟可以參加。
  • 一小時會進行一次決戰配對。
  • 在「最強同盟決定戰」的配對中或大戰中無法參加、退出、解散同盟。
  • 每次大戰前兩名的同盟中,貢獻度在前五名內的玩家可以獲得最強同盟決定戰的獎勵。
  • 脫離同盟會連帶扣掉該玩家在原本同盟的超同盟Pt(玩家自己的不會減少)。
  • 每天的排行榜第一位的同盟,給予10張「武功轉蛋券」的獎勵。
  • 活動結束時,會依照同盟排行個人排行個別進行論功行賞。
  • 在「勇將轉蛋」中獲得的武將可以加強在大戰中的攻擊力。
  • 最強同盟決定戰」期間無法逕行平常的同盟戰。

閱讀全文

[TITANIUM] ALLOY與GCM的應用

alloy_GCM上次「[Titanium]用appcelerator的app management實現Push Notification」中有網友問了如何在titanium中使用GCM(Google Cloud Messaging)。當時還想說卡牌遊戲的案子應該夠我忙一陣子了,想不到這麼快我也碰到這樣的案子。剛好titanium的SDK在升級到3.0跟內建ALLOY後我也沒有好好跟它親近一下,趁這個機會實作完就順便筆記一下吧。
這次的需求是透過corepush這個asp來push廣播。所以先參考了它的說明Google APIs Console新建了一個project。但是到了「Create new Server key」這一步會發現我們的API Access中並沒有像他的圖一樣出現「Create new Server key」的選項。原來它少了到serveice中打開「Google Cloud Messaging for Android」這一個步驟。手動打開後就可以順利取得API Key囉。
但是麻煩的才剛剛開始,corepush第四步提供的是原生的java範例,並不適用於我們的titanium。所以接下來就得去參考Google-Cloud-Messaging-Titanium
閱讀全文