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

35 行
1.6 KiB

using UnityEngine;
using HuaweiHms;
namespace HuaweiHmsDemo{
public class LocationRunTest:Test<LocationRunTest>{
public ActivityIdentificationService activityIdentificationService;
public override void RegistEvent(TestEvent registEvent){
registEvent("SetActivityPermission",RequestActivityPermission);
registEvent("RequestActivity",RequestActivity);
registEvent("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 Activity());
activityIdentificationService.createActivityIdentificationUpdates(5000,LocationCommon.GetPendingIntent())
.addOnSuccessListener(new LocationSuccessListener((AndroidJavaObject o)=>{
TestTip.Inst.ShowText("activity success");
}))
.addOnFailureListener(new LocationFailureListener((Exception e)=>{
TestTip.Inst.ShowText("activity failure");
}));
}
public void RemoveRunning(){
LocationBroadcast.SetActivityEnabled(false);
activityIdentificationService.deleteActivityIdentificationUpdates(LocationCommon.GetPendingIntent());
}
}
}