Android-系统服务-LocationManager

0 快速索引表

  • 权限汇总

https://developer.android.google.cn/reference/android/Manifest.permission

/frameworks/base/core/res/AndroidManifest.xml

android.permission.ACCESS_FINE_LOCATION

android.permission.ACCESS_COARSE_LOCATION

android.permission.ACCESS_BACKGROUND_LOCATION

android.permission.LOCATION_BYPASS

  • 接口汇总

https://developer.android.google.cn/reference/android/location/LocationManager

/frameworks/base/location/java/android/location/LocationManager.java

android.location.LocationManager.getLastKnownLocation

android.location.LocationManager.requestSingleUpdate

android.location.LocationManager.getCurrentLocation

android.location.LocationManager.requestLocationUpdates

https://developer.android.google.cn/reference/android/location/Location

/frameworks/base/location/java/android/location/Location.java

android.location.Location.getAccuracy

android.location.Location.getAltitude

android.location.Location.getExtras

android.location.Location.getLatitude

android.location.Location.getLongitude

https://developer.android.google.cn/reference/android/location/Address

/frameworks/base/location/java/android/location/Address.java

android.location.Address.getLongitude

android.location.Address.getLatitude

https://developer.android.google.cn/reference/android/telephony/CellLocation

android.telephony.CellLocation.requestLocationUpdate

https://developer.android.google.cn/reference/android/telephony/CellIdentityCdma

android.telephony.CellIdentityCdma.getLatitude
android.telephony.CellIdentityCdma.getLongitude

  • adb命令

adb shell cmd location

adb shell dumpsys location

  • 参考资料

https://developer.android.google.cn/training/location?hl=zh-cn

Android GPS 简介

Android11 GPS 流程代码走读


1 需求

Android版本升级导致位置权限变化:

  • Android 12支持配置精确定位和粗略定位
  • Android 11支持单次授权
  • Android 10支持后台请求位置权限

2 权限

android.permission.ACCESS_FINE_LOCATION

  • Added in API level 1
  • Protection level: dangerous
