コード例 #1
0
 public MotionActivityManagerImpl(AndroidContext context,
                                  AndroidSqliteDatabase database,
                                  IMessageBus messageBus)
 {
     this.context    = context;
     this.database   = database;
     this.messageBus = messageBus;
     this.client     = ActivityRecognition.GetClient(context.AppContext);
 }
コード例 #2
0
 public MotionActivityManagerImpl(ShinyCoreServices core,
                                  AndroidSqliteDatabase database,
                                  ILogger <IMotionActivityManager> logger)
 {
     this.core      = core;
     this.database  = database;
     this.logger    = logger;
     this.client    = ActivityRecognition.GetClient(core.Android.AppContext);
     this.eventSubj = new Subject <MotionActivityEvent>();
 }
コード例 #3
0
        public async override void OnDestroy()
        {
            isRunning = false;
            ActivityRecognition.GetClient(this).RemoveActivityTransitionUpdates(pendingIntent);


            if (mGoogleActivityReceiver != null)
            {
                LocalBroadcastManager.GetInstance(this).UnregisterReceiver(mGoogleActivityReceiver);
                mGoogleActivityReceiver = null;
            }

            Bundle b         = new Bundle();
            var    duration1 = DateTimeOffset.Now.Subtract(mSensorData.StartDate).TotalSeconds;

            if (duration1 > min_tracking_time)
            {
                mSensorData.Duration = duration1;
                await mDatabase.WriteAsync(tempRealm =>
                {
                    tempRealm.Add(mSensorData);
                });

                b.PutBoolean("SavingSuccessful", true);
            }
            else
            {
                b.PutBoolean("SavingSuccessful", false);
                //using (var h = new Handler(Looper.MainLooper)) h.Post(() =>
                //{
                //    Toast.MakeText(this.ApplicationContext, "Activity was too short to be saved.", ToastLength.Short).Show();
                //});
            }
            Intent onStop_intent = new Intent("StoppingSignal");

            onStop_intent.PutExtra("report", b);
            LocalBroadcastManager.GetInstance(context).SendBroadcast(onStop_intent);
            mSensorManager.UnregisterListener(this);
            base.OnDestroy();
        }
コード例 #4
0
        public override StartCommandResult OnStartCommand(Intent intent, StartCommandFlags flags, int startId)
        {
            base.OnStartCommand(intent, flags, startId);

            if (intent.Action.Equals(Constants.ACTION_START_SERVICE))
            {
                RegisterForegroundService();
                data_idx  = 1;
                isRunning = true;
                var startTicks = (int)(DateTime.Now.Ticks >> 23); // retain bits 23 to 55
                var mStartDate = DateTimeOffset.Now;
                mSensorData = new MotionSensorData
                {
                    StartTicks = startTicks,
                    StartDate  = mStartDate
                };
                mSensorManager?.RegisterListener(this, mAccel, SensorDelay.Ui);
                mSensorManager?.RegisterListener(this, mMagn, SensorDelay.Ui);
                wklock.Acquire();

                List <ActivityTransition> transitions = InitActivityTransitions();
                ActivityTransitionRequest request     = new ActivityTransitionRequest(transitions);

                pendingIntent = PendingIntent.GetBroadcast(context, 0, new Intent("GSM_TRANSITIONS_RECEIVER_ACTION"), PendingIntentFlags.UpdateCurrent);

                mGoogleActivityReceiver = new GoogleActivityReceiver();
                LocalBroadcastManager.GetInstance(context).RegisterReceiver(mGoogleActivityReceiver, new IntentFilter("GSM_TRANSITIONS_RECEIVER_ACTION"));

                var task = ActivityRecognition.GetClient(context).RequestActivityTransitionUpdates(request, pendingIntent);
                task.AddOnSuccessListener(new OnSuccessListener());
                task.AddOnFailureListener(new OnFailureListener());
            }
            else if (intent.Action.Equals(Constants.ACTION_STOP_SERVICE))
            {
                StopForeground(true);
                StopSelf();
            }
            return(StartCommandResult.Sticky);
        }
コード例 #5
0
        //<uses-permission android:name="com.google.android.gms.permission.ACITIVITY_RECOGNITION" />
        public IObservable <MotionActivityEvent> WhenActivityChanged() => Observable.Create <MotionActivityEvent>(async ob =>
        {
            var client1 = await new GoogleApiClient.Builder(Application.Context)
                          //.AddApi(Awareness)
                          .AddConnectionCallbacks(() =>
            {
                //Connected Successful
            })
                          .BuildAndConnectAsync((i) => { });

            //SnapshotClient.GetDetectedActivityAsync()
            //var request = new ActivityTransition.Builder();
            //new ActivityTransitionRequest();
            //new ActivityTransition.Builder();
            //new Awareness().api.GetDetectedActivityAsync(null).Result.Status.HasResolution;
            var client = ActivityRecognition.GetClient(Application.Context);

            var task = client.RequestActivityUpdates(0, null);
            task.AddOnSuccessListener(this);
            task.AddOnFailureListener(this);

            return(() => { });
        });