3

我正在使用钛 sdk 版本 3.1.1.GA 为 android OS 开发一个移动应用程序,我正在努力让它工作。我想要做的是当我点击通知时打开一个特定的窗口。我可以显示通知,但是当我单击它时,它会显示活动堆栈中的最后一个窗口。

我的代码从 service.js 创建通知

var intent = Ti.Android.createIntent({
    action : Ti.Android.ACTION_MAIN,
    // className : '<application id>.NotifierActivity',
    url : 'alertmsg.js',
    flags : Ti.Android.FLAG_ACTIVITY_NEW_TASK | Ti.Android.FLAG_ACTIVITY_CLEAR_TOP
});
intent.addCategory(Titanium.Android.CATEGORY_LAUNCHER);

// Create a PendingIntent to tie together the Activity and Intent
var pending = Titanium.Android.createPendingIntent({
    intent: intent,
    flags: Titanium.Android.FLAG_UPDATE_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.my_icon,
    contentTitle: 'Reminder pending',
    contentText : 'Click to return to the application.',
    contentIntent: pending,
    //sound: 'click.mp3',
    defaults: Titanium.Android.NotificationManager.DEFAULT_ALL,
});
// Send the notification.
Titanium.Android.NotificationManager.notify(1, notification);

我的 TiApp.xml 文件中的代码

<android xmlns:android="http://schemas.android.com/apk/res/android">
    <services>
        <service type="interval" url="logservice.js"/>
    </services>
    <manifest>
        <uses-permission android:name="android.permission.VIBRATE" ></uses-permission>
    </manifest>
    <application>
        <activities>
            <activity url="alertmsg.js">
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
                    <category android:name="android.intent.category.BROWSABLE"/>
                </intent-filter>
            </activity>
        </activities>
    </application>
</android>

有什么帮助吗??提前致谢。

4

0 回答 0