2013-03-06 81 views
0

我得到一個拋出:SecurityException在地理編碼

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

試圖豆形軟糖我的設備上做獲取地理編碼。

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取代。)

+0

plz添加AndroidManifest.xml文件xml – 2013-03-06 04:47:45

+1

似乎[問題](https://code.google.com/p/android/issues/detail?id=39635) – StarPinkER 2013-03-06 04:59:42

+0

@JermaineXu,是的,我看到了,有沒有儘管如此,一個解決方法來獲取地理編碼?在清單中正確添加 – Alok 2013-03-06 05:16:15

回答

1

替換該行

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

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

也請大家有沒有應用程序標記(前一次發生在我身上)下下艙單標籤添加這些權限。

否則我不認爲你的代碼有什麼問題。 如果問題仍然存在,請嘗試重新啓動設備,然後再次嘗試運行代碼,因爲這可能是硬件問題。

+0

權限。這段代碼在SherlockFragment中。但那不是它看起來的問題。 – Alok 2013-03-06 05:25:11

+0

重新啓動設備。但是想要爲最終用戶處理它而不讓他重新啓動。 – Alok 2013-03-06 05:26:17

+1

好吧,這不會經常發生,您可以創建一個對話框,要求用戶在處理此異常的catch塊上重新啓動設備。我的意思是這是報告的錯誤,我們不能做太多關於它 – 2013-03-06 05:28:22

1

檢查您的Android清單代碼。

通常,java.lang.SecurityException發生,因爲您可能輸入兩個指向相同活動的條目。刪除第二個,並檢查一次。

相關問題