title: GoogleFit distinguish data between from different devices
body: <p>I am using <a href="https://developers.google.com/fit/android/history" rel="noreferrer">GoogleFit HistoryAPI</a> for get step data from user. It's working well.<br />
  However, in my case,  I want to distinguish data between from different devices (using same account) because I don't want user using same account for 2 or more devices (it is a game base on step so I don't want user play on 1 device and have achievement on many devices).</p>
  <p>I found that <a href="https://developers.google.com/android/reference/com/google/android/gms/fitness/data/Device" rel="noreferrer">Device</a> from <a href="https://developers.google.com/android/reference/com/google/android/gms/fitness/data/DataSource.html#getDevice()" rel="noreferrer">DataSource#getDevice</a>, <a href="https://developers.google.com/android/reference/com/google/android/gms/fitness/data/Device.html#getLocalDevice(android.content.Context)" rel="noreferrer">Device#getLocalDevice</a> can help me distinguish data between from different devices.  Below is info from official docs:</p>
  <blockquote>
  <p>To get information about the device for a data source, use the DataSource.getDevice method. The device information is useful to distinguish from similar sensors on different devices, show the device information from a sensor to the user, or process data differently depending on the device. For example, you may be interested in reading data specifically from the a sensor on a wearable device but not from the same type of sensor on the phone.</p>
  <p>To get a Device instance for the device that is running your activity, use the Device.getLocalDevice static method. This is useful when you want to check if a data source is on the same device that your app is running on.</p>
  </blockquote>
  <p>So,</p>
  <pre><code>// My idea is comparing the uid of local device and uid of device in datasource
  // if it is same =&gt; step come from THIS device
  // if not =&gt; step come from OTHER device
  private void dumpDataSet(DataSet dataSet) {
      for (DataPoint dp : dataSet.getDataPoints()) {
          Log.i(Constant.TAG, &quot;Origin type uid: &quot; + dp.getOriginalDataSource().getDevice().getUid());
          Log.i(Constant.TAG, &quot;Local device uid: &quot; + Device.getLocalDevice(getApplicationContext()).getUid());
  
          ... 
       }
  }
  </code></pre>
  <p>However, the logcat result for datasource from only <strong>1 DEVICE</strong> is</p>
  <pre><code>Origin type uid: 9ff67c48
  Local device uid: f2b01c49ecd9c389
  // Only the model, manufacturer is same (but I can not use 2 fields because user can use 2 devices with same model, manufacturer)
  </code></pre>
  <p>You can see that the <code>uid</code> from <code>datasource</code> is different to <code>local device uid</code>, so I <strong>can not</strong> distinguish data.</p>
  <p>Is there any way to distinguish data between from different devices? Any help or suggestion would be great appreciated.</p>
  <p><a href="https://github.com/PhanVanLinh/AndroidGoogleFit" rel="noreferrer">DEMO project</a></p>