0

LocationManagerforで登録後、登録期間中にデータやネットワークのオン/オフを切り替えてもLocationManager.NETWORK_PROVIDERコールバック は呼び出されません。onStatusChanged()この方法は、ネットワーク ベースのプロバイダーには無効ですか?

4

1 に答える 1

0

これを試して :

package com.mytest;

import android.R;
import android.app.Activity;
import android.content.Context;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.location.LocationProvider;
import android.os.Bundle;
import android.widget.TextView;

public class NetworkTest extends Activity {

    private LocationManager locationManager;
    private TextView textView;
    private final LocationListener networkLocationListener=new LocationListener(){

        @Override
        public void onStatusChanged(String provider, int status, Bundle extras) {
            switch (status) {
            case LocationProvider.AVAILABLE:
                textView.setText(textView.getText().toString()
                        + "Network location available again\n");
                break;
            case LocationProvider.OUT_OF_SERVICE:
                textView.setText(textView.getText().toString()
                        + "Network location out of service\n");
                break;
            case LocationProvider.TEMPORARILY_UNAVAILABLE:
                textView.setText(textView.getText().toString()
                        + "Network location temporarily unavailable\n");
                break;
            }
        }

        @Override
        public void onProviderEnabled(String provider) {
            textView.setText(textView.getText().toString()
                    + "Network Provider Enabled\n");
        }

        @Override
        public void onProviderDisabled(String provider) {
            textView.setText(textView.getText().toString()
                    + "Network Provider Disabled\n");
        }

        @Override
        public void onLocationChanged(Location location) {
            textView.setText(textView.getText().toString()
                    + "New network location: "
                    + String.format("%9.6f", location.getLatitude()) + ", "
                    + String.format("%9.6f", location.getLongitude()) + "\n");
        }
    };

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activitynetwork);
        textView = (TextView) findViewById(R.id.textview);
        locationManager = (LocationManager)
                getSystemService(Context.LOCATION_SERVICE);
    }

    @Override
    protected void onResume() {
        super.onResume();
        locationManager.requestLocationUpdates(
                LocationManager.NETWORK_PROVIDER, 5000, 0,
                networkLocationListener);
    }

    @Override
    protected void onPause() {
        super.onPause();
        locationManager.removeUpdates(networkLocationListener);
    }
}

わたしにはできる。

于 2013-01-31T18:10:48.403 に答える