2

I'm developing some apps using GCM(google cloud messaging), and I want to send notifications about some informations of my company(new apps, promotions,...) to users of all current apps. If a device installs many apps, it will receive and notify the same notification many time, so users may feel uncomfortable. I want each notification to only notify one time in a device, is there any solution for this problem?

I see someone misunderstand my question. My problem is: a device installed many apps of my company, so if I send the same notification to each separate app(ex: notify that My company has published a new app) this device will notify many time with the same content.

My solution: use a shared memory(file) for all apps, each notification has an unique id, when a notification comes each app will check this file(create a new file if not exist), if this file content doesn't contain the unique id of this notification and the device allows this app to show notification, it will write to file this id and show this notification, else(this id exists or the device doesn't allow this app show notification) this app will ignore this notification. By this solution, I need to check if user allow an app show notification or not, can I check this?

Is there Any other solutions or suggestions to improve my solution?

Ikarus
  • 1,169
  • 4
  • 14
  • 28

3 Answers3

2

(check history of this answer to see previous edits)

Server side, you must now which apps your user have installed.

  1. You need a serial number or another way to uniquely identify your user
  2. You can inspect installed packages
  3. You can listen for install/uninstall events or periodically update your information

Then, you choose which app will fire the notification (using the SENDER_ID as suggested by @mina fawzy).

EDIT

To summarise, your approach is client side:

  • app fires a notification with NOTIF_ID. Is NOTIF_ID in SHARED_FILE?
    • Y: notification already displayed
    • N: are notifications allowed?
      • Y: write NOTIF_ID to SHARED_FILE and show notification
      • N: ignore this notification

You now need to check if notifications are disabled for your app:

Community
  • 1
  • 1
vault
  • 3,930
  • 1
  • 35
  • 46
  • Thanks, but I think you misunderstand my problem, it's not "an user uses many devices", it's "one device installed many apps of the same developer", plesae see my edited question – Ikarus Oct 21 '14 at 16:43
  • Ok @Ikarus, I edited! – vault Oct 21 '14 at 23:04
  • I thought about these features, it's quite complicated, and an issue is when an user turn off notification of the app which is chose to display notification, so can I listen for turn on/off notification events(like install/uninstall events) to switch the display notification mission to another app which enable show notification? I also update another solution above, I think it's a better approach – Ikarus Oct 22 '14 at 04:14
  • To clarify: [is this the feature you are afraid of that enables users to disable notifications?](http://www.guidingtech.com/13572/disable-useless-app-notifications-android-jelly-bean) I'm using cyanogenmod since ages and thought it was one of its features :P – vault Oct 22 '14 at 09:43
  • Nice, with android.service.notification package, even I may not need to use shared file because it can help me check notification id in notification bar (need consider about race condition), unfortunately [android.service.notification](https://developer.android.com/reference/android/service/notification/package-summary.html) is only on the Android version >= 4.3. Because this is not an important feature, I'm gonna postpone it – Ikarus Oct 23 '14 at 01:51
0

Each app register in GCM server have unique SENDER ID , this number put in both mobile and your server that will send notifications , so when you send notification you send to specific mobile application not to all apps , so its server side problem not android one

updated answer

you need unique identifier to each phone like ANDROID_ID in Settings.Secure

private String android_id = Secure.getString(getContext().getContentResolver(),
                                                        Secure.ANDROID_ID); 

don't forget to import it

import android.provider.Settings.Secure;
Mina Fawzy
  • 20,852
  • 17
  • 133
  • 156
0

In client side, you could export your GCM receiver, let all of apps from your company use. all apps use the same GCM receiver, then they could judge if they need to prompt the notification or not.

And then in server side, you should collect which app had been installed in user's phone via user id (cause GCM register id maybe not the same); when you want to send a notification to user, you should check each user id rather than check the register id.

then you could solve this issue.

Chauyan
  • 157
  • 8