【发布时间】:2014-12-18 05:03:49
【问题描述】:
我正在使用 Titanium appcelerator(使用合金)创建一个 Android 应用程序,我创建了一个状态栏通知,问题是当通知出现时,我想打开一个特定窗口并在用户点击通知时向其传递一些数据,所以我的代码是:
// Intent object to launch the application
var intent = Ti.Android.createIntent({
action : Ti.Android.ACTION_MAIN,
flags : Ti.Android.FLAG_ACTIVITY_CLEAR_TOP | Ti.Android.FLAG_ACTIVITY_NEW_TASK,
url : "window.js"
});
intent.addCategory(Ti.Android.CATEGORY_LAUNCHER);
intent.putExtra("id", "10");
var activity = Ti.Android.currentActivity;
// Create a PendingIntent to tie together the Activity and Intent
var pending = Titanium.Android.createPendingIntent({
activity : activity,
intent : intent,
type : Ti.Android.PENDING_INTENT_FOR_ACTIVITY,
flags : Titanium.Android.FLAG_CANCEL_CURRENT
});
// Create the notification
var notification = Titanium.Android.createNotification({
// icon is passed as an Android resource ID -- see Ti.App.Android.R.
icon : Ti.App.Android.R.drawable.appicon,
contentTitle : 'Something Happened',
contentText : 'Click to return to the application.',
contentIntent : pending,
flags : Ti.Android.ACTION_DEFAULT | Ti.Android.FLAG_AUTO_CANCEL | Ti.Android.FLAG_SHOW_LIGHTS
});
// Send the notification.
Titanium.Android.NotificationManager.notify(1, notification);
当用户点击通知时,确实,应用程序来到了前面,但在离开的同一个窗口中,而不是想要的窗口。
我快到了,给我一点推力。
谢谢。
【问题讨论】:
标签: android titanium titanium-alloy