Get unique Id for the current user - android

How can I get a unique Id for the current user who is using my application?
I don't want to retrieve the device UDID (for my users privacy concerns).
I saw once that in the latest API versions (4.0+) there is such method to generate a unique
id for the current android user, but I cannot find it now.

This is the official statement from Google
http://android-developers.blogspot.be/2011/03/identifying-app-installations.html
You should really read it.

I guess you are using some kind of backend, so maybe you can create an endpoint that return a unique token that you save in the shared preferences.

Related

Get unique ANDROID_ID on flutter is it possible?

I would like to get the unique device id on android with Flutter.
I've tried this plugin device_info but it doesn't return the ANDROID_ID that I get in java Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
how can I get the same id?
In this case it might be simpler using platform specific code and a Flutter platform channel setup.
You can then use your Java code as included in your question and pass the Android ID to your Flutter application via a platform channel when needed.
See Writing custom platform-specific code with platform channels .
You can do what you did, but it is not reliable or guaranteed. Please read up on:
https://developer.android.com/training/articles/user-data-ids
for best handling of unique IDs.
Of course you can get the phone network ID, but what if that device doesn't have a carrier.
You could get the device ID, but what if it returns null for that manufacturer.
You could get the Advertiser ID, and this is often recommended, but it CAN CHANGE, it is unlikely to change, but if they do a factory reset or anything like that, it would.
So your best bet might be to generate your own unique IDs and store them locally with the application either in a DB implementation or SharedPreferences.
So to answer your question, if you have existing audience that you used the wrong, bad practice way of using unique IDs, then you should make an ID factory with if/else logic to fix it.
If (first time accessing an ID for this installed application)
//createOne and store it
else if(ID already exists and matches ANDROID_SECURE_ID method)
//get it the old way,
//create new one, and update your access to APIs or DB with new associated ID so that you never hit this code path again
else
//use correct ID implementation that you created
You could also just as easily do a one time check in your Application onCreate to fix anyone with wrong ID and then set a flag that you fixed it so you don't fix it again in sharedpref.

How can I get same id in friends & tagable friends Facebook api?

We are working on an Application in which we are getting friends data using me/friends & me/taggable_friends apis.
For both of the apis we are getting different id of user. In me/taggable_friends api, It is returning different id of particular user.
Please advice how to manage this situation.
Thanks.
What you get from the taggable_friends endpoint is not an id, but a token only – and it is short-lived.
The only purpose for which you are supposed to use it, is tagging friends in OG stories. For that, you are supposed to provide the user with a UI where they can select the friends they want to tag.
You are not allowed to try and use the data you get from that endpoint for any other purpose.

How to get unique id for clients without registration? (Jodel app for e.g)

Imagine an application that consists of loads of clients and one server. The clients should be able to use the application without the need to register a username for e.g. (Therefore getting the feeling of anonymously using the app)
What unique data in a smartphone could be use to identify "anonymous" users and seperate them uniquely, so that each user would have its own personal data.
Could one use the IMEI id?
Is this possible?
At I/O 15 Google announced the 'instance ID' which uniquely identifies an app installation, and can be used for a veriety of other purposes as well.
I give more detail in an answer to an existing, similar question here:
https://stackoverflow.com/a/30948111/150016
Yes You can use the IMEI, but then you need a permission...or you could give every User a Unique ID on the server side
I think a long type variable is enough so the first one that connects you give him the ID 1 the app gets the ID and so on and so forth
You can use a built in feature here:
import android.provider.Settings.Secure;
private String uniqueIdentifier = Secure.getString(getContext().getContentResolver(),
Secure.ANDROID_ID);
where Secure.ANDROID_ID is presented as "A 64-bit number (as a hex string) that is randomly generated when the user first sets up the device and should remain constant for the lifetime of the user's device."
This is exactly the use case for the new Instance ID: getting a unique ID that you can use to identify even a not logged in user to your server.
This works on both phones and tablets (something IMEI does not) and avoid issues with ANDROID_ID (such as a few manufacturers always using the same ANDROID_ID on all devices).
You don't want to use the IMEI, as it will only apply to devices that have cell phones in them. There are plenty of wifi only devices out there in the wild.
Also, to get the IMEI, you need to ask for extra permission in your manifest.
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
You'd be better off either generating your own random GUID and storing it in your app's SQLite database, or use the Android ID field.
Android ID will give you extra benefits like providing a different identifier for different user profiles within a device.
Another answer here mentioned using Instance ID, but the big caveat there is it requires Google Play Services, so your app wouldn't work on AOSP / forked devices (i.e. Amazon's tablets). I'd have just inserted this as a comment to that answer, but my rep won't let me comment yet.

