原生插件通用使用流程:

插件地址购买插件,选择该插件绑定的项目。
在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
});