My question is: Can I implement android push notifications in a lan enviroment?
Any tips to do it?
thanks!
My question is: Can I implement android push notifications in a lan enviroment?
Any tips to do it?
thanks!
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:
Without the battery saving mechanism, it's still possible to communicate with an app, but not as "reliably" nor as "battery-efficiently".
Workarounds:
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:
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.
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
© 2022 - 2024 — McMap. All rights reserved.