here's my problem :
I have this code (from this tuto) :
public Location getLocation(Context act) {
try {
locationManager = (LocationManager) mContext
.getSystemService(LOCATION_SERVICE);
// getting GPS status
isGPSEnabled = locationManager
.isProviderEnabled(LocationManager.GPS_PROVIDER);
// getting network status
isNetworkEnabled = locationManager
.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
if (!isGPSEnabled && !isNetworkEnabled) {
// no network provider is enabled
} else {
this.canGetLocation = true;
if (ContextCompat.checkSelfPermission(act, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED) {
// First get location from Network Provider
if (isNetworkEnabled) {
locationManager.requestLocationUpdates(
LocationManager.NETWORK_PROVIDER,
MIN_TIME_BW_UPDATES,
MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
Log.d("Network", "Network");
if (locationManager != null) {
location = locationManager.getLastKnownLocation(LocationManager.NETWORK_PROVIDER);
if (location != null) {
latitude = location.getLatitude();
longitude = location.getLongitude();
}
}
}
// if GPS Enabled get lat/long using GPS Services
if (isGPSEnabled) {
if (location == null) {
locationManager.requestLocationUpdates(
LocationManager.GPS_PROVIDER,
MIN_TIME_BW_UPDATES,
MIN_DISTANCE_CHANGE_FOR_UPDATES, this);
Log.d("GPS Enabled", "GPS Enabled");
if (locationManager != null) {
location = locationManager
.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (location != null) {
latitude = location.getLatitude();
longitude = location.getLongitude();
}
}
}
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
return location;
}
It works just fine on AVD and phone but with android TV, it won't work.
My android TV is on "use Wifi to estimate location" ( and is "on" of course) so I thought that even if there is no GPS_PROVIDER it at least should go on NETWORK_PROVIDER but isNetworkEnabled = locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER); is always false.
I specify that I have wifi on my tv and when I entered google map in my browser it found me.
Can someone please help me understand why it doesn't work or propose an other solution to get my location (apart from google play service, my TV doesn't have it installed)...
EDIT
My manifest :
<!-- lire dans la carte sd -->
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<!-- écrire dans la carte sd -->
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<!--location -->
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<!-- accès à internet -->
<uses-permission android:name="android.permission.INTERNET" />
<!-- accès à l'état de la connection internet -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<!-- pour enlever le bouton recent app -->
<uses-permission android:name="android.permission.REORDER_TASKS" />
<!-- pour l'AccountManager -->
<uses-permission android:name="android.permission.AUTHENTICATE_ACCOUNTS"/>
<!-- pareil je crois -->
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<!-- Pour delete les accounts -->
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-feature
android:name="android.hardware.touchscreen"
android:required="false" />
<uses-feature
android:name="android.software.leanback"
android:required="true" />
<uses-feature
android:name="android.hardware.faketouch"
android:required="false" />
<uses-feature
android:name="android.hardware.telephony"
android:required="false" />
<uses-feature
android:name="android.hardware.camera"
android:required="false" />
<uses-feature
android:name="android.hardware.nfc"
android:required="false" />
<uses-feature
android:name="android.hardware.location.gps"
android:required="false" />
<uses-feature android:name="android.hardware.location.network"/>
<uses-feature
android:name="android.hardware.microphone"
android:required="false" />
<uses-feature
android:name="android.hardware.sensor"
android:required="false" />
<supports-screens
android:largeScreens="true"
android:normalScreens="false"
android:requiresSmallestWidthDp="720"
android:smallScreens="false"
android:xlargeScreens="true" />