2

I have a few admin users in my android app and others are normal users. the mapping between them is one to many i.e. each admin is mapped to one or many users but each user must have only one admin. how can i configure my app so that admin users can send push notifications from their device to the users' device mapped to it.

PS: Mapping between user and admin may change.

i have read about - GCM/FCM. but they don't allow to send push notification from device. nor they provide any mapping as i described.

Abbas Kararawala
  • 1,154
  • 9
  • 19
  • you can use FCM, it allows you to send notification from device – Divyesh Patel May 18 '17 at 05:36
  • fcm allows to create groups called TOPIC – Divyesh Patel May 18 '17 at 05:42
  • @DivyeshPatel Could you point out your reference for that? I'd be very much interested with it. – AL. May 18 '17 at 05:42
  • check fcm docs. and sample code. it has everything you want to do – Divyesh Patel May 18 '17 at 05:42
  • @AbbasKararawala You could [manage device groups on client side](https://firebase.google.com/docs/cloud-messaging/android/device-group#managing-device-groups-on-android-client-apps). But never send a downstream message from any device other than the server. – AL. May 18 '17 at 05:44
  • @DivyeshPatel I'm fairly familiar with the docs. However I'm very interested where it was pointed out that "*FCM allows you to send notification from device*". Since this is wrong. Would appreciate it if you can point it out, then maybe we could point it out to someone from the Firebase Team so that it would be updated. – AL. May 18 '17 at 05:45
  • @AL.how about creating a webservice on server that can be triggered via rest from any android app? – Abbas Kararawala May 18 '17 at 05:47
  • yes. you can send Notification from device also. You have to make Json object in app with key,text and other required data and call fcm ENDPOINT api and send notifictaion – Divyesh Patel May 18 '17 at 05:47
  • @AbbasKararawala Sounds like something you could do with [Cloud Functions for Firebase](https://firebase.google.com/docs/functions/). – AL. May 18 '17 at 05:48
  • check this: http://stackoverflow.com/a/41982419/6756514 – Divyesh Patel May 18 '17 at 05:48
  • 1
    @DivyeshPatel That is *doable*, but **strongly unadvised**. Sending a Downstream message from the device means that you'd include the Server Key on client side, which exposes it for abuse. Not at all the correct usage. – AL. May 18 '17 at 05:49
  • you are right, but here admin send notification to users. and there are few admins so security issues not problematic – Divyesh Patel May 18 '17 at 05:50
  • @DivyeshPatel Yes. *Doable*. But if you look at the [accepted answer](http://stackoverflow.com/a/38028340/4625829), it is *strongly advised* for downstream messages to only come from a Server to protect the Server Key. – AL. May 18 '17 at 05:51
  • that's correct. It is good practice to use SERVER side code to send notification. – Divyesh Patel May 18 '17 at 05:52
  • guys guys! i think i lost you here. shall i go ahead with the webservice practice or you have something to replace that? – Abbas Kararawala May 18 '17 at 05:53
  • 1
    @AbbasKararawala Sorry about that. Depending on your use-case, you could make use of either Upstream Messaging (FCM) or if you intend to send a message through a Firebase Trigger the use Cloud Functions for Firebase. – AL. May 18 '17 at 06:03
  • 1
    Security wise tho, if ever someone was able to get the APK for some reason and the Server Key was in there (probably along with the Sender ID) then that person would be able to send messages to all your app users. So it's up to you if you want to send downstream messages directly from the app. – AL. May 18 '17 at 06:05
  • Thanks - @AL. :) – Abbas Kararawala May 18 '17 at 06:22

0 Answers0