Is posible use android push notifications in lan? without internet [closed]
Asked Answered
D

2

7

My question is: Can I implement android push notifications in a lan enviroment?

Any tips to do it?

thanks!

Darladarlan answered 31/10, 2019 at 9:14 Comment(8)
question is how are you planning to connect the devices to lan?Planchet
All devices are connected with static IP, and I got all these IPs in a DB.Darladarlan
Are you talking about the UI aspect of popping up a notification, or are you asking about the network push notification mechanism in android os?Machinegun
@Todd The question was if is possible to use push notification in a lan environment, without internet. Only to send message to an app specific user. Some cases new tasks to do.Darladarlan
@wolobi for clarity, are you referring to i) the "popup user interface" experience, or ii) "leveraging the usually internet based network push notification mechanism over the lan". I believe you wanted [i].Machinegun
@Todd, Imagine a "lan" network, One internal web server and 100 android devices working in the same network. Can the server web send an push notification to an specific device?. This device may have the app opened or closed, and when receive the mesage, "popup user interface".Darladarlan
@wolobi the "popup user interface" part is well documented online. For me, I came looking for the answer to the network part, but the accepted answer is only taking about the ready stuff, not the answer I am looking for. The accepted answer doesn't have any networking solution.Machinegun
@Todd That's true. fixed.Darladarlan
M
4

No. Without the internet, it is not possible to stimulate the OS Push Notification triggering system manually separate to the official OS vendor infrastructure.

There might be a way to do so, with a non-standard means:

  • Spoofed DNS
  • Stolen Push Notifications Certificate
  • (Manually inserted CA [although the certificate is likely pinned in the app])
  • Root OS override

Without the battery saving mechanism, it's still possible to communicate with an app, but not as "reliably" nor as "battery-efficiently".

Workarounds:

  • Keeping your app awake (there are techniques for doing this but not always reliable across many types of devices); AND
  • Your own network channel (TCP connection, HTTP/TCP connection, TCP Polling, HTTP Polling)
  • As a backup, the User can help keep the app running. An indicator can help, showing the user whether or not the app is still connected to the server. For user-reliability, you might be able to display a notification to the user, when the app is about to "deactivate", so the user can help and reactivate the app.

The naming of "Push Notifications" and "Notifications" is ambiguous to many people.

Notifications (without the word Push)

Are defined by Android as

A notification is a message that Android displays outside your app's UI

This is what @FinnMarquardt is helping with in their answer - https://mcmap.net/q/668103/-is-posible-use-android-push-notifications-in-lan-without-internet-closed

This can certainly even done without any network connection at all. When your app starts, you can display a notification like "The App just started". So this concept refers to a UI component that an App can use, and doesn't involve networking.

Push Notifcations

The word "Push" means a lot:

  • Channel - A specific communications channel that is managed by the OS vendor (Google); AND
  • Trigger - A trigger within the OS that wakes up your App
  • NOT a Notification (UI) - This mechanism doesn't display a Notification

The Channel is convenient because you don't need to built that (Protocol, and distribution Server(s)), but it is something you can build yourself.

The Trigger aspect cannot be replicated. It's very important for the whole Smartphone in saving power. It allows apps to go to sleep, and let the OS take care of such a mechanism once for the whole smartphone. For Android, see https://developer.android.com/training/monitoring-device-state/doze-standby, and then take note of the section "Using FCM to interact with your app while the device is idle"

FCM high-priority messages let you reliably wake your app to access the network, even if the user’s device is in Doze or the app is in App Standby mode

The Doze mode of an app cannot wake itself up. You need an OS mechanism to do that, for Android that means a Push Notification (FCM).

A Push Notification mechanism on its own has nothing to do with "Notification" explained earlier. A "Push Notification" MAY trigger the app to display a "Notification", but not necessarily. For example, it might trigger the app which will then take a location (GPS) reading, and send that data to a server.

Machinegun answered 16/8, 2020 at 23:58 Comment(0)
H
3

Not the default firebase service ones since they require you to be connected to the internet to receive the push from firebase.

However you can create a push notification on a device manually,

 NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this, SOME_CHANNEL_ID)
            .setSmallIcon(R.drawable.icon_notif)
            .setColor(getResources().getColor(R.color.primary))
            .setContentTitle(title)
            .setContentText(text)
            .setAutoCancel(true)
            .setStyle(new NotificationCompat.BigTextStyle()
               .bigText(text)
            );

    Intent intent = new Intent(getApplicationContext(), LauncherActivty.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);


    PendingIntent pendingIntent = PendingIntent.getActivity(getApplicationContext(), 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    notificationBuilder.setContentIntent(pendingIntent);
    NotificationManager notificationManager =  (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(notificationGroup, SOME_NOTIFICATION_ID, notificationBuilder.build());

this would create a push notification on this device (or update an existing one)

All that would be left would be to add the communication part between the devices so that the push notification creation is triggered on the target device

https://developer.android.com/training/connect-devices-wirelessly/wifi-direct for example

Heterolecithal answered 31/10, 2019 at 9:51 Comment(1)
What you have described is a popup notification, the display part. "Push notification" refers to the network capability that is run by Google for Android and wakes up the app. It's a low power solution so that the app neither must maintain a network connection to a server nor poll the server. It saves power. OP might be about the UI part (also in error), which makes the question and answer misleading together. Perhaps the question and answer need editing for the benefit of others.Machinegun

© 2022 - 2024 — McMap. All rights reserved.