[英]Awareness Snapshot APi not working for android
I want to be able to get the current location and activity in my Android app. 我希望能够在我的Android应用程序中获取当前位置和活动。 I implemented it, but it seems it never return anything. 我实现了它,但似乎它永不返回任何东西。 When I debug it never calls OnResult method. 当我调试时,它永远不会调用OnResult方法。 It just returns nothing. 它什么也没返回。 For example in below code it should be returning the current user activity as I/Awareness: DetectedActivity [type=STILL, confidence=100] but there is nothing getting displayed. 例如,在下面的代码中,它应该以I / Awareness的形式返回当前的用户活动:DetectedActivity [type = STILL,confidence = 100],但没有任何显示。
I'm testing this on Android v6.0 and yes fine location is in my manifest and turned on on my phone. 我正在Android v6.0上对此进行测试,可以在清单中找到正确的位置,然后在手机上将其打开。
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="com.google.android.gms.permission.ACTIVITY_RECOGNITION" />
Here's my code for getting the activity: 这是我获得活动的代码:
public class MainActivity extends AppCompatActivity {
private static final String TAG = "Awareness";
private GoogleApiClient mGoogleApiClient;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mGoogleApiClient = new GoogleApiClient.Builder(MainActivity.this)
.addApi(Awareness.API)
.build();
mGoogleApiClient.connect();
}
private void initSnapshots() {
Awareness.SnapshotApi.getDetectedActivity(mGoogleApiClient)
.setResultCallback(new ResultCallback<DetectedActivityResult>() {
@Override
public void onResult(@NonNull DetectedActivityResult detectedActivityResult) {
if (!detectedActivityResult.getStatus().isSuccess()) {
Log.e(TAG, "Could not get the current activity.");
return;
}
ActivityRecognitionResult ar = detectedActivityResult.getActivityRecognitionResult();
DetectedActivity probableActivity = ar.getMostProbableActivity();
Log.i(TAG, probableActivity.toString());
}
});
}
}
I am also following this link: https://inthecheesefactory.com/blog/google-awareness-api-in-action/en 我也在关注此链接: https : //inthecheesefactory.com/blog/google-awareness-api-in-action/en
Do you have a valid API Key in your manifest.xml? manifest.xml中是否有有效的API密钥? And enabled the Awareness API in your project? 并在您的项目中启用了意识API? - for more information see google-doc: https://developers.google.com/awareness/android-api/get-a-key -有关更多信息,请参见google-doc: https : //developers.google.com/awareness/android-api/get-a-key
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.