2013-05-22 16 views
6

Yani bu benim MyLocationListener Sınıfjava.lang.SecurityException "gps" konum sağlayıcı ACCESS_FINE_LOCATION izni

package com.example.gpslocater; 

import android.content.Context; 
import android.location.Location; 
import android.location.LocationListener; 
import android.os.Bundle; 
import android.widget.TextView; 
import android.widget.Toast; 

public class MyLocationListener implements LocationListener { 

     public TextView mLocationTextView; 
    Context mContent; 
    public MyLocationListener(Context context) { 
     mContent = context; 
    } 
    @Override 
    public void onLocationChanged(Location location) { 

     location.getLatitude(); 
     location.getLongitude(); 

     String Text = "My current location is :" + 
     "Latitude = " + location.getLatitude() + 
     " Longitude = " + location.getLongitude(); 
     //figure out a way to make it display through a text view 
     mLocationTextView.setText(Text); 
    } 

    @Override 
    public void onProviderDisabled(String provider) { 
     Toast.makeText(mContent, "Gps Disabled", Toast.LENGTH_SHORT).show(); 

    } 

    @Override 
    public void onProviderEnabled(String provider) { 
     Toast.makeText(mContent, "Gps Enabled", Toast.LENGTH_SHORT); 


    } 

    @Override 
    public void onStatusChanged(String provider, int status, Bundle extras) { 
     // TODO Auto-generated method stub 

    } 

} 

edilir gerektirir Ve bunun çalıştığını çalıştırdığınızda bu Şimdi benim GPS Etkinlik sınıfı

public class GPSActivity extends Activity { 
    private Button mGPSButton; 
    private TextView mLatitudeTextView; 
    private TextView mLongitudeTextView; 
    private LocationManager mLocationManager; 
    private LocationListener mLocationListener; 

    @Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_gps); 

     mLocationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE); 
     mLocationListener = new MyLocationListener(null); 
     mGPSButton = (Button)findViewById(R.id.press_button); 
     mGPSButton.setOnClickListener(new View.OnClickListener() { 

      @Override 
      public void onClick(View v) { 
       // TODO Auto-generated method stub 
       mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, mLocationListener); 
      } 
     }); 
    } 


    @Override 
    public boolean onCreateOptionsMenu(Menu menu) { 
     // Inflate the menu; this adds items to the action bar if it is present. 
     getMenuInflater().inflate(R.menu.g, menu); 
     return true; 
    } 

} 

olduğunu ancak düğmeye bastıktan sonra program yanıt vermemeye başladığında bir çok hata mesajı var. a busy cat

Hata var java.lang.SecurityException "gps" konum sağlayıcısı için ACCESS_FINE_LOCATION izni gerektiğini belirten ssage, eklediğimde bunu eklemek zorunda mıyım? Programımın çökmesinin sebebi olduğunu düşünüyorum. Sağlanan logcat'ten mantıklı.

cevap

11

izinler

Liste Bazı yararlı linkler Bildiri dosyasının

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>// missing in manifest file 

aşağıda izni ekle Manifest'inizde

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

Bildirimin manifesto düğümüne izinlerin eklenmesi gerektiğini unutmayın. İzin yapısı hakkında daha fazla bilgi burada bulunabilir: [link] (http://developer.android.com/guide/topics/manifest/manifest-intro.html#perms) – GreatSeaSpider

-1

ya sen

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

senin .. tezahür İzin Bu koymak iznini kullanmadığı ihtiyaç düzeltin:

AndroidManifest.xml

... 

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

... 

Ayrıca Eclipse İzin Editör kullanabilirsiniz.

2

Android beyannamesine aşağıdaki izinleri eklemek zorunda

<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/> 
İlgili konular