Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/224.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 在安卓系统中启用按钮前确保GPS信号强_Android_Button_Gps - Fatal编程技术网

Android 在安卓系统中启用按钮前确保GPS信号强

Android 在安卓系统中启用按钮前确保GPS信号强,android,button,gps,Android,Button,Gps,在允许开始记录GPS位置的按钮单击之前,如何确保找到良好的GPS信号?好的,如果使用LocationManager-类并对onLocationChanged()执行操作,它在获得位置之前不会实际触发 编辑:这里有一些你可以尝试的东西。 编辑2:哦,我实际上误解了这个问题。不过我会留下我的回应 .xml: <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_wi

在允许开始记录GPS位置的按钮单击之前,如何确保找到良好的GPS信号?

好的,如果使用
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>

让我知道这是否适合你

您可以在按钮内使用此代码单击以检查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();
                    }

要检查GPS定位,您必须注册一个
gpsstatus.listener
,并查看GPS状态和更新之间的时间

查看此链接了解如何:

我认为这并不是为了确定是否存在GPS定位,而是为了查看GPS接收器是否已启用。GPS可以在没有正确定位的情况下启用。另外,getLastKnownLocation无法确保“当前gps会话”中的位置。如果您的gps接收器位于地下1000米处,此代码将返回true。您想知道gps是否已固定,对吗?如中所示,您可以定期接收位置?是否可以从服务设置按钮可见性?LocationListener是应用程序中服务的一部分。谢谢。我对此不太确定,但您是否可以通过变量将其传递给您的应用程序,并在启动活动时进行检查?不过,这将是一个静态解决方案。
 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();
                    }