小编use*_*626的帖子

在IntentService中实现的Android LocationLister从不执行OnLocationChanged()方法

我编写了一个实现LocationListener接口的IntentService.当第一次调用OnLocationChanged()方法时,服务应该发送一条消息.但永远不会调用OnLocationChanged().这是我的代码:

public class MyIntentService extends IntentService implements LocationListener {

    private int result = Activity.RESULT_CANCELED;
    protected Messenger mMessenger;
    protected LocationManager mLocationManager = null;

    public MyIntentService() {
        super("LocationService");
    }

    @Override
    protected void onHandleIntent(Intent intent) {
        Log.i(TAG, "Got starting intent: " + intent.toString());
        Bundle extras = intent.getExtras();

        if (extras != null) {
            Messenger = (Messenger) extras.get("MESSENGER");

            if(mLocationManager == null) {  
            mLocationManager =  (LocationManager) MyIntentService.this
                                    .getSystemService(Context.LOCATION_SERVICE);
            }
            String provider = LocationManager.GPS_PROVIDER;
            boolean gpsIsEnabled = mLocationManager.isProviderEnabled(provider);

            if(gpsIsEnabled) {
                Context con = MyIntentService.this;
                mLocationManager.requestLocationUpdates(provider, 0, 0, …
Run Code Online (Sandbox Code Playgroud)

android locationlistener intentservice

4
推荐指数
1
解决办法
3022
查看次数

标签 统计

android ×1

intentservice ×1

locationlistener ×1