在允许点击按钮开始记录GPS位置之前,如何确保找到良好的GPS信号?
答案 0 :(得分:0)
好吧,如果你使用LocationManager
- 类并对onLocationChanged()
采取行动,那么在它获得一个位置之前它实际上不会触发。
编辑:这是你可以尝试的东西。 编辑#2:噢,我实际上误读了这个问题。我会留下我的回复。
.xml
:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button android:id="@+id/mybutton1"
android:visibility="INVISIBLE"
android:layout_width="200dp"
android:layout_height="100dp"
android:text="MyButton1"
/>
</LinearLayout>
.java:
//Get the LocationManager & Button
final LocationManager locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
final Button button = (Button) findViewById(R.id.mybutton1);
//Add the listener
LocationListener locationListener = new LocationListener() {
public void onLocationChanged(Location location) {
//Remove the listener and make the button visible
locManager.removeUpdates(locationListener);
button.setVisibility(1);
}
public void onStatusChanged(String provider, int status, Bundle extras) {}
public void onProviderEnabled(String provider) {}
public void onProviderDisabled(String provider) {}
};
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, locationListener);
让我知道这是否适合您!
答案 1 :(得分:0)
要检查GPS定位,您必须注册gpsstatus.listener
并查看GPS状态和更新之间的时间。
查看此链接了解具体方法: How can I check the current status of the GPS receiver?
答案 2 :(得分:-1)
您可以在按钮单击中使用此代码来检查GPS的状态。
LocationListener ll = new MyLocationListener();
lm.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 0, 0, ll);
lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 2000, 10, ll);
LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Location location = lm.getLastKnownLocation(LocationManager.GPS_PROVIDER);
if (lm.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
Log.i("About GPS", "GPS is Enabled in your devide");
AlertDialog.Builder GPSON =new Builder(MyCardio.this);
GPSON.setCancelable(false);
GPSON.setMessage("GPS IS ON");
GPSON.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
// TODO Auto-generated method stub
}
});
GPSON.show();
} else {
AlertDialog.Builder GPSOFF = new Builder(MyCardio.this);
GPSOFF.setCancelable(false);
GPSOFF.setTitle("Connection Error");
GPSOFF.setMessage(" Please Enable Your GPS !");
GPSOFF.setPositiveButton("Ok",new DialogInterface.OnClickListener()
{
public void onClick(DialogInterface dialog,int which)
{
// startActivity(new Intent(LoginActivity.this,MainMenuActivity.class));
}
});
GPSOFF.show();
}