Android/Ios in-app billing. unique ID

i made a cordova 3.3 app for Android and Ios, and i want to sell a premium version that permit to save settings and data for every on my distant database for an easy recovery if they change their phones.
Initially i thought to get their google/apple account email but it seems to not be possible.
So i thought that i just need an unique ID from the item purchased that i should use as an userID on my distant database.
I use this plugin for android:
https://github.com/poiuytrez/AndroidInAppBilling/tree/master/v3
So, the inappbilling.buy(success, fail, productId) and inappbilling.getPurchases(success, fail) both return a json object like this ex:
{"orderId":"12999763169054705758.1385463868367493", "packageName":"com.example.myPackage", "productId":"example_subscription", "purchaseTime":1397590291362, "purchaseState":0, "purchaseToken":"ndglbpnjmbfccnaocnppjjfa.AO-J1Ozv857LtAk32HbtVNaK5BVnDm9sMyHFJkl-R_hJ7dCSVTazsnPGgnwNOajDm-Q3DvKEXLRWQXvucyW2rrEvAGr3wiG3KnMayn5yprqYCkMNhFl4KgZWt-4-b4Gr29_Lq8kcfKCkI57t5rUmFzTdj5fAdvX5KQ"}
Can someone confirm me than orderId is strictly unique on android? (with source link or proof pls) ?
I will have the same issue on Ios, so do you know a if a value will can make the deal on Ios? I can't see the return value of the restore function in this plugin:
https://github.com/j3k0/PhoneGap-InAppPurchase-iOS
If it's ok for both, i could regist an ID like this :
"android_" + orderId
Or
"ios_" + ???
as user ID
Ok i found the answer on the ref... sorry.
http://developer.android.com/google/play/billing/billing_reference.html
"orderId : A unique order identifier for the transaction. This corresponds to the Google Wallet Order ID."
So i think it's ok for android. i will look on the Ios ref.
If you think about better idea for my case, feel free to add another answer.

Unique ID for each user in Android

I want to allocate unique ID to each user as soon as he installs the application so that whenever the app contacts the server I know who is contacting.
For this purpose, I thought that on first time installation, the app contacts the server and gets unique ID. But I don't know where to store it permanently so that next time when app is started, it knows what its ID is rather than contacting server.
Sorry if that is some obvious question as I am newbie.
This question has been asked many times on Stack Overflow.
In short: Android has always supported a unique ID. However, prior to Android 2.2, the ID was not always identical on certain kinds of phones. Since 2.2 is pretty ubiquitous by now, I would use that ID.
The Android Developer Blog has a good article about this.
And as Joachim said - you may want to consider a different approach altogether. Android's unique ID is good and persistent across factory resets, but not across a device upgrade. Also keep in mind that many people have several devices (like a phone and a tablet). You may want to use the Google account instead, the AccountManager can help you there.
Use SharedPreferences to store the unique id.
Here is an example:
Android SharedPreferences
For more complex data, you can use SQlite.
For unique id, you can use IMEI of device on which application is going to install. Refer this link for how to get IMEI number. Then stored that IMEI number in shared preference. Refer Guillermo lobar's link for that. You need to check for that unique id in preference when you application starts. At very first time, save that in preference. So when next time it checks for that id, app find it in preference and hence no need to connecting server. :)
You could get the IMEI of the device. As of API 26, getDeviceId() is deprecated. If you need to get the IMEI of the device, use the following:
String deviceId = "";
if (Build.VERSION.SDK_INT >= 26) {
deviceId = getSystemService(TelephonyManager.class).getImei();
}else{
deviceId = getSystemService(TelephonyManager.class).getDeviceId();
}

Categories

Resources