"notification_key already exists"
Based on the docs, there is no way to get from GCM the
notification_key of an existing
notification_key_name. If you think about it, it makes sense that trying to create a new
notification_key for an existing
notification_key_name would give you an error, since if it wasn't the case, you might be accidentally overwriting the Registration IDs of an existing
notification_key if you happen to supply an existing
notification_key_name by mistake.
You are comparing this to registering a device to GCM multiple times, each time getting the same Registration ID, but it's not a similar situation. When you register a device to GCM, GCM has a way to identify the device and know that it is already registered and return the same Registration ID. With user notifications, it only has the
notification_key_name that you supplied, and there's nothing stopping you from using the same
notification_key_name for multiple users. That is, there is something stopping you - the error you got when trying to create a
notification_key with a previously used
An easy way to overcome your problem is to treat
notification_key_name as a unique identifier generated by your server. If you don't have a
notification_key for a certain user (either because it's a new user or because you failed to store the
notification_key you previously got from Google), you generate a new unique
notification_key_name and use it to create a new
notification_key. You don't have to care about the old
notification_key that you failed to store.
Finally you store both the
notification_key_name in a table that contains the user id.