I am building a app with in-app subscriptions. I have implemented Real Time developer notifications as recommended by Google by properly configuring as mentioned over there. Whenever I purchase or cancel a subscription, SubscriptionNotification is published to the Pub/Sub topic as expected. But I am not able to get that message in the app. My requirement is that whenever message is published to the topic same message must be received inside app without any explicit request. And I have a pull subscription of Google's Pub/Sub api. So does pull suit here or should I go for push? So any kind of help would be highly appreciated.
You would not want to receive the Cloud Pub/Sub message in the application itself. In order to accomplish this, you would need to have a subscription per application instance and Cloud Pub/Sub is not designed to scale that way: the limit is 10,000 subscriptions per topic. Additionally, each instance of the application would receive all notifications for all users, which is likely not what you want.
The purpose of the real time developer notifications is for your service to receive notifications of changes to users' entitlements. Then, when users make requests to your service from the application, it can respond appropriately based on the subscription features that should be enabled. If you want an application instance to be notified when entitlements change, you'd have to implement that separately in the service in response to the Cloud Pub/Sub notifications. You could use something like Firebase Cloud Messaging to send the appropriate messages to individual application instances. However, you would still need to have a service that acts as a subscriber to Cloud Pub/Sub and gets the messages from the topic for developer notifications and then passes these along to Firebase Cloud Messaging.
Related
Hello Everyone,
I have create gmail app and complete all types of functionality but one functionality not implemented this one is mail receive in our gmail app.
Me search any types solution for receive mail and i have found one solution is google cloud Pub/Sub but this pub/sub how to implemented in our app is not idea show please tell me any one how to used pub/sub in android.
Cloud Pub/Sub is not the right choice for receiving messages on Android. The service is designed for inter-service communication. Using it on Android would present two problems:
The limit on the number of topics and subscriptions per project. Only 10,000 topics and subscriptions are allowed and only 10,000 subscriptions per topic. If you plan to scale out to many devices, you will run up against these limits quickly.
Security/authentication issues. You would need to ship the credentials within the Android application and so you will either have to generate service accounts for every individual device or use the same one across all devices. What do you do if those credentials are compromised? In the former case, you have to keep track of all of them and revoke the right one. In the latter case, revoking the privileges means all of your devices stop working.
You need something like Firebase Cloud Messaging to send data to Android devices. You may use Cloud Pub/Sub as a means to generate notifications out of GMail, but the subscriber would be another server-side application or perhaps a Cloud Function that passes the notification on via Firebase Cloud Messaging.
I'm trying to implement this example: create rtdn of developer notifications, however, I use firebase, so I'll be using Cloud Functions to give onPublish in my topic subscriptions.
My question is as follows, the recommended for pub / sub notifications for Real Time Notifications is to use push notifications, since the pull is based on the assumption of the back end to exit, which does not happen in Cloud Functions, however, when clicking push on the Console, it asks for an "endpoint url", where do I get this endpoint url from or how would I generate it? In fact, even though I researched, I did not understand the reason for this.
Screenshoot example:
You do not need to make a push subscription yourself through the Pub/Sub console. If you go to ‘Cloud Functions’, create one and set the trigger to be ‘Cloud Pub/Sub’ and then choose a topic, it will create a push subscription on your behalf. After that, whenever a message is published on that topic, your cloud function will be triggered.
The URL endpoint is used when you own an HTTP address that you want Pub/Sub to push messages to.
Consider a whatsapp group. When any user texts in group, all the participants receive a notification.
Consider Youtube, whenever a content creator uploads a video, I get notifications.
These are all automated.
How to do this? I use Firebase as backend in my android app.
You need back-end services that you communicate with through an Api from your app. Think of this as a communication layer between Firebase and your app.
Generally this can be considered as a REST API. Here is more reading:
https://restfulapi.net/rest-api-design-tutorial-with-example/
I want a push notification, when there is data in server change,delete or added etc The notification is associated with the user. And the Google Cloud Messaging notification is associated for the application running in device. Also there is a lot of over head for developers, when developer are creating the system using google cloud message. Therefore I decide not to use Google Cloud Message.
I know is using XMPP or WebSocket can fulfill my requirement but it is battery inefficient. My question is there a better approach to fulfill my requirement.
You can send the GCM registration Id in the login request to the server and remove it once the user logs out. This way you can send a GCM message to a particular user.
If you want to use a GCM alternative you can try Pushy.me, its also a very good service that uses MQTT protocol and have less headaches as compared to GCM.
Depending on your specific needs, using an alarm and intent service to poll your server every so often - say 24 hours - can work. Then create a local notification if needed. This way no third parties are needed, but you won't have real time notifications.
I have an android application where a user can insert data into web sql server. I want all the users to receive push notifications when someone inserts a row into database. How to implement.
You can use Google Cloud Messaging (GCM)
Google Cloud Messaging (GCM) for Android is a service that allows you
to send data from your server to your users' Android-powered device,
and also to receive messages from devices on the same connection. The
GCM service handles all aspects of queueing of messages and delivery
to the target Android application running on the target device, and it
is completely free.
For more info on how to use it, refer to developer.android.com
Try this tutorial (or the official documentation) for specifics, but in overview you maintain a list of registration tokens for your users, and send the list of tokens for users you want to get a notification to Google and the send it out. Google will tell you afterward if any of those tokens are now invalid--those should be removed from your system at that point.
http://www.tutorialspoint.com/android/android_push_notification.htm