Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/181.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/grails/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 活动识别API_Android_Google Play Services_Activity Recognition - Fatal编程技术网

Android 活动识别API

Android 活动识别API,android,google-play-services,activity-recognition,Android,Google Play Services,Activity Recognition,在最近的Google Play服务更新中,有人对活动识别API有问题吗 我已经在一个应用程序中实现了它。在5.0更新之前,它工作得非常好。现在,当用户走路或坐着不动时,它会在车内返回:/ 而且根本不返回走路、跑步或走路 我应该知道的活动识别API是否有任何更改 如果您需要更多详细信息,请告诉我。行走活动和跑步活动作为输入,您需要解析它们 // Get the update ActivityRecognitionResult result = ActivityRecognitionResult.e

在最近的Google Play服务更新中,有人对活动识别API有问题吗

我已经在一个应用程序中实现了它。在5.0更新之前,它工作得非常好。现在,当用户走路或坐着不动时,它会在车内返回
:/

而且根本不返回走路、跑步或走路

我应该知道的活动识别API是否有任何更改


如果您需要更多详细信息,请告诉我。

行走活动和跑步活动作为输入,您需要解析它们

// Get the update
ActivityRecognitionResult result = ActivityRecognitionResult.extractResult(intent);

// Get the most probable activity from the list of activities in the update
DetectedActivity mostProbableActivity = result.getMostProbableActivity();

// Get the type of activity
int activityType = mostProbableActivity.getType();

if (activityType == DetectedActivity.ON_FOOT) {
    DetectedActivity betterActivity = walkingOrRunning(result.getProbableActivities());
    if (null != betterActivity)
        mostProbableActivity = betterActivity;
}

private DetectedActivity walkingOrRunning(List<DetectedActivity> probableActivities) {
    DetectedActivity myActivity = null;
    int confidence = 0;
    for (DetectedActivity activity : probableActivities) {
        if (activity.getType() != DetectedActivity.RUNNING && activity.getType() != DetectedActivity.WALKING)
            continue;

        if (activity.getConfidence() > confidence)
            myActivity = activity;
    }

    return myActivity;
}

主要的变化是ON_FOOT现在返回检测到的活动列表。现在改为使用getMostProbableActivities()

此解决方案在步行时可以行走或跑步 获取检测到的活动列表,如下所示:

//Get the list from the result
ActivityRecognitionResult result = ActivityRecognitionResult.extractResult(intent);
ArrayList<DetectedActivity> activityList = new ArrayList<DetectedActivity>(result.getProbableActivities());

//Get the most probable activity
getMostProbableActivity(activityList);
private DetectedActivity getMostProbableActivity(List<DetectedActivity> detectedActivityList)
{
DetectedActivity result = null;

//Find the most probably activity in the list
for(DetectedActivity detectedActivity : detectedActivityList)
{
    if(detectedActivity.getType() != DetectedActivity.ON_FOOT)
    {
        if(result == null)
        {
            result = detectedActivity;
        }
        else
        {
            if(result.getConfidence() < detectedActivity.getConfidence())
            {
                result = detectedActivity;
            }
        }
    }
}

return result;
//从结果中获取列表
ActivityRecognitionResult=ActivityRecognitionResult.extractResult(意图);
ArrayList activityList=新的ArrayList(result.getProbableActivities());
//获取最可能的活动
getMostProbableActivity(活动列表);
现在通过列表查找最可能的活动,如下所示:

//Get the list from the result
ActivityRecognitionResult result = ActivityRecognitionResult.extractResult(intent);
ArrayList<DetectedActivity> activityList = new ArrayList<DetectedActivity>(result.getProbableActivities());

//Get the most probable activity
getMostProbableActivity(activityList);
private DetectedActivity getMostProbableActivity(List<DetectedActivity> detectedActivityList)
{
DetectedActivity result = null;

//Find the most probably activity in the list
for(DetectedActivity detectedActivity : detectedActivityList)
{
    if(detectedActivity.getType() != DetectedActivity.ON_FOOT)
    {
        if(result == null)
        {
            result = detectedActivity;
        }
        else
        {
            if(result.getConfidence() < detectedActivity.getConfidence())
            {
                result = detectedActivity;
            }
        }
    }
}

return result;
private DetectedActivity getMostProbableActivity(列表detectedActivityList)
{
DetectedActivity结果=null;
//在列表中查找最可能的活动
for(DetectedActivity DetectedActivity:detectedActivityList)
{
if(detectedActivity.getType()!=detectedActivity.ON_FOOT)
{
如果(结果==null)
{
结果=检测到的活性;
}
其他的
{
if(result.getConfidence()

}我有Google play Services 5.0.84 它与我的Nexus5配合得很好。我不知道你在说什么,所以这可能是你代码中的错误

我的应用程序每分钟都在不断地采样,并且(大部分时间)返回正确的活动。驾驶/行走/倾斜/步行。。万事俱备

另外,如果您没有使用
getMostProbableActivity
,那么您应该使用它!
注释:在特定的设备或某些厂商的固件中,可能确实会出现故障,但这不太可能。

您可以尝试这个简单的“for循环”,以确保您的用户正在驾驶

for (DetectedActivity detectedActivity : detectedActivityList)
        {
           {
              if(DetectedActivity == “In_Vehicle” && result.getConfidence()> 75)
                     {
                        // output = User is Driving;
                        // Perform task 
                     }
           }
        }
记住,Google Play services要确保您的用户正在执行某项任务,置信度必须大于75,只有这样您才能确保任务已执行。
或者,您可以尝试一些免费SDK,如Tranql、Neura或ContextHub,它们可以让您更好地了解用户的活动和位置。

感谢您的回复。我不需要知道用户是步行还是跑步,我只需要知道用户是步行。所以我就到此为止。现在,我需要做的就是找出用户走路或坐着时API返回车内的原因。您是否基于信心进行过滤,并使用最可能的活动
DetectedActivity mostProbableActivity=result.getMostProbableActivity()
mostProbableActivity.getConfidence()>=50
不,我只是在使用getMostProbableActivity()。今天我将尝试一下getConfidence(),让您了解它的运行情况。我正在使用getMostProbableActivity()。我还没有尝试过getConfidence。它的价格被低估了,谷歌建议改用无连接API。