本演示项目在Unity for Android Build中启用部分华为HMS和AGC服务,对应的类和函数的名称和用法相同。
您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

36 行
1.6 KiB

using UnityEngine;
using HuaweiService;
using HuaweiService.location;
namespace HuaweiServiceDemo{
public class LocationRunTest:Test<LocationRunTest>{
public ActivityIdentificationService activityIdentificationService;
public override void RegisterEvent(TestEvent registerEvent){
registerEvent("SetActivityPermission",RequestActivityPermission);
registerEvent("RequestActivity",RequestActivity);
registerEvent("RemoveRunning",RemoveRunning);
}
public void RequestActivityPermission(){
LocationCommon.SetPermission(
new string[]{"com.huawei.hms.permission.ACTIVITY_RECOGNITION"},
new string[]{"android.permission.ACTIVITY_RECOGNITION"}
);
}
public void RequestActivity(){
LocationBroadcast.SetActivityEnabled(true);
activityIdentificationService = ActivityIdentification.getService(new UnityPlayerActivity());
activityIdentificationService.createActivityIdentificationUpdates(5000,LocationCommon.GetPendingIntent())
.addOnSuccessListener(new LocationSuccessListener((AndroidJavaObject o)=>{
TestTip.Inst.ShowText("activity success");
}))
.addOnFailureListener(new HmsFailureListener((Exception e)=>{
TestTip.Inst.ShowText("activity failure");
}));
}
public void RemoveRunning(){
LocationBroadcast.SetActivityEnabled(false);
activityIdentificationService.deleteActivityIdentificationUpdates(LocationCommon.GetPendingIntent());
}
}
}