My code without the redirection to Pastebin:
NutritionFacts facts = mProduct.NutritionFacts;
DataSource source = new DataSource.Builder()
.setAppPackageName(BuildConfig.APPLICATION_ID)
.setType(DataSource.TYPE_RAW)
.setDataType(DataType.TYPE_NUTRITION)
.build();
DataPoint point = DataPoint.create(source);
point.setTimestamp(System.currentTimeMillis(), TimeUnit.MILLISECONDS);
point.getValue(Field.FIELD_FOOD_ITEM).setString(mProduct.Name);
point.getValue(Field.FIELD_MEAL_TYPE).setInt(Field.MEAL_TYPE_SNACK);
point.getValue(Field.FIELD_NUTRIENTS).setKeyValue(Field.NUTRIENT_CALORIES,
facts.KCalPerServing);
point.getValue(Field.FIELD_NUTRIENTS).setKeyValue(Field.NUTRIENT_TOTAL_FAT,
facts.FatsPerServing);
point.getValue(Field.FIELD_NUTRIENTS).setKeyValue(Field.NUTRIENT_SATURATED_FAT,
facts.SatsPerServing);
point.getValue(Field.FIELD_NUTRIENTS).setKeyValue(Field.NUTRIENT_MONOUNSATURATED_FAT,
facts.MonounsatsPerServing);
point.getValue(Field.FIELD_NUTRIENTS).setKeyValue(Field.NUTRIENT_POLYUNSATURATED_FAT,
facts.PolyunsatsPerServing);
point.getValue(Field.FIELD_NUTRIENTS).setKeyValue(Field.NUTRIENT_TOTAL_CARBS,
facts.CarbsPerServing);
point.getValue(Field.FIELD_NUTRIENTS).setKeyValue(Field.NUTRIENT_SUGAR,
facts.SugarPerServing);
/* Alcohol missing */
/* Amylum missing */
point.getValue(Field.FIELD_NUTRIENTS).setKeyValue(Field.NUTRIENT_PROTEIN,
facts.ProteinsPerServing);
point.getValue(Field.FIELD_NUTRIENTS).setKeyValue(Field.NUTRIENT_DIETARY_FIBER,
facts.RoughagePerServing);
point.getValue(Field.FIELD_NUTRIENTS).setKeyValue(Field.NUTRIENT_SODIUM,
facts.SatsPerServing * 1f / 2.5f); /* Salt = 2.5 * Sodium */
DataSet set = DataSet.create(source);
set.add(point);
Fitness.HistoryApi.insertData(mGoogleApiClient, set).await();
Am Montag, 6. Juni 2016 12:27:27 UTC+2 schrieb Christian Becker:
>
> Hi,
> unfortunately this was not this problem. I create and insert the
> DataSource/DataPoint with the following code: http://pastebin.com/WGFC2MsU
>
> Can you take a look at it and compare it with your code so that you can
> eventually identify the issue with my code?
>
> Thanks in advance,
> Christian
>
>
> Am Donnerstag, 2. Juni 2016 08:59:54 UTC+2 schrieb sanjeet kumar Singh:
>>
>> Hi,
>> Yes we found the cause for the above problem. There was one attribute
>> missing when we were setting the nutrition values to DataPoint.
>> So, in DataPoint you need to set the fields listed below (Meal type and
>> Food item):
>>
>> dataPoint.getValue(Field.FIELD_FOOD_ITEM).setString("some string");
>> dataPoint.getValue(Field.FIELD_MEAL_TYPE).setInt(Field.MEAL_TYPE_SNACK);
>>
>>
--
You received this message because you are subscribed to the Google Groups
"Android Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/android-developers.
To view this discussion on the web visit
https://groups.google.com/d/msgid/android-developers/ea136a1a-2302-4aef-b52c-7452c53403cc%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.