Google Cloud Message Sandbox

2019-07-06 01:02发布

问题:

I followed the tutorial to implement push notifications on my Android App (Google Cloud Message). I managed to successfully implement these messages but now I'm concerned about dev/production environment. There is only one API key (in opposite of Apple who has sandbox key and production key). How you guys deal with this? I don't want my gcm tests firing real messages to users.

回答1:

You can use the dry_run field :

dry_run

If included, allows developers to test their request without actually sending a message. Optional. The default value is false, and must be a JSON boolean.

If it doesn't work you can try the restricted_package_name field with an invalid package name. I haven't tried it, but it might behave the way you want.

restricted_package_name

A string containing the package name of your application. When set, messages will only be sent to registration IDs that match the package name. Optional.

The quotes were taken from the GCM Architectural Overview.



回答2:

You can do this by creating a new API Project.

  • From the Google Developer Console create a new sandbox API project
  • Create a new public API access key for server applications
  • Server sandbox environments push using the public API access key for server applications from the sandbox API project
  • Android debug builds use the project ID from the sandbox API project