1210     <!-- Allows an app to access precise location.
1211          Alternatively, you might want {@link #ACCESS_COARSE_LOCATION}.
1212          <p>Protection level: dangerous
1213     -->
1214     <permission android:name="android.permission.ACCESS_FINE_LOCATION"
1215         android:permissionGroup="android.permission-group.UNDEFINED"
1216         android:label="@string/permlab_accessFineLocation"
1217         android:description="@string/permdesc_accessFineLocation"
1218         android:backgroundPermission="android.permission.ACCESS_BACKGROUND_LOCATION"
1219         android:protectionLevel="dangerous|instant" />

android.permission.ACCESS_COARSE_LOCATION

  • Added in API level 1
  • Protection level: dangerous
1221     <!-- Allows an app to access approximate location.
1222          Alternatively, you might want {@link #ACCESS_FINE_LOCATION}.
1223          <p>Protection level: dangerous
1224     -->
1225     <permission android:name="android.permission.ACCESS_COARSE_LOCATION"
1226         android:permissionGroup="android.permission-group.UNDEFINED"
1227         android:label="@string/permlab_accessCoarseLocation"
1228         android:description="@string/permdesc_accessCoarseLocation"
1229         android:backgroundPermission="android.permission.ACCESS_BACKGROUND_LOCATION"
1230         android:protectionLevel="dangerous|instant" />

android.permission.ACCESS_BACKGROUND_LOCATION

  • Added in API level 29
  • Protection level: dangerous
1232     <!-- Allows an app to access location in the background. If you're requesting this permission,
1233          you must also request either {@link #ACCESS_COARSE_LOCATION} or
1234          {@link #ACCESS_FINE_LOCATION}. Requesting this permission by itself doesn't give you
1235          location access.
1236          <p>Protection level: dangerous
1237 
1238          <p> This is a hard restricted permission which cannot be held by an app until
1239          the installer on record whitelists the permission. For more details see
1240          {@link android.content.pm.PackageInstaller.SessionParams#setWhitelistedRestrictedPermissions(Set)}.
1241     -->
1242     <permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION"
1243         android:permissionGroup="android.permission-group.UNDEFINED"
1244         android:label="@string/permlab_accessBackgroundLocation"
1245         android:permissionFlags="hardRestricted"
1246         android:description="@string/permdesc_accessBackgroundLocation"
1247         android:protectionLevel="dangerous|instant" />
1248 

android.permission.LOCATION_BYPASS

1249     <!-- Allows an application (emergency or advanced driver-assistance app) to bypass
1250     location settings.
1251          <p>Not for use by third-party applications.
1252          @SystemApi
1253          @hide
1254     -->
1255     <permission android:name="android.permission.LOCATION_BYPASS"
1256                 android:protectionLevel="signature|privileged"/>

3 接口

android.location.LocationManager.getLastKnownLocation

  • Added in API level 1
  • @RequiresPermission(anyOf = {ACCESS_COARSE_LOCATION, ACCESS_FINE_LOCATION})
820      /**
821       * Gets the last known location from the given provider, or null if there is no last known
822       * location. The returned location may be quite old in some circumstances, so the age of the
823       * location should always be checked.
824       *
825       * <p>This will never activate sensors to compute a new location, and will only ever return a
826       * cached location.
827       *
828       * <p>See also {@link #getCurrentLocation(String, CancellationSignal, Executor, Consumer)} which
829       * will always attempt to return a current location, but will potentially use additional power
830       * in the course of the attempt as compared to this method.
831       *
832       * @param provider a provider listed by {@link #getAllProviders()}
833       *
834       * @return the last known location for the given provider, or null if not available
835       *
836       * @throws SecurityException if no suitable permission is present
837       * @throws IllegalArgumentException if provider is null or doesn't exist
838       */
839      @RequiresPermission(anyOf = {ACCESS_COARSE_LOCATION, ACCESS_FINE_LOCATION})
840      @Nullable
841      public Location getLastKnownLocation(@NonNull String provider) {
842          return getLastKnownLocation(provider, new LastLocationRequest.Builder().build());
843      }
845      /**
846       * Gets the last known location from the given provider, or null if there is no last known
847       * location.
848       *
849       * <p>See {@link LastLocationRequest} documentation for an explanation of various request
850       * parameters and how they can affect the returned location.
851       *
852       * <p>See {@link #getLastKnownLocation(String)} for more detail on how this method works.
853       *
854       * @param provider            a provider listed by {@link #getAllProviders()}
855       * @param lastLocationRequest the last location request containing location parameters
856       *
857       * @return the last known location for the given provider, or null if not available
858       *
859       * @throws SecurityException if no suitable permission is present
860       * @throws IllegalArgumentException if provider is null or doesn't exist
861       * @throws IllegalArgumentException if lastLocationRequest is null
862       *
863       * @hide
864       */
865      @SystemApi
866      @RequiresPermission(anyOf = {ACCESS_COARSE_LOCATION, ACCESS_FINE_LOCATION})
867      @Nullable
868      public Location getLastKnownLocation(@NonNull String provider,
869              @NonNull LastLocationRequest lastLocationRequest) {
870          Preconditions.checkArgument(provider != null, "invalid null provider");
871          Preconditions.checkArgument(lastLocationRequest != null,
872                  "invalid null last location request");
873  
874          try {
875              return mService.getLastLocation(provider, lastLocationRequest,
876                      mContext.getPackageName(), mContext.getAttributionTag());
877          } catch (RemoteException e) {
878              throw e.rethrowFromSystemServer();
879          }
880      }

android.location.LocationManager.requestSingleUpdate

  • Added in API level 9
  • Deprecated in API level 30
  • Use getCurrentLocation() instead
1007      /**
1008       * Register for a single location update using the named provider and a callback.
1009       *
1010       * <p>See {@link #requestLocationUpdates(String, long, float, LocationListener, Looper)} for
1011       * more detail on how to use this method.
1012       *
1013       * @param provider a provider listed by {@link #getAllProviders()}
1014       * @param listener the listener to receive location updates
1015       * @param looper   the looper handling listener callbacks, or null to use the looper of the
1016       *                 calling thread
1017       *
1018       * @throws IllegalArgumentException if provider is null or doesn't exist
1019       * @throws IllegalArgumentException if listener is null
1020       * @throws SecurityException        if no suitable permission is present
1021       * @deprecated Use {@link #getCurrentLocation(String, CancellationSignal, Executor, Consumer)}
1022       * instead as it does not carry a risk of extreme battery drain.
1023       */
1024      @Deprecated
1025      @RequiresPermission(anyOf = {ACCESS_COARSE_LOCATION, ACCESS_FINE_LOCATION})
1026      public void requestSingleUpdate(
1027              @NonNull String provider, @NonNull LocationListener listener, @Nullable Looper looper) {
1028          Preconditions.checkArgument(provider != null, "invalid null provider");
1029  
1030          Handler handler = looper == null ? new Handler() : new Handler(looper);
1031          requestLocationUpdates(
1032                  provider,
1033                  new LocationRequest.Builder(0)
1034                          .setMaxUpdates(1)
1035                          .setDurationMillis(MAX_SINGLE_LOCATION_TIMEOUT_MS)
1036                          .build(),
1037                  new HandlerExecutor(handler),
1038                  listener);
1039      }
1041      /**
1042       * Register for a single location update using a Criteria and a callback.
1043       *
1044       * <p>Note: Since Android KitKat, Criteria requests will always result in using the
1045       * {@link #FUSED_PROVIDER}.
1046       *
1047       * <p>See {@link #requestLocationUpdates(long, float, Criteria, PendingIntent)} for more detail
1048       * on how to use this method.
1049       *
1050       * @param criteria contains parameters to choose the appropriate provider for location updates
1051       * @param listener the listener to receive location updates
1052       * @param looper   the looper handling listener callbacks, or null to use the looper of the
1053       *                 calling thread
1054       *
1055       * @throws IllegalArgumentException if criteria is null
1056       * @throws IllegalArgumentException if listener is null
1057       * @throws SecurityException        if no suitable permission is present
1058       * @deprecated Use {@link #getCurrentLocation(String, CancellationSignal, Executor, Consumer)}
1059       * instead as it does not carry a risk of extreme battery drain.
1060       */
1061      @Deprecated
1062      @RequiresPermission(anyOf = {ACCESS_COARSE_LOCATION, ACCESS_FINE_LOCATION})
1063      public void requestSingleUpdate(
1064              @NonNull Criteria criteria,
1065              @NonNull LocationListener listener,
1066              @Nullable Looper looper) {
1067          Preconditions.checkArgument(criteria != null, "invalid null criteria");
1068  
1069          Handler handler = looper == null ? new Handler() : new Handler(looper);
1070          requestLocationUpdates(
1071                  FUSED_PROVIDER,
1072                  new LocationRequest.Builder(0)
1073                          .setQuality(criteria)
1074                          .setMaxUpdates(1)
1075                          .setDurationMillis(MAX_SINGLE_LOCATION_TIMEOUT_MS)
1076                          .build(),
1077                  new HandlerExecutor(handler),
1078                  listener);
1079      }
1081      /**
1082       * Register for a single location update using a named provider and pending intent.
1083       *
1084       * <p>See {@link #requestLocationUpdates(long, float, Criteria, PendingIntent)} for more detail
1085       * on how to use this method.
1086       *
1087       * @param provider      a provider listed by {@link #getAllProviders()}
1088       * @param pendingIntent the pending intent to send location updates
1089       *
1090       * @throws IllegalArgumentException if provider is null or doesn't exist
1091       * @throws IllegalArgumentException if intent is null
1092       * @throws SecurityException        if no suitable permission is present
1093       * @deprecated Use {@link #getCurrentLocation(String, CancellationSignal, Executor, Consumer)}
1094       * instead as it does not carry a risk of extreme battery drain.
1095       */
1096      @Deprecated
1097      @RequiresPermission(anyOf = {ACCESS_COARSE_LOCATION, ACCESS_FINE_LOCATION})
1098      public void requestSingleUpdate(@NonNull String provider,
1099              @NonNull PendingIntent pendingIntent) {
1100          Preconditions.checkArgument(provider != null, "invalid null provider");
1101  
1102          requestLocationUpdates(
1103                  provider,
1104                  new LocationRequest.Builder(0)
1105                          .setMaxUpdates(1)
1106                          .setDurationMillis(MAX_SINGLE_LOCATION_TIMEOUT_MS)
1107                          .build(),
1108                  pendingIntent);
1109      }
1111      /**
1112       * Register for a single location update using a Criteria and pending intent.
1113       *
1114       * <p>Note: Since Android KitKat, Criteria requests will always result in using the
1115       * {@link #FUSED_PROVIDER}.
1116       *
1117       * <p>See {@link #requestLocationUpdates(long, float, Criteria, PendingIntent)} for more detail
1118       * on how to use this method.
1119       *
1120       * @param criteria      contains parameters to choose the appropriate provider for location
1121       *                      updates
1122       * @param pendingIntent the pending intent to send location updates
1123       *
1124       * @throws IllegalArgumentException if provider is null or doesn't exist
1125       * @throws IllegalArgumentException if intent is null
1126       * @throws SecurityException        if no suitable permission is present
1127       * @deprecated Use {@link #getCurrentLocation(String, CancellationSignal, Executor, Consumer)}
1128       * instead as it does not carry a risk of extreme battery drain.
1129       */
1130      @Deprecated
1131      @RequiresPermission(anyOf = {ACCESS_COARSE_LOCATION, ACCESS_FINE_LOCATION})
1132      public void requestSingleUpdate(@NonNull Criteria criteria,
1133              @NonNull PendingIntent pendingIntent) {
1134          Preconditions.checkArgument(criteria != null, "invalid null criteria");
1135  
1136          requestLocationUpdates(
1137                  FUSED_PROVIDER,
1138                  new LocationRequest.Builder(0)
1139                          .setQuality(criteria)
1140                          .setMaxUpdates(1)
1141                          .setDurationMillis(MAX_SINGLE_LOCATION_TIMEOUT_MS)
1142                          .build(),
1143                  pendingIntent);
1144      }

android.location.LocationManager.getCurrentLocation

  • Added in API level 30
882      /**
883       * Asynchronously returns a single current location fix from the given provider.
884       *
885       * <p>See
886       * {@link #getCurrentLocation(String, LocationRequest, CancellationSignal, Executor, Consumer)}
887       * for more information.
888       *
889       * @param provider           a provider listed by {@link #getAllProviders()}
890       * @param cancellationSignal an optional signal that allows for cancelling this call
891       * @param executor           the callback will take place on this {@link Executor}
892       * @param consumer           the callback invoked with either a {@link Location} or null
893       *
894       * @throws IllegalArgumentException if provider is null or doesn't exist
895       * @throws IllegalArgumentException if executor is null
896       * @throws IllegalArgumentException if consumer is null
897       * @throws SecurityException        if no suitable permission is present
898       */
899      @RequiresPermission(anyOf = {ACCESS_COARSE_LOCATION, ACCESS_FINE_LOCATION})
900      public void getCurrentLocation(@NonNull String provider,
901              @Nullable CancellationSignal cancellationSignal,
902              @NonNull @CallbackExecutor Executor executor, @NonNull Consumer<Location> consumer) {
903          getCurrentLocation(
904                  provider,
905                  new LocationRequest.Builder(0).build(),
906                  cancellationSignal, executor, consumer);
907      }
909      /**
910       * Asynchronously returns a single current location fix from the given provider based on the
911       * given {@link LocationRequest}.
912       *
913       * <p>See
914       * {@link #getCurrentLocation(String, LocationRequest, CancellationSignal, Executor, Consumer)}
915       * for more information.
916       *
917       * @param locationRequest    the location request containing location parameters
918       * @param cancellationSignal an optional signal that allows for cancelling this call
919       * @param executor           the callback will take place on this {@link Executor}
920       * @param consumer           the callback invoked with either a {@link Location} or null
921       *
922       * @throws IllegalArgumentException if provider is null or doesn't exist
923       * @throws IllegalArgumentException if executor is null
924       * @throws IllegalArgumentException if consumer is null
925       * @throws SecurityException        if no suitable permission is present
926       * @hide
927       * @deprecated Use
928       * {@link #getCurrentLocation(String, LocationRequest, CancellationSignal, Executor, Consumer)}
929       * instead.
930       */
931      @Deprecated
932      @SystemApi
933      @RequiresPermission(anyOf = {ACCESS_COARSE_LOCATION, ACCESS_FINE_LOCATION})
934      public void getCurrentLocation(@NonNull LocationRequest locationRequest,
935              @Nullable CancellationSignal cancellationSignal,
936              @NonNull @CallbackExecutor Executor executor, @NonNull Consumer<Location> consumer) {
937          Preconditions.checkArgument(locationRequest.getProvider() != null);
938          getCurrentLocation(locationRequest.getProvider(), locationRequest, cancellationSignal,
939                  executor, consumer);
940      }
  •  Added in API level 31
942      /**
943       * Asynchronously returns a single current location fix from the given provider based on the
944       * given {@link LocationRequest}. This may activate sensors in order to compute a new location,
945       * unlike {@link #getLastKnownLocation(String)}, which will only return a cached fix if
946       * available. The given callback will be invoked once and only once, either with a valid
947       * location or with a null location if the provider was unable to generate a valid location.
948       *
949       * <p>A client may supply an optional {@link CancellationSignal}. If this is used to cancel the
950       * operation, no callback should be expected after the cancellation.
951       *
952       * <p>This method may return locations from the very recent past (on the order of several
953       * seconds), but will never return older locations (for example, several minutes old or older).
954       * Clients may rely upon the guarantee that if this method returns a location, it will represent
955       * the best estimation of the location of the device in the present moment.
956       *
957       * <p>Clients calling this method from the background may notice that the method fails to
958       * determine a valid location fix more often than while in the foreground. Background
959       * applications may be throttled in their location accesses to some degree.
960       *
961       * The given location request may be used to provide hints on how a fresh location is computed
962       * if necessary. In particular {@link LocationRequest#getDurationMillis()} can be used to
963       * provide maximum duration allowed before failing. The system will always cap the maximum
964       * amount of time a request for current location may run to some reasonable value (less than a
965       * minute for example) before the request is failed.
966       *
967       * @param provider           a provider listed by {@link #getAllProviders()}
968       * @param locationRequest    the location request containing location parameters
969       * @param cancellationSignal an optional signal that allows for cancelling this call
970       * @param executor           the callback will take place on this {@link Executor}
971       * @param consumer           the callback invoked with either a {@link Location} or null
972       *
973       * @throws IllegalArgumentException if provider is null or doesn't exist
974       * @throws IllegalArgumentException if executor is null
975       * @throws IllegalArgumentException if consumer is null
976       * @throws SecurityException        if no suitable permission is present
977       */
978      @RequiresPermission(anyOf = {ACCESS_COARSE_LOCATION, ACCESS_FINE_LOCATION})
979      public void getCurrentLocation(@NonNull String provider,
980              @NonNull LocationRequest locationRequest,
981              @Nullable CancellationSignal cancellationSignal,
982              @NonNull @CallbackExecutor Executor executor, @NonNull Consumer<Location> consumer) {
983          Preconditions.checkArgument(provider != null, "invalid null provider");
984          Preconditions.checkArgument(locationRequest != null, "invalid null location request");
985  
986          if (cancellationSignal != null) {
987              cancellationSignal.throwIfCanceled();
988          }
989  
990          GetCurrentLocationTransport transport = new GetCurrentLocationTransport(executor, consumer,
991                  cancellationSignal);
992  
993          ICancellationSignal cancelRemote;
994          try {
995              cancelRemote = mService.getCurrentLocation(provider,
996                      locationRequest, transport, mContext.getPackageName(),
997                      mContext.getAttributionTag(), AppOpsManager.toReceiverId(consumer));
998          } catch (RemoteException e) {
999              throw e.rethrowFromSystemServer();
1000          }
1001  
1002          if (cancellationSignal != null) {
1003              cancellationSignal.setRemote(cancelRemote);
1004          }
1005      }

android.location.LocationManager.requestLocationUpdates

  • Added in API level 1
1146      /**
1147       * Register for location updates from the given provider with the given arguments, and a
1148       * callback on the {@link Looper} of the calling thread.
1149       *
1150       * <p>See {@link #requestLocationUpdates(String, LocationRequest, Executor, LocationListener)}
1151       * for more detail on how this method works.
1152       *
1153       * <p class="note"> Prior to Jellybean, the minTime parameter was only a hint, and some location
1154       * provider implementations ignored it. For Jellybean and onwards however, it is mandatory for
1155       * Android compatible devices to observe both the minTime and minDistance parameters.
1156       *
1157       * @param provider     a provider listed by {@link #getAllProviders()}
1158       * @param minTimeMs    minimum time interval between location updates in milliseconds
1159       * @param minDistanceM minimum distance between location updates in meters
1160       * @param listener     the listener to receive location updates
1161       *
1162       * @throws IllegalArgumentException if provider is null or doesn't exist
1163       * @throws IllegalArgumentException if listener is null
1164       * @throws RuntimeException if the calling thread has no Looper
1165       * @throws SecurityException if no suitable permission is present
1166       */
1167      @RequiresPermission(anyOf = {ACCESS_COARSE_LOCATION, ACCESS_FINE_LOCATION})
1168      public void requestLocationUpdates(@NonNull String provider, long minTimeMs, float minDistanceM,
1169              @NonNull LocationListener listener) {
1170          requestLocationUpdates(provider, minTimeMs, minDistanceM, listener, null);
1171      }

android.location.Location.getAccuracy

416      /**
417       * Returns the estimated horizontal accuracy radius in meters of this location at the 68th
418       * percentile confidence level. This means that there is a 68% chance that the true location of
419       * the device is within a distance of this uncertainty of the reported location. Another way of
420       * putting this is that if a circle with a radius equal to this accuracy is drawn around the
421       * reported location, there is a 68% chance that the true location falls within this circle.
422       * This accuracy value is only valid for horizontal positioning, and not vertical positioning.
423       *
424       * <p>This is only valid if {@link #hasAccuracy()} is true. All locations generated by the
425       * {@link LocationManager} include horizontal accuracy.
426       *
427       * @return horizontal accuracy of this location
428       */
429      public @FloatRange(from = 0.0) float getAccuracy() {
430          return mHorizontalAccuracyMeters;
431      }

android.location.Location.getAltitude

457      /**
458       * The altitude of this location in meters above the WGS84 reference ellipsoid.
459       *
460       * <p>This is only valid if {@link #hasAltitude()} is true.
461       *
462       * @return altitude of this location
463       */
464      public @FloatRange double getAltitude() {
465          return mAltitudeMeters;
466      }

android.location.Location.getExtras

740      /**
741       * Returns an optional bundle of additional information associated with this location. The keys
742       * and values within the bundle are determined by the location provider.
743       *
744       * <p> Common key/value pairs are listed below. There is no guarantee that these key/value pairs
745       * will be present for any location.
746       *
747       * <ul>
748       * <li> satellites - the number of satellites used to derive a GNSS fix
749       * </ul>
750       */
751      public @Nullable Bundle getExtras() {
752          return mExtras;
753      }

android.location.Location.getLatitude

378      /**
379       * Get the latitude in degrees. All locations generated by the {@link LocationManager} will have
380       * a valid latitude.
381       *
382       * @return latitude of this location
383       */
384      public @FloatRange(from = -90.0, to = 90.0) double getLatitude() {
385          return mLatitudeDegrees;
386      }

android.location.Location.getLongitude

397      /**
398       * Get the longitude in degrees. All locations generated by the {@link LocationManager} will
399       * have a valid longitude.
400       *
401       * @return longitude of this location
402       */
403      public @FloatRange(from = -180.0, to = 180.0) double getLongitude() {
404          return mLongitudeDegrees;
405      }

android.location.Address.getLongitude

332      /**
333       * Returns the longitude of the address if known.
334       *
335       * @throws IllegalStateException if this Address has not been assigned
336       * a longitude.
337       */
338      public double getLongitude() {
339          if (mHasLongitude) {
340              return mLongitude;
341          } else {
342              throw new IllegalStateException();
343          }
344      }

android.location.Address.getLatitude

295      /**
296       * Returns the latitude of the address if known.
297       *
298       * @throws IllegalStateException if this Address has not been assigned
299       * a latitude.
300       */
301      public double getLatitude() {
302          if (mHasLatitude) {
303              return mLatitude;
304          } else {
305              throw new IllegalStateException();
306          }
307      }

4 示例


5 adb命令

  • adb shell cmd location
C:\>adb shell cmd location help
Location service commands:
  help or -h
    Print this help text.
  is-location-enabled [--user <USER_ID>]
    Gets the master location switch enabled state. If no user is specified,
    the current user is assumed.
  set-location-enabled true|false [--user <USER_ID>]
    Sets the master location switch enabled state. If no user is specified,
    the current user is assumed.
  providers
    The providers command is followed by a subcommand, as listed below:

    add-test-provider <PROVIDER> [--requiresNetwork] [--requiresSatellite]
      [--requiresCell] [--hasMonetaryCost] [--supportsAltitude]
      [--supportsSpeed] [--supportsBearing]
      [--powerRequirement <POWER_REQUIREMENT>]
      [--extraAttributionTags <TAG>,<TAG>,...]
      Add the given test provider. Requires MOCK_LOCATION permissions which
      can be enabled by running "adb shell appops set <uid>
      android:mock_location allow". There are optional flags that can be
      used to configure the provider properties and additional arguments. If
      no flags are included, then default values will be used.
    remove-test-provider <PROVIDER>
      Remove the given test provider.
    set-test-provider-enabled <PROVIDER> true|false
      Sets the given test provider enabled state.
    set-test-provider-location <PROVIDER> --location <LATITUDE>,<LONGITUDE>
      [--accuracy <ACCURACY>] [--time <TIME>]
      Set location for given test provider. Accuracy and time are optional.
    send-extra-command <PROVIDER> <COMMAND>
      Sends the given extra command to the given provider.

      Common commands that may be supported by the gps provider, depending on
      hardware and software configurations:
        delete_aiding_data - requests deletion of any predictive aiding data
        force_time_injection - requests NTP time injection
        force_psds_injection - requests predictive aiding data injection
        request_power_stats - requests GNSS power stats update
  • adb shell dumpsys location


6 参考资料(官方)

https://developer.android.google.cn/training/location?hl=zh-cn


7 参考资料(其它)

android的四种定位方式_简单并快乐着的博客-CSDN博客

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值