Geocoder中的SecurityException

时间:2013-03-06 04:37:56

标签: android geocode securityexception

我正在

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

尝试在我的JellyBean设备上获取地理编码时。

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();
}

我添加了权限ACCESS_FINE_LOCATIONACCESS_COARSE_LOCATIONINTERNET。如何避免一直获得地理编码?


的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>

(包名称已替换为xxx。)

2 个答案:

答案 0 :(得分:1)

检查您的Android清单代码。

通常, java.lang.SecurityException 会发生,因为您可能会输入两个指向同一活动的条目。删除第二个并检查一次。

答案 1 :(得分:1)

替换此行

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

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

另外请检查您是否在清单标记下添加了这些权限,而不是在应用程序标记下(发生在我之前)。

否则我认为您的代码没有任何问题。 如果问题仍然存在,请尝试重新启动设备,然后再次尝试运行代码,因为这可能是硬件问题。