0

Hi I have requirement where i need to check if user already logged in some other device.

Sceario 1: If user logged in, I am making service call to change from 0 to 1. If user log out, i am making service call to 0. This works perfectly.

But problem is if user uninstall app after sign in, without log out, how to manage this scenario? As it changed to 1 and in this case

Scenario 2: I got suggestion that, if user un-install the app without log out or you're not log-in in app till 1 day you should change user's status to logout.but in this case, if user log in one device and uninstall app immediately within few hours(say may be because of low ram), once again user install app means, in this case the above scenario fails too.

I used device id from gcm to use, but device id also not an uinque one, if uninstalled app in same device and logged in, device id too will vary. Please suggest me how to resolve this issue.

Thanks.

Shadow
  • 6,864
  • 6
  • 44
  • 93

3 Answers3

0

To check if user uninstalled the app and again installed and logged in, you can user unique id of android device which is :

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

for more details see here

Community
  • 1
  • 1
Rohit Rai
  • 286
  • 4
  • 13
0

scenario 1 is the simplest, but a bit edited :

instead of just make a "ping" to your service on login / logout (that may cause some problem if you miss logout for any reason, as uninstall app, network issue, etc), simpler is to have timed ping (let's say every 30 sec, your app send a ping)

on server side, at ping receipt, start a timer and keep some safety margin for latency. let's say, if no other ping came in 45 sec, you log out automatically

you can adjust duration or underlying mechanism but main idea is there

Jerome B.
  • 244
  • 2
  • 8
0

You can use unique device id that is associated with the device i.e. IMEI number.

TelephonyManager telephonyManager =
        (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
String deviceId = telephonyManager.getDeviceId();

This device id is not reset and remains the same for a device.

for more details see here

Community
  • 1
  • 1