First of all I don't know what type of code to put for my problem.
I'm developing an Android mobile game, with two ways to earn ruby, via mini transactions or via the OfferWall IronSource.
Regarding the OfferWall, those are tasks to complete to then receive Ruby in exchange.
Now my problem that I would very much like to solve
When a user completes a task and the app is not running, how can I send a notification?
zigg, my suggestion would be to call firebase notification while running background service or you can use push notification as Blundell suggested in background service.
The background service will run even if the app is not running. I use foreground services and call push notification in the service when the app is closed or in background.
Hope this helps.
Related
I know we can START_STICKY service or use receiver event for start service in android
I'm making chat app for android with java that this service must be active in
any mode in android
There are many method for keep alive this service
START_STICKY
Use phone event
Start Foreground
But I dont know what is best way for keep alive service and android 8 and other version
You know that for chat app,service must be active always for receive new messages
Thanks
I found best solution
We dont have any problem about alive service in android 7 and lower version
Main problem is in android version 8
We can associate service to BroadcastReceiver in manifest and have alive service always
BroadcastReceiver can be TICK or CONNECTIVIYCHANGED or SCREEN event that when this events
occur so us service started without any problem
Thanks
I have a Java web application which needs to send manual and automatic notifications to the user.
This notification should go to the user's browser as well as the mobile devices (both iOS & Android).
I found out there is no way to send notifications to mobile devices directly if there is no native application running on the mobile device. So my only option seems to be web push notifications. I went through a few articles and I found it very confusing. I don't know where to start.
Can I send the notifications directly from Java Code? Or do I have to use FCM(Firebse)? If so can I call FCM directly from Java code, such as by calling it using Apache http client libraries?
How does the FCM, client's browser and my application connect?
I also found out that a service worker should run in the background to receive the notifications. How do I integrate it with the Java code?
You can send them directly without using FCM and there are several libraries available, including a Java one.
Unfortunately iOS currently has no support for Web Push. Subscriptions to your service are on a device level rather than by user, so if I sign up on my desktop you cannot send notifications to my mobile unless I sign up again in my mobile browser.
Notifications pushed to Android will be displayed if an instance of the browser is running, in the real world (for me anyway) Chrome always seems to be running in the background somewhere so I get notifications through in pretty much real time. The downside is web push notifications go straight into the notification shade, they do not pop up on screen first.
The rough workflow goes like this:
User visits your page, you load service worker and check for web push
capability, if satisfied you can request permission to send
notifications.
If user grants permission you pass your public key to your service
worker to create a subscription for that user, this returns an
endpoint and two keys which you need to push a notification to them.
Your webpush library runs as a server instance and takes care of all
the encryption and token handling, you configure it however you like
to dispatch messages, usually in response to HTTP POST requests but
it's up to you.
Within your service worker you define an event handler for receipt of
a push message. This is where you create and display the notification
to the user, again how you do this is up to you.
You can pass parameters in the payload of the notification and use them as variables within the notification you display or you can hard code values, you can specify different behaviours depending upon whether the user has your page in focus or not, you can add buttons and set different actions for them, trigger events upon dismissal, customise the vibrate pattern, replace or stack the notifications, access the data in existing notifications etc etc. All this is handled by your service worker, receiving the notification alone does nothing at all.
Your service worker is just a script written in javascript which you link from your page. It is loaded and installed by the browser the first time a user visits and then runs independently when invoked.
Service workers are very powerful. You can also use them to implement complex caching rules, serve content while offline, push data between different browser windows etc. A service worker can spawn more service workers and as they run outside of the main thread of your browser they are ideal for offloading cpu intensive tasks to without delaying the rendering of your page.
Final point to note, your site must be served over SSL to be able to deploy a service worker.
1) It depends a bit on where the Java code that sends a message runs.
If it runs in an Android device, then there is no way to securely send messages from that code. See my answer here for more details: How to send one to one message using Firebase Messaging
If the code runs in an environment you control (such as a server you control, or Cloud Functions), you can call the FCM HTTP end points documented here. The Java Admin SDK doesn't support sending messages yet, although it seems to be under consideration.
Currently working on an Android application that enables people to alert other people in the same network that have said app installed on their android device. It uses Java's Network Service Discovery classes to accomplish this.
There's a background android service that advertises a network service to the network, so the device can be seen and communicated with by other devices in the network. It calls
mNsdManager.registerService(serviceInfo, NsdManager.PROTOCOL_DNS_SD, mRegistrationListener);
to register the service on the network.
This background service runs at all times when the device is connected to a WiFi-network to ensure availability.
All the functionalities that have been implemented work fine, until the phone gets put to sleep.
When that happens the network service, which is supposed to be broadcasted at all times, stops showing up.
I assume this is not a bug, but normal behaviour since the Android background service is stopped(?) and as such stops sending packets to the network when the phone is put to sleep.
How can I solve this issue? Do I need to take a different approach entirely?
I use gottox/socket.io-java-client on android chat app.And Now I want to use socket.io as a background service.In chat app If a new message (when chat app is closed),send a notification like "new message on chat app-click here if you want to see.
How can I do that? I did a chat app with node.js,gottox on android.But I need this app work as a background service on phone.Do you have any plugins or examples?
A service or any other Android component can be closed by the operating system. The solution is to use Android notifications to wake up any component.
My app will be running in the background and uploads data to the server from time to time. Everything works fine, except that I want my app NOT to upload data to the server on its own by turning on network services. Instead, I want it to only start the upload process when another app or service has started a connection. In some words, I wanna be parasitic to the other app.
I know for a fact that this can be done in Android, however I couldn't find anything in the documentation. Any idea?
I would try registering for the broadcast intent WifiManager.NETWORK_STATE_CHANGED_ACTION, via a BroadcastReceiver. See http://developer.android.com/reference/android/net/wifi/WifiManager.html#NETWORK_STATE_CHANGED_ACTION.
Hope that helps!