Why is "using getString() to get device identifiers" not recommended? - java

I'm trying to get my device ID to Logcat but Android Studio is giving me this warning.
using getstring to get device identifiers is not recommended
String deviceID = Settings.Secure.getString(getApplicationContext().getContentResolver(),
Settings.Secure.ANDROID_ID);
Why is it not recommended?

The full warning says:
Using these device identifiers is not recommended other
than for high value fraud prevention and advanced telephony use-cases.
For advertising use-cases, use AdvertisingIdClient$Info#getId and for
analytics, use InstanceId#getId.
More info:
https://developer.android.com/training/articles/user-data-ids.html
I think Android does not recommend using this value, since it's a permanent unique id, which can be used to track your user, and he or she can't change this id or prevent you to read it. The other options given in the warning respects your user's wishes. That's why Android recommend you to use that.
It really depends on what you are going to do with that id. Privacy is a sensitive thing these days.
Also check this:
...you must abide by a user’s ‘Opt out of interest-based advertising’
or 'Opt out of Ads Personalization' setting. If a user has enabled
this setting, you may not use the advertising identifier for creating
user profiles for advertising purposes or for targeting users with
personalized advertising. Allowed activities include contextual
advertising, frequency capping, conversion tracking, reporting and
security and fraud detection.
Source: https://developer.android.com/training/articles/user-data-ids.html

Related

how get a unique Android device ID?

According to the policy, we must use this method to register the user
Therefore, using email or number to register a user is not a good way for us
According to my studies, there are several ways to get a unique ID
But each has its own problems
I need a method that does not require special access from the user
Using Android ID is a good method. The problem is that it can be changed on rooted phones
And this is very bad in terms of security, of course, in Android lower than 8
Is there a specific trick or method to solve this problem?
I also know an application that does not use Android ID or mac WIFI and Pseudo-Unique ID, but does get the information according to the user's device. Is there a way to know what method it uses?
it's simple all you have to do is use the below code. this method will return android id now all you have to do is add checks at your backend.
val id = Settings.Secure.getString(
getContext()?.contentResolver,
Settings.Secure.ANDROID_ID
)

Android, How to properly scan and filter ble UUID's

I am working with BluetoothLe on Android (min API : 21+). Currently the procedure of filtering service uuid's works, but not quite as expected. Below is a code segment used for setting up the basic scanner parameters, this is what currently works. Based on areas of other work with Ble, (iOS, Embedded Hardware) it becomes apparent that there are abilities to filter Ble devices based on their 16-bit UUID assignments only. Which brings me to Android... I realized android has had a rather rough start to Ble and its rather segmented ecosystem of devices, but I fail to see how/why android cant follow similar paths with the UUID's like other platforms. As all the UUID's coming from the Bluetooth SIG are 16-bit identifiers only with a mere definition of a UUID_BASE (00000000-0000-1000-8000-00805F9B34FB).
...
// devices UUID service
ParcelUuid parcelUuid = new ParcelUuid(UUID.fromString("1F0E0D0C-0B0A-0909-0807-060504030201"));
// devices UUID service mask
ParcelUuid parcelUuidMask = new ParcelUuid(UUID.fromString("00000D0C-0000-0000-0000-000000000000"));
// Filters and Settings
scanFilter = new ScanFilter.Builder().setServiceUuid(parcelUuid, parcelUuidMask).build();
scanFilterList.add(scanFilter);
scanSettings = new ScanSettings.Builder().setScanMode(ScanSettings.SCAN_MODE_LOW_POWER).build();
// Scanning Started
mBluetoothLeScanner.startScan(scanFilterList, scanSettings, scanCallback);
...
With all that stated above, I have two Embedded Hardware devices broadcasting Two of their own UUID Services that are very similar to one another but different non the less. Below are those UUID's, in all accounts only the MSB(Most Signifigant Byte) is the differentiator amongst them all. Also there Device Names are different.
Device One:
Service 1 - 1F0E0D0C-0B0A-0909-0807-060504030201
Service 2 - 2F0E0D0C-0B0A-0909-0807-060504030201
Device Two:
Service 1 - EF0E0D0C-0B0A-0909-0807-060504030201
Service 2 - FF0E0D0C-0B0A-0909-0807-060504030201
Common Identifier amongst the UUID's:
0x0D0C
From the code segment provided earlier, the ParcelUuid that is used in the setServiceUuid method appears to require an exact match for the scanner to even return a device, despite the matching mask needed. How then, do you make the request to the drivers/hardware to filter only by 16-bit Identifiers instead of the full 128-bit Identifiers?? Because the model I have presented above with the two different devices, each with their own Service UUID's different from the other, isn't capable of scanning and returning all the devices wanted or expected.
I feel like the problem I'm having is two-fold but needs to addressed, because I cant seem to find the answer anywhere. I have searched high and low for all forum post, stack questions/answer that touch on this topic but none of them appear to pop out as what I'm looking for. I'm not sure if my understanding of filtering on android is faulty, if android is missing features, or inability to find such features in the supplied classes of android. I have a few thoughts on how to accomplish this "feature" in software but it will be rather ugly, time consuming, and taxing on the battery. One such example is scanning openly and filtering it manually. But I think there is or should be a feature to support 128-bit AND 16-bit UUID filtering when scanning through devices.
Can anyone help shed light on this????
Also, apologies for the length of this posted question...
The mask i should be opposite - use 1's for bits to include and 0's for those that should be ignored.
filter: 1F0E0D0C-0B0A-0909-0807-060504030201
mask: 0000FFFF-0000-0000-0000-000000000000
Result is that any device which has '0D0C' is included. You'd probably want a "tighter" filter with more similarities in it than this.
I'm not sure exactly what you want to filter on, but if you simply want to apply the filter ????0D0C-????-????-????-????????????, you should have the parcelUuid set to 00000D0C-0000-0000-0000-000000000000 and the parcelUuidMask set to 0000FFFF-0000-0000-0000-000000000000.
You should filter the BLE based on MAC addresses , they filter like a charm and perhaps if you have found the solution for the UUID filtering please do share.

