0

I am getting a

java.lang.SecurityException: Not allowed to bind to service Intent { act=com.android.location.service.GeocodeProvider pkg=com.google.android.location }

while trying to do fetch geocode on my JellyBean device.

Geocoder geocoder = new Geocoder(getActivity(), Locale.getDefault());                 
try {                    
    List<Address> listAddresses = geocoder.getFromLocation(latitude, longitude, 1);
    if (null != listAddresses && listAddresses.size() > 0)
        currentAddress =listAddresses.get(0);
} catch (IOException e) {
    e.printStackTrace();
}

I have the permissions ACCESS_FINE_LOCATION, ACCESS_COARSE_LOCATION, INTERNET added. How can this be avoided to get geocode all the time?


AndroidManifest.xml:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="xxx"
    android:versionCode="15"
    android:versionName="0.5" >

    <uses-sdk
        android:minSdkVersion="8"
        android:targetSdkVersion="16" />

    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

    <permission
        android:name="xxx.permission.C2D_MESSAGE"
        android:protectionLevel="signature" />

    <uses-permission android:name="xxx.permission.C2D_MESSAGE" />
    <!-- App receives GCM messages. -->
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
    <!-- GCM connects to Google Services. -->
    <uses-permission android:name="android.permission.INTERNET" />
    <!-- GCM requires a Google account. -->
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <!-- Keeps the processor from sleeping when a message is received. -->
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.NETWORK" />
    <uses-permission android:name="android.permission.USE_CREDENTIALS" />

    <application
        android:allowBackup="true"
        android:hardwareAccelerated="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name=".DashboardActivity"
            android:label="@string/app_name"
            android:screenOrientation="portrait"
            android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
            android:windowSoftInputMode="adjustPan" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".MainActivity"
            android:label="@string/title_activity_main"
            android:screenOrientation="portrait" >
        </activity>

        <receiver
            android:name="com.google.android.gcm.GCMBroadcastReceiver"
            android:permission="com.google.android.c2dm.permission.SEND" >
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                <action android:name="com.google.android.c2dm.intent.REGISTRATION" />

                <category android:name="xxx" />
            </intent-filter>
        </receiver>

        <service android:name="xxx.GCMIntentService" />

        <meta-data
            android:name="com.facebook.sdk.ApplicationId"
            android:value="@string/app_id" />

        <activity android:name="com.facebook.LoginActivity" >
        </activity>
    </application>

</manifest>

(Package name was replaced by xxx.)

Alok
  • 453
  • 1
  • 4
  • 17

2 Answers2

1

Check your Android Manifest Code.

Generally, java.lang.SecurityException occurrs because you may enter two entries pointing to same activity. Remove the second one and check it once .

Hardik Mishra
  • 14,779
  • 9
  • 61
  • 96
androidgeek
  • 3,440
  • 1
  • 15
  • 27
1

Replace this line

Geocoder geocoder = new Geocoder(getActivity(), Locale.getDefault()); 

with

 Geocoder geocoder = new Geocoder(<Your Activity Name>.this, Locale.getDefault());

also please check if you have added these permissions under manifest tag not under the application tag(happened to me once before).

otherwise I don't think anything is wrong with your code. If problem still exists try rebooting your device and then try running code again, as this may be hardware issue.

Aashish Bhatnagar
  • 2,595
  • 2
  • 22
  • 37
  • permissions are added properly in manifest. This piece of code is inside a SherlockFragment. But thats not the problem it seems. – Alok Mar 06 '13 at 05:25
  • Restarting the device works. But would want to handle it for the end user without having him restart. – Alok Mar 06 '13 at 05:26
  • 1
    well this doesn't happen very often you can create a dialog asking user to restart device on catch block handling this exception. I mean this is reported bug we can't do much about it – Aashish Bhatnagar Mar 06 '13 at 05:28
  • What is exactly helpful in this answer? The code replacement makes no sense since you can't "replace" getActivity() with .this since this is obviously a Fragment. Why this was accepted as the answer is misleading – Bostone Mar 15 '13 at 06:04
  • this was helpful here "If problem still exists try rebooting your device and then try running code again, as this may be hardware issue." and he experienced this it was a reported bug and exception handling helped him. I posted the code because I was unaware of fragment usage. – Aashish Bhatnagar Mar 15 '13 at 06:17