更新记录

1.0.0(2023-12-23)

v1.0.0 后台定位、持续定位、息屏定位、根据wgs84坐标获取位置信息、获取手机应用使用情况、获取电池电流


平台兼容性

Android Android CPU类型 iOS
适用版本区间:4.4 - 13.0 armeabi-v7a:未测试,arm64-v8a:未测试,x86:未测试 ×

原生插件通用使用流程:

  1. 购买插件,选择该插件绑定的项目。
  2. 在HBuilderX里找到项目,在manifest的app原生插件配置中勾选模块,如需要填写参数则参考插件作者的文档添加。
  3. 根据插件作者的提供的文档开发代码,在代码中引用插件,调用插件功能。
  4. 打包自定义基座,选择插件,得到自定义基座,然后运行时选择自定义基座,进行log输出测试。
  5. 开发完毕后正式云打包

付费原生插件目前不支持离线打包。
Android 离线打包原生插件另见文档 https://nativesupport.dcloud.net.cn/NativePlugin/offline_package/android
iOS 离线打包原生插件另见文档 https://nativesupport.dcloud.net.cn/NativePlugin/offline_package/ios

注意事项:使用HBuilderX2.7.14以下版本,如果同一插件且同一appid下购买并绑定了多个包名,提交云打包界面提示包名绑定不一致时,需要在HBuilderX项目中manifest.json->“App原生插件配置”->”云端插件“列表中删除该插件重新选择


原生插件通用使用流程:

购买插件,选择该插件绑定的项目。 在HBuilderX里找到项目,在manifest的app原生插件配置中勾选模块,如需要填写参数则参考插件作者的文档添加。 根据插件作者的提供的文档开发代码,在代码中引用插件,调用插件功能。 打包自定义基座,选择插件,得到自定义基座,然后运行时选择自定义基座,进行log输出测试。 开发完毕后正式云打包 付费原生插件目前不支持离线打包,请先点击试用以便了解功能是否满足你的需要

接口说明

引入插件: 在manifest中app原生插件配置中,添加云端插件

在App.vue 文件 onLaunch 方法中引入插件,随后在需要使用的页面直接引用

//在App.vue onLaunch中引入插件
this.$store.state.fUN_PackageAndLocationModule = uni.requireNativePlugin('FUN-PackageAndLocationModule');

//在需要使用的页面onLoad中引入
this.fUN_PackageAndLocationModule = this.$store.state.fUN_PackageAndLocationModule;

1.检查是否授权定位未授权则弹出授权框 checkedLocationPermission

字段 类型 说明
code string success 响应状态
fineFlag boolean true/false 获取定位权限是否开启
backgroundFlag boolean true/false 后台获取定位权限是否开启
let that = this;
this.fUN_PackageAndLocationModule.checkedLocationPermission({},result => {
    that.fineFlag = result.fineFlag
    that.backgroundFlag = result.backgroundFlag
})

2.获取新位置 getAndroidLastKnownLocation

注:本方法需要在调用更新位置方法后才能获取到定位信息,详见第三点更新位置

字段 类型 说明
code string success 响应状态
message string getLocationOk、ACCESS_FINE_LOCATION_IS_NULL 、ACCESS_BACKGROUND_LOCATION_IS_NULL、PLEASE_REQUEST_LOCATION_PERMISSION getLocationOk为获取成功,其他为授权未成功或报错信息
fineFlag boolean true/false 获取定位权限是否开启
backgroundFlag boolean true/false 后台获取定位权限是否开启
data json {addressLine:"获取完整地址",locality:"获取城市",adminArea:"获取省份",countryName:"获取国家名",altitude:"海拔",latitude:"纬度",longitude:"经度",speed:"速度",accuracy:"精度"} 响应地址信息
let that = this;
//获取更新后的位置
that.fUN_PackageAndLocationModule.getAndroidLastKnownLocation({},curResult => {
    that.$store.state.locationUpload.count = that.$store.state.locationUpload.count+1;
    that.locationInfo = curResult.data;
    console.log(curResult)
})

3.更新位置 updateLocationByAndroid

字段 类型 说明
code string success 响应状态
message string updateOk、ACCESS_FINE_LOCATION_IS_NULL 、ACCESS_BACKGROUND_LOCATION_IS_NULL updateOk为更新成功,其他为授权未成功或报错信息
fineFlag boolean true/false 获取定位权限是否开启
backgroundFlag boolean true/false 后台获取定位权限是否开启
let that = this;
this.fUN_PackageAndLocationModule.updateLocationByAndroid({},result => {
    that.fineFlag = result.fineFlag
    that.backgroundFlag = result.backgroundFlag
    if(that.fineFlag && that.backgroundFlag){
        //获取更新后的位置
        that.fUN_PackageAndLocationModule.getAndroidLastKnownLocation({},curResult => {
            that.$store.state.locationUpload.count = that.$store.state.locationUpload.count+1;
            that.locationInfo = curResult.data;
            console.log(curResult)
        })
    }else{
        //授权
        that.checkedLocationPermission();
    }
})

4.后台授权与自启动广播注册 getAutostartSettingIntent

注:使用后台定位需要让手机保持后台运行,目前 三星、华为、小米、VIVO、OPPO、360、魅族、一加、乐视 可以使用此方法打开启动设置界面,其余手机则打开默认应用权限设置界面

this.fUN_PackageAndLocationModule.getAutostartSettingIntent({},result => {
    console.log("getAutostartSettingIntent",result)
    //会自动弹出授权弹窗
})

5.根据WGS84经纬度获取地址信息 getLocationInfo

传入wgs84经纬度,使用场景通常为uniapp获取的wgs84类型的位置信息

let that = this;
uni.getLocation({
    type: 'wgs84',
    success: function (res) {
        console.log('当前位置的经度:' + res.longitude);
        console.log('当前位置的纬度:' + res.latitude);
        let obj = {latitude:res.latitude,longitude:res.longitude}
        this.fUN_PackageAndLocationModule.getLocationInfo(obj,result => {
            that.addressInfo = result.data.addressLine;
        })
    }
});

6.获取应用信息授权情况 getIsPackagePermission

let that = this;
this.fUN_PackageAndLocationModule.getIsPackagePermission({},result => {
    if(result.code == 'success' && !result.data){//未授权
        that.showPermission = true;
    }
})

7.弹出授权获取应用弹窗 requestUsageStatsPermission

let that = this;
this.fUN_PackageAndLocationModule.requestUsageStatsPermission();

8.获取应用使用信息 getPackageInfo

let that = this;
//取出两天内应用使用时长 dasy只能取 1到7 整数,表示取几天内的数据
this.fUN_PackageAndLocationModule.getPackageInfo({days:5},result => {
    //result.data = {appName:"应用程序名称",packageName:"包名",totalTimeInForeground:"使用时长"}
});

9.获取电池电流 getBatteryCurrentInfo

let that = this;
this.fUN_PackageAndLocationModule.getBatteryCurrentInfo({days:5},result => {
    //result.current= 电流 除以10000后单位为A
});

隐私、权限声明

1. 本插件需要申请的系统权限列表:

定位权限、电池权限、应用使用情况权限、开机自启动权限

2. 本插件采集的数据、发送的服务器地址、以及数据用途说明:

插件不采集任何数据

3. 本插件是否包含广告,如包含需详细说明广告表达方式、展示频率:

暂无用户评论。

使用中有什么不明白的地方,就向插件作者提问吧~ 我要提问