PHP code example of mariodevv / nativephp-health-connect

1. Go to this page and download the library: Download mariodevv/nativephp-health-connect library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

mariodevv / nativephp-health-connect example snippets


use MarioDevv\HealthConnect\Facades\HealthConnect;

// 1. Ask the user. Opens the system dialog and returns immediately.
HealthConnect::requestPermissions(['steps', 'sleep']);   // default: all types

// 2. Check what was granted (poll, e.g. on page load).
HealthConnect::status();
// ['available' => true, 'granted' => ['steps', 'sleep'], 'writable' => []]

// 3. Totals (deduplicated across sources).
HealthConnect::aggregate('steps', now()->subDay(), now());
// ['type' => 'steps', 'count' => 8423]

// 4. Raw records.
HealthConnect::read('heart_rate', now()->subDay(), now());
// ['type' => 'heart_rate', 'records' => [['start' => ..., 'end' => ..., 'source' => 'com.fitbit.FitbitMobile', 'samples' => [['time' => ..., 'bpm' => 64], ...]]]]

HealthConnect::write('steps', ['count' => 1200, 'from' => now()->subMinutes(30), 'to' => now()]);
HealthConnect::write('weight', ['kg' => 72.5]);          // 'time' defaults to now
// ['type' => 'weight', 'written' => 1]