How to detect if user cleared my app data - java

When user clear app data it automatically logout but he still get firebase cloud messaging i want to stop sending notifications after user clear app data .

Firebase Cloud Messaging has no concept of users and/or their authentication state, so if your app behavior depends on those it is because you have made a mapping.
For example, it is common to associate the FCM device tokens with the UID of Firebase Authentication, and then look up the FCM device tokens when you want to send a message to that user. If that is indeed what your application does, you'll need to clear that association when the user signs out to stop sending of messages through FCM.
For example, you could check if a specific, known value still exists in the app data every time that your app becomes active, and clear the FCM mapping if that is not the case. Also see:
How to check if clear cache was done by user in android?
Android: How to get notified if the user clears application data from Settings -> Applications Manager
How do we know when our application data get cleared in android?

Related

how to make real time notification in android using retrofit 2

I want to make real-time notification in my android app, but I don't know how to make it real-time and connected to the database
how to make my app can get/access data change from the database every time the database changing even when we didn't open the app
let's say every time admin sending notification, it will send data to database and it has column "read" and it will set to 0 and then user's app will immediately receive notification where the column "read" is 0, and when user opens the notification it will open an activity and change column "read" from database to 1.
You can use either firebase cloud messaging or user background notification service with web socket connection
There are many ways to achieve this type of real-time communication like,
Socket.
MQTT Protocol.
WebRTC.
Firebase Live Database.
Also, you can achieve this feature by sending notification from your admin panel to the user's mobile devices.
A common way is to implement Firebase(FCM) in your application and on your server. You can see how to implement FCM using this Offical documentation help Link https://firebase.google.com/docs/cloud-messaging/

Storing a JWT on device to keep user logged in

I'm developing an android banking app and want users to stay logged in even after app is shut down. My idea to make this as secure as possible was to store a unique device id in the JWT and then extract the id from the token and compare it to the device id fetched from device at startup of app.
I would store the token in SharedPreferences, however, I just read that these device id's are not always unique due to people rooting they're phones. What would be the best solution? How can I be sure that the token I'm verifying at startup, is given to that user/device? I don't necessarily need to use device id's so any other secure option is welcome.
I don't think it's a good idea to have a persistable login session inside something as sensitive as banking app, but if you insist:
Use SafetyNet Attestation API for checking if the device you're running your app on is rooted and if it is, prevent the user from interacting. Once you did that just use regular SharedPreferences with Mode.PRIVATE and no one should be able to read this data outside of your app.

Firebase: Send push notification to user on all their devices

I am building an app similar to Instagram. User uploads a post and other others can like it. When people like the post, I want the post author to get a push notification using FCM (Firebase Cloud Messaging).
My problem is that the refreshToken (that is generated using FirebaseInstanceId.getInstance().getToken();) is specific to the device. So if the same user logs into the app from a different device, I want to make sure I send a push notification to all the devices. So here is my proposed solution, I want to know if it's the right way to do it:
Every time user logs into a device, I store the refreshToken into the database and when I want to generate a push notification, I can iterate over all those refreshTokens and send a push notification to all those devices.
Is there a better way to accomplish this?
Note: I am aware of Device Group Messaging and I can't use that because I don't have an app server. And I don't want to do it on the client side because that requires the client to have a Google account.
Yes, the implementation is okay.
Every time user logs into a device, I store the refreshToken into the
database.
This is actually not necessary to send the device push registration id (refreshToken in your case) each time user logs into your application from a device. You need to send the push registration id (i.e. refreshToken) from your device only when the device is not known to the server yet (i.e. new device).
Is there a better way to accomplish this?
I think no. This is the perfect way that you have implemented. However, we might always think of several optimization points like, tracking which devices are logged off, so that you do not need to send the push notification to that device any more. So in case of logging off from a device, send another invalidate refreshToken request to the server from that device, so that it does not get any further push notification. This is an improvement over the current implementation.

Multiple GCM Registration IDs for the same user sending push notifications multiple times

In the backend I receive GCM Registration_id, user_id (unique), latitude, longitude, score etc from Android application and save in the Amazon DynamoDB table. When I want to send push notifications to all the mobiles, I fetch all the GCM registration IDs, put into a java.util.set to avoid duplicates and then send Push Notifications to all those android devices based on set of registration IDs.
But now the problem is, Since whenever user uninstall and install the android application again, new registration_id will be generated and I receive it & save in database. Hence, same user receive push notifications multiple number of times, and it's because of multiple GCM Registration_ids saved for same user.
How do I solve this problem in the backend? I want to send only one push notification for every user. I am using Java Spring framework? Any example code and code to query DynamoDB will be highly helpful. TIA
You need to keep one entry of GCM Registration_id against each user in the database, whenever a user loagin or Install an application at that time you should send GCM Registration_id to the server and replace the older one with new id... check the following link
http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/Expressions.Modifying.html#Expressions.Modifying.UpdateExpressions

Sending notification to everyone running an application, Android

Set up:
I have a system which has multiple users. Each user will download my app onto their Android phone and use it. What I want is when any user performs a specific action (I have two in my app), I want to pop up a notification in all the other user phones.
A simple break down is like this:
Start app --> Navigate to the part where action is performed --> Perform the action --> Store the action the a DB --> Notify ALL USERS --> Pop up the same notification on all phones.
How would I go about this problem? Can anyone suggest ideas or links, cause I don't even have a clue on how to approach this.
If you are looking to send notification to all users, even if all the users are not actively using the application, then Puch Notification is a good approach.
Push notifications let your application notify a user of new messages
or events even when the user is not actively using your application.
On Android devices, when a device receives a push notification, your
application's icon and a message appear in the status bar. When the
user taps the notification, they are sent to your application.
Notifications can be broadcast to all users, such as for a marketing
campaign, or sent to just a subset of users, to give personalized
information.
Have a look at Android Google Cloud Messaging
Also I have found XMPP a good solution as described by this post.
You will find some good solutions here and here
Well, you will need a database on a server, and then you will need the app to constantly (or at intervals) query the database in the background for changes, and notify the user when it finds one. A system similar to how many apps give notifications is what I am getting at.

Categories