Data | FoodNote

The SDK’s Health Data provides a 'FoodNote' sample application to show how to manage food intake data with Samsung Health including the permission request. Check the sample application by importing its project with Android Studio (or Eclipse).

Prerequisites

Prerequisites to run FoodNote are:

  • Prepare an Android device that supports Android 4.4KitKat (API level 19) or above.
    (Samsung and non-Samsung devices are available both.)

  • Install the latest Samsung Health.

  • Turn on the developer mode.

  • Import FoodNote with Android Studio (or Eclipse).

  • Run FoodNote on the device.

Overview

FoodNote demonstrates how to use Health Data’s APIs for checking the selected day’s calorie intake with HealthConstants.FoodIntake and HealthConstants.FoodInfo including permission request.
Figure 18 shows its screenshots.

Figure 18: FoodNote sample app

Especially, the health data store connection and exception handling would be helpful to your application to prepare unexpected error.

Table 10 describes source and resource files of FoodNote.

Source / Resource Description
AndroidManifest.xml Declaring required permissions with the <meta-data> element.
src/com/samsung/android/foodnote
AppConstants.java Getting the meal type name.
ChooseFoodActivity.java Loading the food list of the FoodInfoTable class and showing them that the user can choose.
FoodDataHelper.java
  • Inserting food intake data
  • Deleting food intake data
  • Reading food intake data of the selected day and the meal type
FoodInfoTable.java Defining sample food information.
MainActivity.java FoodNote's main activity
  • Connecting to the health data store and handling exceptions through ConnectionListener.
  • Checking permission for HealthConstants.FoodInfo and HealthConstants.FoodIntake, and requesting permission if required.
  • Creating an option menu for setting permission.
  • Showing the selected day’s calorie intake.
  • Adding an observer to get notification for the calories change.
MealStoreActivity.java
  • Showing a list of food intake items for the selected meal that is chosen on MainActivity.
  • Deleting a food intake item in the list.
Table 9: FoodNote’s source description