您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
35 行
1.6 KiB
35 行
1.6 KiB
using UnityEngine;
|
|
using HuaweiHms;
|
|
|
|
namespace HuaweiHmsDemo{
|
|
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 Activity());
|
|
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());
|
|
}
|
|
}
|
|
}
|