I need my notification to pop up there with a list of items.
Now when I click on an item in the list I want the notification to shift focus to my app and close the notification.
I tried some code you gave me but was inadequate to provide the help I needed.
I even wrote the code in a service but abandoned it all together.
Have you considered using multiple notifications, one for each option?
I have no idea who you are addressing when you write "I tried some code you gave me"
It would have been more helpful to provide a link to the previous help.
It would be even more helpful if you posted the code you have tried along with a description of what you expected it to do and what happened that was different from what you expected.
<!DOCTYPE html>
<html>
<body>
<button onclick="notifyMe()">Notify me!</button>
<script>
function notifyMe() {
// Let's check if the browser supports notifications
if (!("Notification" in window)) {
alert("This browser does not support desktop notification");
}
// Let's check if the user is okay to get some notification
else if (Notification.permission === "granted") {
// If it's okay let's create a notification
var notification = new Notification("Hi there!");
}
// Otherwise, we need to ask the user for permission
// Note, Chrome does not implement the permission static property
// So we have to check for NOT 'denied' instead of 'default'
else if (Notification.permission !== 'denied') {
Notification.requestPermission(function (permission) {
// Whatever the user answers, we make sure we store the information
if(!('permission' in Notification)) {
Notification.permission = permission;
}
// If the user is okay, let's create a notification
if (permission === "granted") {
var notification = new Notification("Hi there!");
}
});
}
}
</script>
</body>
</html>2) What code is in your Service.js file?
3) Will you be keeping the foreground app open all the time or will the service be opening it by code?
4) Do you really need a service? If you want to open an app in response to a notification being touched, you can do that directly in a normal app without a service
When I suggested you post the code you had tried, I wrote:
"It would be even more helpful if you posted the code you have tried along with a description of what you expected it to do and what happened that was different from what you expected."
Without that, we can only guess what you are looking for and guessing is just a waste of our time.
2) Looks like you may be able to do something from that start
3) you can open the main app by calling
app.StartApp() without any parameter
4) that seems like a sensible reason to use a service.
If you continue to only send the notification in response to a message from the service, your notification will close when it is pressed
Once you have some code you would expect to work, I'm sure you will address the following question:
5) what do you expect your code to do? what happens that is different from what you expect?
2) Looks like you may be able to do something from that start
ANS: I would definitely consider migrating my windows.Onload code into the OnStart() function.
3) you can open the main app by calling app.StartApp() without any parameter.
ANS: Thanks that's very helpful.
4) that seems like a sensible reason to use a service.
ANS: Yeah. I actually discarded the service idea because it appeared to slow my phone and make it hot but later figured it was from my little memory space.
I will revert to service. In the meantime i am using recurring function calls using the setInterval.
If you continue to only send the notification in response to a message from the service, your notification will close when it is pressed.
ANS: No problem if it closes on click. But my issue is that how do I get some action performed on clicking the notification ?
Once you have some code you would expect to work, I'm sure you will address the following question:
ANS: how do I get some action performed on clicking the notification ?
Where do I put the code. i thought of notificationObject_OnTouch()
Is there an event for the notificationObject at all ?
5) what do you expect your code to do? what happens that is different from what you expect?
ANS: I expect my code to
a. open the app
b. display a div in html (I have these areas under control. My issue is where to put the code when the notificationObject is clicked)
function OnStart()
{
var id = app.GetNotifyId();
if( id ) app.Alert( id, "Notification ID" );
else
{
not = app.CreateNotification();
not.SetMessage(
"You have an urgent notification",
"Press me!", "Do as the title says."
);
not.Notify( 1234 );
setTimeout( app.Exit, 2000 );
}
}
function OnData( isStartUp )
{
var id=app.GetNotifyId();
if(id == "touchable") OnNotification(id);
}
function OnNotification(id)
{
app.ShowPopup( "notification touched" );
//remove following line if you want to leave notification on screen
notify.Cancel( id );
}It is worth noting that none of this stuff was written fot html apps1. What are the specifications for the notification icons (big and small)?
2. What is the isStartUp in the following code and how do i use it?
Function OnData(isStartUp){
.....
}
Small is one single colour on a transparent background.
That is the combination I find works best on all devices. Samsung ignore the Android rules on colour for displaying the small icon, at least for some versions of Android.
OnData is fired every time your app receives a targeted intent and isStartup is a boolean so you can tell if it may be a blank intent received at startup.
It is not really useful when receiving notifications.
Check if app.GetNotifyId() returns something instead.