Android Geocoder.getLocationFromName () throws IOException: service is not available on the device

I use the Geocoder.getLocationFromName () method both on the emulator and on my phone (Nexus S with Android 4.1), and I get the following exception:

java.io.IOException: Service not Available 

There are a number of questions in the emulator ( example ), and most of them say that this is a specific version of the emulator, a problem. However, an exception appears both on my AVD (2.3 and 4.1), and on my phone.

Both my phone and AVD have an Internet connection. My version of the API is 16 (android 4.1), but I also tried to use older ones. Both AVDs include the Google API.

Any ideas on what's going on here?

This is the corresponding code snippet:

 Geocoder myGeocoder = new Geocoder(getApplicationContext(), Locale.getDefault()); List<Address> newAddresses = myGeocoder.getFromLocationName(arg0.toString(), 10); 

And this is my manifest:

 <?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.asdasd" android:versionCode="6" android:versionName="1.3.1"> <uses-sdk android:minSdkVersion="16" /> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /> <application android:icon="@drawable/ic_launcher_asdasd" android:label="@string/app_name"> <activity android:name=".AsdasdActivity" android:label="@string/app_name" android:screenOrientation="portrait" android:windowSoftInputMode="stateHidden"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name="com.google.ads.AdActivity" android:configChanges="keyboard|keyboardHidden|orientation" /> </application> </manifest> 
+6
source share
1 answer

Make sure one of the Google APIs is installed for your purpose of creating the application, not just Android 4.0 (or similar). You can change this setting in Eclipse by right-clicking on your project and choosing Properties, then Android. Alternatively, you can simply edit the project.properties file as follows:

 # Project target target=Google Inc.:Google APIs:16 

The reason is that the Geocoder class Geocoder present in the main Android platform, but depends on the code provided by the Google API for proper operation. Even if your AVD includes the Google API, your project still needs to be created against this specific build goal.

+7
source

Source: https://habr.com/ru/post/925942/


All Articles