我是currentyl试图实现Google ActivityRecognitionApi.但是我得到以下错误:
错误:无法处理文件C:\ Users\marschall\Desktop\googlesamples-android-play-location-2ed2964\ActivityProject\app\build\intermediates\explosion-aar\com.google.android.gms\play-services-cast -framework\10.0.1\res\drawable-xxhdpi-v4\quantum_ic_forward_30_grey600_36.png进入C:\ Users\marschall\Desktop\googlesamples-android-play-location-2ed2964\ActivityProject\app\build\intermediates\res\merged \调试\绘制-xxhdpi-V4\quantum_ic_forward_30_grey600_36.png
错误:任务':app:mergeDebugResources'的执行失败.错误:无法处理文件C:\ Users\marschall\Desktop\googlesamples-android-play-location-2ed2964\ActivityProject\app\build\intermediates\explosion-aar\com.google.android.gms\play-services-cast -framework\10.0.1\res\drawable-xxhdpi-v4\quantum_ic_forward_30_grey600_36.png进入C:\ Users\marschall\Desktop\googlesamples-android-play-location-2ed2964\ActivityProject\app\build\intermediates\res\merged \调试\绘制-xxhdpi-V4\quantum_ic_forward_30_grey600_36.png
我是Android开发的新手,真的不知道该怎么做.
我感谢任何评论.
提前致谢
编辑:我的错!忘了复制一些文件......
java android google-api google-api-client activity-recognition
在最近的Google Play服务更新中,任何人都无法使用活动识别API吗?
我在应用程序中实现了它.它在5.0更新之前完全正常工作.现在它IN_VEHICLE在用户走路或坐着时返回.:/
并且不会返回WALKING,RUNNING或者根本不会ON_FOOT.
我应该注意哪些活动识别API有任何变化?
如果您需要更多详细信息,请与我们联系.
在最后一次谷歌I/O上,在位置API的Android中引入了一项新服务 - 活动识别.
iOS有这样的框架吗?
我使用活动识别api和活动转换.当我第一次运行应用程序时,第一次转换始终是.在这个应用程序中WALKING-ENTER.当我只尝试IN_VEHICLE-ENTER和IN_VEHICLE-EXIT在transitions,它是IN_VEHICLE-ENTER.我想忽略了第一次转换,但我测试的设备没有出现这样的问题.有这些问题的设备是Android 8.1,设备没有问题是6.0.
MainActivity扩展了AppCompatActivity
private static Intent serviceIntent;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
int PERMISSION_ALL = 1;
String[] PERMISSIONS = {Manifest.permission.ACCESS_COARSE_LOCATION, Manifest.permission.ACCESS_FINE_LOCATION};
if(!hasPermissions(this, PERMISSIONS)){
ActivityCompat.requestPermissions(this, PERMISSIONS, PERMISSION_ALL);
}
Button button = findViewById(R.id.button);
button.setOnClickListener(
new View.OnClickListener() {
public void onClick(View view) {
serviceIntent = new Intent(MainActivity.this, ServiceS.class);
MainActivity.this.startService(serviceIntent);
}
});
}
public static boolean hasPermissions(Context context, String... permissions) {
if (permissions != null) {
for (String permission : permissions) …Run Code Online (Sandbox Code Playgroud) 我正在使用Activity识别来检测用户活动.
我发现了一个奇怪的行为,在我关闭并打开"WiFi和移动网络位置"后,应用程序没有获得任何活动识别更新.
重新启动手机后,应用程序将从Google Play服务获得更新,直到我再次关闭"WiFi和移动网络位置".
当"WiFi和移动网络位置"关闭再打开时,Google Play服务上的活动识别是否存在任何已知问题?
我在活动识别方面遇到了一些麻烦.我已经在应用程序中实现了它,当设备的屏幕打开时它可以正常工作.我的Activity识别意图服务类中有一个日志条目,我可以看到它何时获得更新.所以,我知道它在屏幕打开时工作正常.
但是在手机进入待机状态(屏幕关闭)后,它会停止检测使用活动.
我没有调用DetectionRequester类中的onDisconnected(),我使用日志帖子进行了检查.
我的问题:为什么我的应用会在设备进入待机模式后停止跟踪使用活动?如何让它不停止检测用户活动?
如果您需要查看任何代码或者您需要有关我的应用程序的更多详细信息,请告诉我们.
我的MainActivity类的相关代码位.这是应用程序启动ActivityRecognition请求的位置.
public class MainActivity extends FragmentActivity {
// The activity recognition update request object
private DetectionRequester mDetectionRequester;
// The activity recognition update removal object
private DetectionRemover mDetectionRemover;
// Store the current request type (ADD or REMOVE)
private REQUEST_TYPE mRequestType;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Crashlytics.start(this);
setContentView(R.layout.activity_main);
mDetectionRequester = new DetectionRequester(this);
mDetectionRemover = new DetectionRemover(this);
// Check for Google Play services
if (servicesConnected())
{
/*
*Set the request type. If a connection error occurs, …Run Code Online (Sandbox Code Playgroud) android google-play-services location-client activity-recognition
我需要在ActivityRecognition Detect用户状态(每隔3分钟调用一次)之后获取用户的位置(通过fusionlocation API),如IN_VEHICLE,ON_FOOT,RUNNING等.
在每个事件上,我需要定期间隔后的用户位置例如:
如果用户仍然是,那么setInterval(5*60*60*1000);在5小时之前检查下一个位置更新.但ActivityRecognation将每3分钟调用一次.
如果用户正在运行,则setInterval(2*60*1000);在2分钟之前/之后检查下一个位置更新.但ActivityRecognation将每3分钟调用一次.
如果用户正在运行,则如果用户正在驾驶,则每隔1分钟发送一个位置,然后每15分钟发送一次位置.
我试图onConnected在类级别将boolean false设置为false和true.但它总是变成真实的,因为整个Intent服务在3分钟后被调用.
if (startLocationFirst){
requestLocatonSetting(5*60*60*1000,3*60*60*1000,LocationRequest.PRIORITY_HIGH_ACCURACY);
LocationAPIclient.connect();// RequestLocation and GoogleAPIClient won't call until device comes from another ActivityRecognation State running,walking etc. And keep Updating location every 5 hours.
}
Run Code Online (Sandbox Code Playgroud)
问题我现在有
startLocationFirst布尔值,直到它来自另一个ActivityRecognation状态并保持更新位置设置为内部startLocationFirst这是带有FusedLocation的IntentService
public class Activity_Recognized_Service extends IntentService implements GoogleApiClient.OnConnectionFailedListener, GoogleApiClient.ConnectionCallbacks, LocationListener {
/**
* Creates an IntentService. Invoked by your subclass's constructor.
*
* @param name Used to name the worker thread, important only for …Run Code Online (Sandbox Code Playgroud) 我最近使用Google推出的Activity Transition API来检测用户何时进出车辆.下面是我用来实现相同的代码.
val intent = Intent(context, ActivityTransitionReceiver::class.java)
val pendingIntent = PendingIntent.getBroadcast(context, requestCode, intent, PendingIntent.FLAG_UPDATE_CURRENT)
transitions.apply {
add(ActivityTransition.Builder()
.setActivityType(DetectedActivity.IN_VEHICLE)
.setActivityTransition(ActivityTransition.ACTIVITY_TRANSITION_ENTER)
.build())
add(ActivityTransition.Builder()
.setActivityType(DetectedActivity.IN_VEHICLE)
.setActivityTransition(ActivityTransition.ACTIVITY_TRANSITION_EXIT)
.build())
}
var transitionRequest = ActivityTransitionRequest(transitions)
// myPendingIntent is the instance of PendingIntent where the app receives callbacks.
val task = ActivityRecognition.getClient(context).requestActivityTransitionUpdates(transitionRequest, pendingIntent)
task.addOnSuccessListener {
// Handle success
context.toast("Task added successfully")
}
task.addOnFailureListener {
// Handle error
context.toast("Error adding task")
}
Run Code Online (Sandbox Code Playgroud)
该应用程序工作正常,并在未从最近的应用程序选项卡中删除时接收广播.但是,当应用程序从最近的应用程序选项卡中删除或被系统杀死时,我无法接收广播.我不知道我做错了什么.还有其他方法可以达到同样的目的吗?
我考虑使用前台服务,以便应用程序不被杀死,但后来认为显示永久通知只是为了检测用户活动过渡不是一个好主意.任何帮助将不胜感激.谢谢.
编辑:我已经看到一些应用程序要求特殊权限,例如"忽略电池优化",当获得此权限时,该应用程序似乎始终有效并且不断发送通知.
android broadcastreceiver android-location activity-recognition
我试图从应该显示用户活动的新Google位置API编译示例代码.喜欢步行,车辆等
该示例的链接是 http://developer.android.com/training/location/activity-recognition.html
就我而言,我可以看到Google Play服务可用,位置服务连接也很好,但之后没有任何内容. onHandleIntent从未被明显调用过.
有人试图让它发挥作用吗?或者互联网上是否还有其他一些工作示例?
谢谢
我正在尝试关注Google的活动识别示例.
在示例中,当您单击按钮时,它们会启动活动识别,但是我想在应用程序启动时启动它 - 所以我尝试将它放在onConnected方法中.但是,它最终会抛出空指针异常.
这是我如何称呼它:
@Override
public void onConnected(Bundle connectionHint) {
Log.d(TAG, "onConnected");
try {
ActivityRecognition.ActivityRecognitionApi.requestActivityUpdates(
mGoogleApiClient,
UPDATE_INTERVAL_IN_MILLISECONDS,
getActivityDetectionPendingIntent()
).setResultCallback(this);
} catch (SecurityException securityException) {
logSecurityException(securityException);
}
}
Run Code Online (Sandbox Code Playgroud)
而错误:
03-21 20:28:57.939 2340-2340/getrewards.example.com.getrewards E/AndroidRuntime? FATAL EXCEPTION: main
Process: getrewards.example.com.getrewards, PID: 2340
java.lang.NullPointerException: Appropriate Api was not requested.
at com.google.android.gms.internal.jx.b(Unknown Source)
at com.google.android.gms.common.api.c.a(Unknown Source)
at com.google.android.gms.common.api.c.a(Unknown Source)
at com.google.android.gms.common.api.c.b(Unknown Source)
at com.google.android.gms.internal.nb.requestActivityUpdates(Unknown Source)
at getrewards.example.com.getrewards.RewardsFragment.onConnected(RewardsFragment.java:274)
at com.google.android.gms.internal.jm.f(Unknown Source)
at com.google.android.gms.common.api.c.gJ(Unknown Source)
at com.google.android.gms.common.api.c.d(Unknown Source)
at com.google.android.gms.common.api.c$2.onConnected(Unknown Source)
at …Run Code Online (Sandbox Code Playgroud)