I'm trying to get my location (longitude and latitude) using Skyhook. I built it successfully.
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;
}
}
};
...
}
But I don't get my location.
Instead I get an Exception
:
java.lang.SecurityException: caller does not have permission to access phone state
I tried to fix this for 2 days, but i don't suitable answer.
Please help me.