我試圖讓我的位置(經度和緯度)使用Skyhook。 我成功構建它。Android - 如何修復權限異常
import android.app.IntentService;
import android.content.Intent;
import android.location.Address;
import android.location.Geocoder;
import android.os.Environment;
import android.os.Handler;
import android.os.Message;
import android.util.Log;
import com.reader.ebook.commomUtill.CommonUtill;
import com.reader.ebook.wxpos.IntergratedLocationManager;
import com.reader.ebook.wxpos.LocationObj;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.List;
import java.util.Locale;
public class LocationService extends IntentService {
String TAG = "Location_tag";
public LocationService() {
super(LocationService.class.getSimpleName());
}
public IntergratedLocationManager er;
public Handler _handlerForStartSearch = new Handler(){
@Override
public void handleMessage(final Message msg){
switch(msg.what){
case 0:
er.getPos();
_handlerForStartSearch.sendEmptyMessageDelayed(0, CommonUtill.updateRate);
break;
case IntergratedLocationManager.ILM_LOCATION_MESSAGE:
final LocationObj loc = (LocationObj) msg.obj;
try{
float current_latitude = loc._latitude;
float current_longitude = loc._longitude;
CommonUtill.setCoordination(current_latitude, current_longitude);
}catch (Exception e){
e.printStackTrace();
}
break;
}
}
};
...
}
但我沒有得到我的位置。 相反,我得到一個Exception
:
java.lang.SecurityException: caller does not have permission to access phone state
我試圖解決這個2天,但我不適合回答。
請幫幫我。
在哪個版本的android中您正在測試此代碼? – Prashant
@Prashant低於6,因爲在6中您會得到更具體的例外 –