代码拉取完成,页面将自动刷新
1.在项目根目录下的build.gradle文件中,
allprojects {
repositories {
maven {
url 'https://s01.oss.sonatype.org/content/repositories/release/'
}
}
}
2.在entry模块的build.gradle文件中,
dependencies {
implementation('com.gitee.chinasoft_ohos:LocationManager:1.0.0')
......
}
在sdk6,DevEco Studio2.2 beta1下项目可直接运行
如无法运行,删除项目.gradle,.idea,build,gradle,build.gradle文件,
并依据自己的版本创建新项目,将新项目的对应文件复制到根目录下
LocationManager支持在Ability、AbilitySlice、Fraction、Service中集成定位功能 每种组件对应一个父类,具体如下:
LocationBaseAbility
LocationBaseAbilitySlice
LocationBaseFraction
LocationBaseService
简单集成可以继承以上对应的抽象父类,并且实现其方法,如下:
public abstract LocationConfiguration getLocationConfiguration();
在子类中实现该方法,例如:
@Override
public LocationConfiguration getLocationConfiguration() {
return Configurations.defaultConfiguration("Give me the permission!", "Would you mind to turn GPS on?");
}
在需要的时机调用获取定位的方法:
getLocation();
提供如下方法处理定位过程和定位结果:
/**
* This method will be called whenever the process is changed.
*
* @param processType new on going process
*/
void onProcessTypeChanged(int processType);
/**
* This method will be invoked whenever new location update received
*/
void onLocationChanged(Location location);
/**
* When it is not possible to receive location, such as no active provider or no permission etc.
* It will pass an integer value from {@linkplain FailType}
* which will help you to determine how did it fail to receive location
*/
void onLocationFailed(int type);
/**
* This method will be invoked when user grants for location permissions,
* or when you ask for it but the application already had that granted.
* You can determine if permission is just granted or
* did the application already have it by checking boolean input of this method.
*/
void onPermissionGranted(boolean alreadyHadPermission);
/**
*
*
*/
void onStatusChanged(int status);
也提供了定制化接口,例如:
LocationConfiguration awesomeConfiguration = new LocationConfiguration.Builder()
.keepTracking(false)
.askForPermission(new PermissionConfiguration.Builder()
.permissionProvider(new YourCustomPermissionProvider())
.rationaleMessage("Gimme the permission!")
.rationaleDialogProvider(new YourCustomDialogProvider())
.requiredPermissions(new String[] { permission.ACCESS_FINE_LOCATION })
.build())
.useDefaultProviders(new DefaultProviderConfiguration.Builder()
.requiredTimeInterval(5 * 60 * 1000)
.requiredDistanceInterval(0)
.acceptableAccuracy(5.0f)
.acceptableTimePeriod(5 * 60 * 1000)
.gpsMessage("Turn on GPS?")
.gpsDialogProvider(new YourCustomDialogProvider())
.setWaitPeriod(ProviderType.GPS, 20 * 1000)
.build())
.build();
CodeCheck代码测试无异常
CloudTest代码测试无异常
病毒安全检测通过
当前版本demo功能与原组件基本无差异
Copyright 2016 yayandroid
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。
1. 开源生态
2. 协作、人、软件
3. 评估模型