Gps通知图标不闪烁

时间:2012-07-15 19:02:01

标签: android gps

我正在通过以下代码在我的Android手机上尝试google maps api。我的应用程序找到我的手机,工作得很好,但gps通知图标不闪烁。如何在找到手机时闪烁gps图标。

感谢回复。

清单:

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

和守则:

import java.util.List;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapActivity;
import com.google.android.maps.MapController;
import com.google.android.maps.MapView;
import com.google.android.maps.MyLocationOverlay;
import com.google.android.maps.Overlay;
import com.google.android.maps.OverlayItem;

import android.content.Context;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.location.LocationProvider;
import android.os.Bundle;
import android.provider.Settings;
import android.widget.EditText;
import android.widget.Toast;

public class main extends MapActivity {

    MapController mControl;
    GeoPoint geoP;
    MapView mapV;
    MyLocationOverlay compass;
    EditText etext;
    String provider;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        etext = (EditText) findViewById(R.id.latLong);
        mapV = (MapView) findViewById(R.id.mapView);
        mapV.displayZoomControls(true);
        mapV.setBuiltInZoomControls(true);

        LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
        boolean enable = locationManager
                .isProviderEnabled(LocationManager.GPS_PROVIDER);
        if (!enable) {
            startActivity(new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS));
        }

        Criteria criteria = new Criteria();
        //criteria.setAccuracy(Criteria.ACCURACY_FINE);
        provider = locationManager.getBestProvider(criteria, false);

        Location location = locationManager.getLastKnownLocation(provider);
        Double lat = location.getLatitude() * 1E6;
        Double longi = location.getLongitude() * 1E6;
        geoP = new GeoPoint(lat.intValue(), longi.intValue());

        List<Overlay> mapOverlays = mapV.getOverlays();
        Drawable drawable = this.getResources().getDrawable(R.drawable.androidmarker);
        compass = new MyLocationOverlay(this, mapV);

        HelloItemizedOverlay itemizedoverlay = new HelloItemizedOverlay(drawable, this);
        OverlayItem overlayitem = new OverlayItem(geoP, "Hola, Mundo!","I'm in Mexico City!");

        itemizedoverlay.addOverlay(overlayitem);

        mapV.getOverlays().add(compass);
        mapOverlays.add(itemizedoverlay);

        mControl = mapV.getController();
        mControl.animateTo(geoP);
        mControl.setZoom(5);
        mControl.setCenter(geoP);

        locationManager.requestLocationUpdates(provider, 0, 0,
                new LocationListener() {

                    public void onStatusChanged(String provider, int status,
                            Bundle extras) {
                        if (status == LocationProvider.AVAILABLE) {
                            Toast.makeText(getApplicationContext(),
                                    "LocationProvider.AVAILABLE",
                                    Toast.LENGTH_SHORT).show();
                        } else if (status == LocationProvider.TEMPORARILY_UNAVAILABLE) {
                            Toast.makeText(getApplicationContext(),
                                    "LocationProvider.TEMPORARILY_UNAVAILABLE",
                                    Toast.LENGTH_SHORT).show();
                        } else if (status == LocationProvider.OUT_OF_SERVICE) {
                            Toast.makeText(getApplicationContext(),
                                    "LocationProvider.OUT_OF_SERVICE",
                                    Toast.LENGTH_SHORT).show();
                        }

                    }

                    public void onProviderEnabled(String provider) {

                    }

                    public void onProviderDisabled(String provider) {

                    }

                    public void onLocationChanged(Location location) {
                        Toast.makeText(getApplicationContext(),
                                "Location Changed", Toast.LENGTH_SHORT).show();

                    }
                });

        //etext.setText(String.valueOf(lat) + "," + String.valueOf(longi));

    }

    protected void onPause() {
        // TODO Auto-generated method stub
        super.onPause();
        compass.disableCompass();
    }

    protected void onResume() {
        // TODO Auto-generated method stub
        super.onResume();
        compass.enableCompass();
    }

    protected boolean isRouteDisplayed() {
        return false;
    }

1 个答案:

答案 0 :(得分:1)

t0mm13b,在我的手机上工作,但GPS通知图标没有闪烁。虚拟设备意味着模拟器。我解决了问题。

代码:

package com.yunusoksuz.gmapstest;

import android.app.Activity;
import android.location.Criteria;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.widget.TextView;
import android.widget.Toast;

public class YnsmapsActivity extends Activity implements LocationListener {
    /** Called when the activity is first created. */
    private LocationManager locationManager;
    private Location location;
    private String provider;
    private Double lat, longi;
    private Criteria criteria;
    TextView tv;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        tv = (TextView) findViewById(R.id.tv1);
        locationManager = (LocationManager) getSystemService(LOCATION_SERVICE);
        criteria = new Criteria();
        criteria.setAccuracy(Criteria.ACCURACY_FINE);
        criteria.setAccuracy(Criteria.ACCURACY_COARSE);
        provider = locationManager.getBestProvider(criteria, false);
        location = locationManager.getLastKnownLocation(provider);
        locationManager.requestLocationUpdates(provider, 0, 0, this);

    }

    public void onLocationChanged(Location location) {
        Toast.makeText(
                this,
                "Lat : " + location.getLatitude() + " LONG : "
                        + location.getLongitude(), Toast.LENGTH_SHORT).show();
        tv.setText("Lat : " + location.getLatitude() + " LONG : "
                + location.getLongitude());
    }

    public void onProviderDisabled(String provider) {
        // TODO Auto-generated method stub

    }

    public void onProviderEnabled(String provider) {
        // TODO Auto-generated method stub

    }

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

    }

    @Override
    protected void onPause() {
        // TODO Auto-generated method stub
        super.onPause();
        locationManager.removeUpdates(this);
    }

    @Override
    protected void onResume() {
        // TODO Auto-generated method stub
        super.onResume();
        locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0,
                0, this);
    }
}

现在gps通知闪烁。