Our intention is to filter the content based on location without requesting Location permission from the Android device,
In-order to meet this requirement, we have tried the following options and still its not reliable
Telephony Manager
it wont work without a Sim card, again say if the user from USA travels india now the below snippets returns US not India
var telephonyManager = context?.getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager
val countryCodeValue = telephonyManager.networkCountryIso
Locale
Locale returns US or UK by default even if they are in India, usually user's Locale would be in English by default
Locale.getDefault().getCountry()
GPS
We doesn't want the Location permission to be requested
Retrieving the Country details form the logged-in Google account
Reply from Google - They dont have any dedicated API to retrieve countryCode of an user
Note:
iOS has a dedicated API which tell the CountryCode of the user, but Android doesn't
IP address
We tried to get the IP of the Android device (from several IP fusion websites), there are following two cases
User connected to WiFi - we are able to get the countryCode (WIFI IP
: 64.134.234.17)
User connected to Mobile Data - we are getting the wrong countryCode
even we are in USA, it says that IP is from JAPAN (MOBILE NETWORK
IP: 210.253.218.106)
Note:
Even Netflix determine the country during the launch, without requesting the Location permission
I think you have only two possibilities...or ask permission...or without asking permission you have to ask the user to insert an address (also only the city) and retrive the country code by mean of Google Geocoding Service
I agreed the above comments. You can't get the precise country by anyways other than there GPS location.
You can read this one hope you will get some idea about
Regarding your query how netflix is using it
https://help.netflix.com/en/node/26100
Brief
1.Disable any proxies (Means they are checking with there ip's)
2.Check your current IP address by visiting whatismyip.com (Same)
Regards
have you try using an API
ex:
http://ip-api.com/json
that will return country code and many other information all by analyze request IP "(no need obtained IP from device)" .
but obvious we need assume user not use any proxy or vpn
(There are plenty of other apis or you can implement and host one by yourself)
No way of getting it without Location permission, your better approximation is the localization by ip but as you saw there is no guarantee of precise localization
Related
The new CCPA guidelines require to have a specific app behaviour for the 'californian users'. By the way, I wonder if the CCPA applies to all californian citiziens (even if they are not physically present in California when the launch the app) or to all the persons present in California (event if they are not californian citizens).
So, I wonder how I can do technically in order to know if a user is concerned by the CCPA law, in order to know if I must implement a CCPA-specific behaviour for him/her.
My question is about both iOS and Android.
Thanks !
from my understanding, CCPA applies to californian residents only (not travelers)... That being said and as we could expect some kind of generalization of the CCPA later for all US citizens, one can use a conjunction of :
MCC code to identify the country (312 to 316)
Any kind of IP to region code service to check for "user is present in California"
MCC CODE
With such a code, we know if the user is has a SIM card associated with an US subscription. On Android we can use getResources().getConfiguration().mcc or put a flag in lacalized config file under values-mccXXX resource directory :
<resources>
<bool name="is_us_subscriber">true</string>
</resources>
With a default to false. Works offline but requires a SIM based device (which excludes some tablets...), for non-SIM based devices there's no seamless way to check for country of residence... Best effort will be to use IP-to-ADDRESS unless you have additionnal information coming from facebook login or whatever...
IP TO ADDRESS
Using one of (or combination of) :
https://developers.google.com/maps/documentation/geolocation/intro
your own server implementation
https://developer.android.com/reference/android/location/Geocoder
other webservice
You can get US State (eg: California) from user IP address. On Android, use webservice to get user latitude and longitude and then call Geocoder to check for Address#getCountry() and Address#getAdminArea() which returns :
the administrative area name of the address, for example, "CA", or
null if it is unknown.
But it will only allow you to know that user is in California... And not user is a Californian resident.
MY OPINION
Use of external webservices is not reliable (no connection, VPN, proxy, ...)
Use of external webservice could be expensive
We lack information regarding user residence with location based services
I would recommend use MCC only since there's a high probability to see some kind of CCPA generalization in the US sooner or later...
I want to get a user's country code without using any permissions that need to be actively requested under android M. For example, if the user were located in China I would want to get back CH. I don't want to use "dangerous" permissions for this - neither read_phone_state to go through the TelephonyManager, nor location in order to try to guess based on his GPS. Is there a way to do this and if so, how?
I've tried using the following code but it's prone to failure if the user sets his language settings separate from his country (e.g. user in India sets his phone to English_US):
Resources r = paramContext.getResources();
Configuration config = r.getConfiguration();
Locale currentLocale = config.locale;
Log.d("TAG", "Country: " + currentLocale.getCountry());
All methods that allow to determine the user's current location with a certain confidence level are marked as dangerous.
That being said, there are several methods that are not as reliable, but might be acceptable for you:
locale:
precondition: locale can be mapped to a single country
source of errors: user is abroad
source of errors: user is foreigner
source of errors: bad l10n quality for the country
TelephonyManager.getSimCountryIso()
precondition: needs an active SIM card
source of errors: user is abroad
source of errors: user bought SIM card from abroad
Looking up the location via GeoIP database
precondition: needs an active internet connection
source of errors: database has wrong mapping for the IP address
source of errors: active VPN network
asking the user for his country
precondition: application workflow allows user input
source of errors: input mistakes
source of errors: information is stale because user did not update the information
source of errors: user maliciously enters wrong information
The only way you can determine the user's physical location programmatically requires a dangerous permission.
If you do not want to ask the user for the permission, then ask the user for the user's location.
I've tried using the following code
That code has nothing to do with the user's physical location.
There are several methods to get location name using lon&lat like GeoCoder or GoogleMap API.
But these methods need to internet for their job!.
is there any way to get location name without internet access?
note:in some device location name discovered as CellInfo
I might be wrong but I seriously doubt that it's possible to store a mapping of Lat/Long with the name of the place in an Android device. You need a server to store this amount of data.
But you could create your own database with some location (those you use frequently).
Or just use internet when it's possible (on WIFI only).
Following scenario:
I want to create an wifi hotspot on a public place (e.g. train station). Therefore i want to write an mobile application (iOS and/or Android) which works as a portal page. As I would be providing internet access via my wifi hotspot I need to make sure that people who want to log in verify their identity properly (responsibility). First I thought i could do something like a facebook login but I guess that would not be enough as people can create fake accounts.
Then I got the idea that I could maybe access their telephone number via their smartphones.
I googled alot and came to the conclusion that it is pretty tough on both platforms.
The iOS method seems to be deprecated and apps wont make it to the app store with that version. Android can read the phone number from the sim card, but not all providers store the number on the sim card.
Question
Is there any possibility to get the phone number? Or is there any other way to uniquely identify a person in a wifi network?
Of course I dont want to do any of that without asking for users permission etc...
Greetings and thanks in advance
Peter
Choosing the MAC address is a good choice, it is not the safest, but it is the more easy to do.
The IMEI is not always provided, and the SERIAL is not uniq.
But actually, I don't know how to do this with iOS.
What is about the MAC address of the phone? This should be unique enough and you can get is easily from android and from iOS.
Android: http://developer.android.com/reference/android/net/wifi/WifiInfo.html#getMacAddress%28%29
iOS: How can I programmatically get the MAC address of an iphone
Using IMEI number
Android Does provide functions/method to access device IMEI number
First Set <uses-permission android:name="android.permission.READ_PHONE_STATE" />
in android manifest
TelephonyManager tm = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
// get IMEI
String imei = tm.getDeviceId();
Hope it helps
For NON CDMA or GSM devices like Tablet
Use
import android.provider.Settings.Secure;
private String android_id = Secure.getString(getContext().getContentResolver(),
Secure.ANDROID_ID);
This would generate a unique code for the device..how ever it would change on when user reset the device ie factory reset it .. and it works for device having os > 2.2(froyo)
This really depends on who you are trying to identify. That may seem like an odd response, but usually, we are trying to identify two, not one, sets of credential elements.
First, we want ot identify the device itself -- is this the deivce we expect to see and can we trust that this device has not been tampered with. Second, we usually want to know if the user of this device at the moment is one we expect to be using this, now validated, device. (If I take your phone, without step #2, I just became you.)
This is why we have things like 802.1x. It lets me validate the user of a network, not just the device. For your case, consider something like:
For device validation, the combination of hte MAC address and the IMEI. TUrn those into a unique hash with some data from the user. For example.
ID = SHA1(IMEI+MAC(Wifi)+user password)
Now that we're pretty sure the device and user are correct, if you need to, you can go one step further and use that hash a key to encrypt a user validation step in your app. Even if the user is correct, if they're on the wrong device, their key won't decrypt.
I have some app that sends some information to the internet from time to time let say ones at day. And I can easily send some coordinates (using the gps position) but I do not want that. The android phone is always connected to the internet via wifi or mobile network. But not always enabled the gps. So is it possible to get the location with wifi or mobile network ? I google this thing and I end up with finding location by gps, I do not want to do that.
Can you give me some ideas what can I do this. I have seen web sites that when I open them they know where am I, so I guess it is possible to find the nearest name of the city just by making a internet request and reading the response or maybe use some service . . .
Thanks
http://developer.android.com/reference/android/location/package-summary.html
http://developer.android.com/reference/android/location/Address.html#getAddressLine(int)
getLocality looks like it may do what you want?
For websites that know where you are, they either use your source IP and look that up (which isn't very reliable for a lot of things), or they use the javascript geolocation APIs as described here:
http://merged.ca/iphone/html5-geolocation
In fact, here's a stack overflow answer on using google API to get to the city name:
Get city name using geolocation