36 2. ANDROID SOFTWARE DEVELOPMENT TOOLS
Figure L1.12: HelloWorld.c.
int classNum = 9001;
int secNum = 1;
__android_log_print(ANDROID_LOG_ERROR, "HelloWorld",
"DSP %d.%03d", classNum, secNum);
e __android_log_print() method (two underscores at the beginning) is similar to the
printf function in C. e first two parameters are the log level and the message tag. e logging
level is the priority of the message, the list of which can be found in the android/log.h header file.
e tag is used to help identify the source of the message; in this case the name of the app. e
next parameter is the message to be logged. For the above example, the string has the specified
integer for the class number inserted, followed by the specified integer for the section number.
e same number formatting that is possible when using the printf function may also be used
here. For instance, the section number can be formatted to three characters width with leading
zeros. Variables are last and are inserted with the formatting specified in the message string in
the order they are listed.
Save the changes made to the HelloWorld.c source file and run the app again. is time,
Android Studio should automatically open the Android DDMS window and show the LogCat
screen. e message DSP 9001.001 would appear in the listing if the previous procedures were
performed properly (see Figure L1.13).