<small id='GJatJ'></small><noframes id='GJatJ'>

  • <i id='GJatJ'><tr id='GJatJ'><dt id='GJatJ'><q id='GJatJ'><span id='GJatJ'><b id='GJatJ'><form id='GJatJ'><ins id='GJatJ'></ins><ul id='GJatJ'></ul><sub id='GJatJ'></sub></form><legend id='GJatJ'></legend><bdo id='GJatJ'><pre id='GJatJ'><center id='GJatJ'></center></pre></bdo></b><th id='GJatJ'></th></span></q></dt></tr></i><div id='GJatJ'><tfoot id='GJatJ'></tfoot><dl id='GJatJ'><fieldset id='GJatJ'></fieldset></dl></div>

    1. <tfoot id='GJatJ'></tfoot>

      1. <legend id='GJatJ'><style id='GJatJ'><dir id='GJatJ'><q id='GJatJ'></q></dir></style></legend>
          <bdo id='GJatJ'></bdo><ul id='GJatJ'></ul>
      2. 无法在android api23上打开位置?

        时间:2023-09-01
        • <tfoot id='UJucm'></tfoot>

          <small id='UJucm'></small><noframes id='UJucm'>

                <legend id='UJucm'><style id='UJucm'><dir id='UJucm'><q id='UJucm'></q></dir></style></legend>

                  <tbody id='UJucm'></tbody>

              • <i id='UJucm'><tr id='UJucm'><dt id='UJucm'><q id='UJucm'><span id='UJucm'><b id='UJucm'><form id='UJucm'><ins id='UJucm'></ins><ul id='UJucm'></ul><sub id='UJucm'></sub></form><legend id='UJucm'></legend><bdo id='UJucm'><pre id='UJucm'><center id='UJucm'></center></pre></bdo></b><th id='UJucm'></th></span></q></dt></tr></i><div id='UJucm'><tfoot id='UJucm'></tfoot><dl id='UJucm'><fieldset id='UJucm'></fieldset></dl></div>
                  <bdo id='UJucm'></bdo><ul id='UJucm'></ul>

                  本文介绍了无法在android api23上打开位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我使用了以下代码,请求许可的对话框按预期显示.但是当我单击允许"时,它什么也不做.日志消息似乎没有被授予权限,所以我去我的参数来验证位置是否打开"并且它是关闭".它不应该是因为我授予应用程序访问我的位置的权限吗?如果我手动将其打开"然后再次运行该应用程序,一旦它请求我的许可,它就会工作并显示日志消息,但并不是请求权限(通过对话)打开位置(当它关闭)如果用户点击允许"?难道我做错了什么 ?我应该提到我正在 api23 上运行应用程序

                  I have used the following code and the dialogue that asks for permission shows as expected. But when I click "allow" it doesn't do anything. The log message doesn't appear as if the permission wasn't granted so I went to my parameters to verify if location is "on" and it was "off". Wasn't it supposed to be on because I granted the app access to my location ? If I manually turn it "on" and then run the app again, once it asks for my permission, it works and shows the log message but isn't the whole point of asking for permissions (via dialogue) to turn on location (when it's off) if the user clicks "allow" ? Am I doing something wrong ? I should mention that I'm running the app on api23

                  是我的Oncreate中的代码:

                   mApiClient = new GoogleApiClient.Builder(this)
                                  .addConnectionCallbacks(this)
                                  .addOnConnectionFailedListener(this)
                                  .addApi(LocationServices.API)
                                  .build();
                  
                   mApiClient.connect();
                  
                      // Create the LocationRequest object
                          mLocationRequest = LocationRequest.create()
                                  .setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY)
                                  .setInterval(10 * 1000)        // 10 seconds, in milliseconds
                                  .setFastestInterval(1 * 1000); // 1 second, in milliseconds
                  

                  这是我的 OnConnected 方法:

                      public void onConnected(@Nullable Bundle bundle) {
                              //start the service
                  //checking and asking for permission
                  
                              if (ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(this, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                                  if (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
                                      ActivityCompat.requestPermissions(this,
                                              new String[]{Manifest.permission.ACCESS_FINE_LOCATION},
                                              MY_PERMISSION_ACCESS_FINE_LOCATION);
                                  }
                                  //   public void onRequestPermissionsResult(int requestCode, String[] permissions,
                                  //                                          int[] grantResults)
                                  // to handle the case where the user grants the permission. See the documentation
                                  // for ActivityCompat#requestPermissions for more details.
                                  return;
                              }
                              Location location = LocationServices.FusedLocationApi.getLastLocation(mApiClient);
                  
                              if (location == null) {
                                  LocationServices.FusedLocationApi.requestLocationUpdates(mApiClient, mLocationRequest, this);
                  
                              } else {
                                  //If everything went fine lets get latitude and longitude
                                  currentLatitude = location.getLatitude();
                                  currentLongitude = location.getLongitude();
                                  Log.v("currentLatitude",currentLatitude + " WORKS " + currentLongitude + "");
                              }
                  
                      }
                  

                  推荐答案

                  试试这个代码:

                  private LocationCoord gps = null;
                  private static final int PERMISSION_REQUEST_CODE = 1;
                  

                  在 OnCreate() 中:

                  In OnCreate():

                  //GPS Manage
                      LocationManager lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
                      boolean gps_enabled = false;
                      boolean network_enabled = false;
                  
                      try {
                          gps_enabled = lm.isProviderEnabled(LocationManager.GPS_PROVIDER);
                      } catch (Exception ex) {
                      }
                  
                      try {
                          network_enabled = lm.isProviderEnabled(LocationManager.NETWORK_PROVIDER);
                      } catch (Exception ex) {
                      }
                  
                      if (!gps_enabled && !network_enabled) {
                          // notify user
                          AlertDialog.Builder dialog = new AlertDialog.Builder(this);
                          dialog.setMessage("Allow ImHere to access this device's location?");
                          dialog.setPositiveButton("Allow", new DialogInterface.OnClickListener() {
                              @Override
                              public void onClick(DialogInterface paramDialogInterface, int paramInt) {
                                  // TODO Auto-generated method stub
                                  Intent myIntent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS);
                                  startActivity(myIntent);
                                  //get gps
                              }
                          });
                          dialog.setNegativeButton("Deny", new DialogInterface.OnClickListener() {
                  
                              @Override
                              public void onClick(DialogInterface paramDialogInterface, int paramInt) {
                                  // TODO Auto-generated method stub
                  
                              }
                          });
                          dialog.show();
                      }
                  
                      gps = new LocationCoord(this);
                  

                  <小时>

                  @Override
                  protected void onStart() {
                      super.onStart();
                  
                      // permission android 6.0
                      if (!checkPermission()) {
                          requestPermission();
                      }
                  
                  }
                  
                  
                  private boolean checkPermission(){
                      int result = ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION);
                      if (result == PackageManager.PERMISSION_GRANTED) return true;
                      else return false;
                  }
                  
                  private void requestPermission(){
                      ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.ACCESS_FINE_LOCATION}, PERMISSION_REQUEST_CODE);
                  }
                  

                  您将需要 Manifest.xml 的此权限:

                  You will need this permissions on the Manifest.xml:

                  <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
                  <uses-permission android:name="android.permission.INTERNET" />
                  <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
                  <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
                  <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
                  

                  你可以在这里获取 LoocationCord.java:https://github.com/toomyy94/ImHere-Chatbot/blob/master/app/src/main/java/pt/ua/tomasr/imhere/modules/LocationCoord.java

                  You can get LoocationCord.java here: https://github.com/toomyy94/ImHere-Chatbot/blob/master/app/src/main/java/pt/ua/tomasr/imhere/modules/LocationCoord.java

                  这篇关于无法在android api23上打开位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 下一篇:地理围栏广播接收器未触发,但当我打开谷歌地

                  相关文章

                  最新文章

                  <tfoot id='sAilM'></tfoot><legend id='sAilM'><style id='sAilM'><dir id='sAilM'><q id='sAilM'></q></dir></style></legend>

                    <small id='sAilM'></small><noframes id='sAilM'>

                      <bdo id='sAilM'></bdo><ul id='sAilM'></ul>
                      <i id='sAilM'><tr id='sAilM'><dt id='sAilM'><q id='sAilM'><span id='sAilM'><b id='sAilM'><form id='sAilM'><ins id='sAilM'></ins><ul id='sAilM'></ul><sub id='sAilM'></sub></form><legend id='sAilM'></legend><bdo id='sAilM'><pre id='sAilM'><center id='sAilM'></center></pre></bdo></b><th id='sAilM'></th></span></q></dt></tr></i><div id='sAilM'><tfoot id='sAilM'></tfoot><dl id='sAilM'><fieldset id='sAilM'></fieldset></dl></div>