Mobile notifications through browser based app - java

Is there any way that we can have a 'pure' browser based app on mobile (iPhone & Android) to throw notifications on the mobile device?
If not, could there be a workaround which will allow my app to somehow notify the user of an alert when my app (browser) is in the background?
Thanks for the help.

With 'pure' browser app I understand a WebApp, which is not downloaded through the App Store. And in this case, it's not possible.
You'd have to write a native app with a UIWebView to reach this with push notifications and local notifications.

For this purpose you can use Google Cloud Messaging service, which provides API both for server apps and client apps.
There are sample apps of how you may implement your server application (based on Google App Engine or standalone - for generic application server) as well as mobile application.
There is similar service from Apple as well:
http://developer.apple.com/library/mac/#documentation/NetworkingInternet/Conceptual/RemoteNotificationsPG/ApplePushService/ApplePushService.html
Going this way you'll implement server application, which would be available from any browser (desktop, as well as mobile). So there may be a page for sending a message to a mobile client of your application.

This may be long outdated answers to a decade-old question.
With ServiceWorker you can issue notifications
let notificationId = 0;
function showNotification() {
if(Notification.permission == 'granted') {
self.registration.showNotification("Notification Title", {
title: "Another Title?",
action: "Do as I say, not as I do.",
body: 'Hear ye! Hear ye!',
icon: 'thing-one-and-thing-two.png',
vibrate: [200, 100, 200, 100, 200, 100, 200],
tag: 'notification-'+notificationId++,
renotify: true,
requireInteraction: false
});
}
}
setTimeout(showNotification, 10000);
After you have asked the user to enable notifications in:
Allow Notifications!
So this works if you do it all correctly.
register the service worker
use only HTTPS
have the user enable the notifications.
What is still unclear to me is why I can vibrate but I can't play a sound? Why the vibration doesn't even seem to work on on my android? Why WhatsApp can play a sound anyway (at least if the page web.whatsapp.com is actually open)? Why on my android the notifications do not ever show up in the foreground but only on my lock screen?

Related

How to set notifications badge over app icon

I created a messaging app, I want when some user send a message to another user then that user receives notifications badges over there app icon.
It should be work even app is closed or killed.
Thanks in advance.
I tried some libraries of GitHub but not working.
This is not a feature the of Android system. Device manufacturers (like Xiaomi you mentioned) or launcher developers (like Nova Launcher) can implement it and expose an api for app developers, but there is no standard for that, nor is it expected by the users to be there.

How do whatsapp and instant messaging apps work in background without persistent notification in Oreo?

What I have studied on stackoverflow and Android documentation.
Finally I've concluded this:
There is no way to create a background service for continuous tasks. If I really want a service I should start a foreground service and user continuously sees a persistent notification "App is running". There is no way to hide this notification. It is intentionally added by Google.
Yes there are other options like WorkManager and JobScheduler but they do work periodically not continuously.
What I do want is to build an instant messaging app which continuously connects to the server using xmpp or sockets. But it requires a continuous connection but I don’t want to use a foreground service because it shows an irritating notification to the user "App is running".
Question 1: How does Whatsapp and other instant messaging app continuously connect to the server but not show a persistent notification ? How do they achieve this ?
Question 2: If Whatsapp use FCM for notifications then it will also work in those mobile which do not have playservices installed, so how does Whatsapp notification mechanism works ?
Starting with Android 6.0 (API level 23), Android introduces two power-saving features that extend battery life for users: DOZE and APP STANDBY. These two features enforce many restrictions on your background processing while the phone is in Doze mode. You should read about Doze and app standby in the following link
https://developer.android.com/training/monitoring-device-state/doze-standby
Now, about your use case is that you want to receive the messages and incoming calls even when the app is not running. For this use case, Android announced High Priority FCM messages in GoogleIO2016. They are high priority Push message which grant the application temporary wakelock and network access, independent of Device's Doze state or if the app happens to be in the app standby. This allows the application to react to the message and notify the user in whatever way it wants about the instant message or incoming call.
I don't know exactly how WhatsApp does that unless I look at their code but you can handle your use case using FCM High Priority Messages.
For more about your use case, follow the below link ofGoogleIO2016 Video from 08:30m to 10:30m
https://www.youtube.com/watch?v=VC2Hlb22mZM&t=505s
and read about this use case on the first link in this answer.

Facebook notification when event happens on my server

I'm new to FB API, and I'm completely lost through variety of them. I have Java web app, and FB login to it on my site. How can I send notification to user, when some event happens (for example, his good arrived, and we want to notify him)?
Should I use Cavans application, or Graph API? Is it possible?
https://developers.facebook.com/docs/games/notifications
Currently, only apps on Facebook.com can use App Notifications. Notifications are only surfaced on the desktop version of Facebook.com.
Meaning, App Notifications are for Page Apps or Canvas Apps and you can send them with an App Access Token to every user who authorized your App. I suggest reading the whole article in the Facebook docs, there are some important rules and a lot of important information.

Send data to android app from web client

I'm trying to make it such that a click on my web client from a computer can "trigger" the android app to run its set function.
I've searched extensively but it seems like all methods need the mobile device to initiate a connection before the web server can even do anything.
Is there a way for the web client to be the one initiating? Also, is there any way to do this without notifying the user of the device, i.e. in the background? I'm using cakephp for the web client but any kind of answer will be appreciated. Thanks!
Use push notification system to trigger any action on your device. Push notification system such as Parse, PushApps, pubnup etc are available for free and some are paid too. Try them. Send a push notification and listen to that push message and on receiving trigger your action.
Use Google Cloud Messaging .
"Google Cloud Messaging for Android (GCM) is a service that allows you to send data from your server to your users' Android-powered device, and also to receive messages from devices on the same connection. The GCM service handles all aspects of queueing of messages and delivery to the target Android application running on the target device. GCM is completely free no matter how big your messaging needs are, and there are no quotas."[Google]
Here you'll find how to implement the GCM with PHP.

Android WebView with notification on new message

I have messaging php based application where users login and send messages to each other.
I created an android app that is a WebView pointing to that website to give and in-app feeling to my users.
Now I'd like to add a notification feature to the app which will notify users every time they receive a message.
Is it possible to do so with a WebView based application ?
Thanks
You could send a notification from the php using Google Cloud Messaging every time there is a new message for that user.
Take a look here http://developer.android.com/guide/google/gcm/index.html

Categories