Android Id and its reliability

I want to generate Uuid for my app so I tried many methods for this.
1) Getting Serial number of device using android.os.Build.SERIAL(this returns "unknown" as result)
2) Dealing with device id (I don't know what it will return in case of tablet devices)
3) Getting Android id using android.provider.Settings.Secure.ANDROID_ID(seems some problem with android 2.2 version)
4) Generating Uuid using java.util.UUID
5) Generating pseudo Uuid using android.os.Build properties
All these methods shows some problems. So I am confused which to be choose? Can anybody suggest me best method?
Android Developer Blog says android id will be unique
Also I heard Android id of device can be changed on factory resetting or os updations .
So is there any chance of for duplication new android id generated during factory resetting or os updations ?
NB:Suppose A Condition
My question is what will happened same 2 device Model of same manufacture will under go restore or os updations.the Android id will change. I am asking about this new id. Will there any chance for android id be same in both device?
The ANDROID_ID is generated each time you initialize the device (after reset, etc.). It doesn't depend on model, serial no., etc. Even if you have two identical devices, their ANDROID_ID's after reset should be different. The ID is not particular special, except that it is global for the device. You can achieve the same thing with an UUID for your app.
Yes, there is a chance of duplicate ID's, but it's negligible.
There's 2^64 possible values for ANDROID_ID, and they are generated with some random function. But it is very very very unlikely that you will ever see a duplicate value - search for discussions about GUID uniqueness to get the point.
In short: you can assume that ANDROID_ID is unique.
Creating unique id's for android device has been discussed vivdly in this link In short use this.
import android.provider.Settings.Secure;
private String android_id = Secure.getString(getContext().getContentResolver(),
Secure.ANDROID_ID);

Since when is the phone charging/discharging

I wanted to learn more about the Android Services / Broadcasts, so I started a simple project, to create a battery monitoring app. It turned out pretty good, I'm using it for a few days now, but I want to add a new function: to show since when is the phone charging/discharging.
First I thought that I would create two static fields in my BoradcastReciever extension class, where I get and publish the data about the battery, one for the actual state (charging/discharging), and one for the time, when the change in state happened. This way, I could just subtract from the current time the last change, and know exactly since when is the phone charging/discharging.
But there is a problem with this solution: It won't show the correct data at first, when a user starts the app. I wouldn't make a big deal of it, but I saw that Android tracks this data somewhere, because inside my phone settings I found this information, so why take the hard way.
So my question is: is there an easy way to get from the Android system the date/time (no matter what format) of the last charging state change?
I looked at the BatteryManager reference but there are no constants named after what I seek, and which I could use, to get the information from the Intent of my receiver.
The Android OS tracks the connect/disconnect of a power source, but does not make this data accessible to apps. You have to record this all yourself, using intent filters.
The two intent filters to use are android.intent.action.ACTION_POWER_CONNECTED and android.intent.action.ACTION_POWER_DISCONNECTED; with these, you can monitor when the power source is connected and disconnected.
You can find information about this process explained incredibly clearly here. Another blog describing the process can be found here.

Identifying user by browser agent details?

I understand that this kind of identification cannot be 100% accurate, but example usage would be internet poll, to detect users that have already voted. Is user detection possible with browser sent details? And what kind of information I can get from browser with every request? If I add IP address or location for example town to this, then identification would be more accurate. Are there any possible downsides I should know about?
You may want to check out the research the EFF has conducted, to identify visitors using default browser-transported information - but no cookies.
Here's the link for Panopticlick.
You should not rely on such information.
As I'm sure you are aware all of this information can be easily forged. As you can specify any request header at will (the request header contains IP, location, browser etc.).
You can use it as a poll, but you should keep in mind that the poll will never be 100% accurate.
If you want to know where the user is from make him authenticate in the site with a valid e-mail and set a cookie on his browser.
Another way to check a user's identity/location is using a paid identity validation service like URU for instance. Even this however is never 100% accurate.
ip + location is not a good thing. Much of internet users are behind firewalls/NAT's/proxy's.
Your best best is long term persistent cookie.

Categories

Resources