To output logs in the program, use the android.util.Log class.
This class provides several static methods
Log.v(String tag, String msg);
Log.d(String tag, String msg);
Log.i(String tag, String msg);
Log.w(String tag, String msg);
Log.e(String tag, String msg);
In order to help players understand better, let us take a look at the meaning of each option: Verbose (verbose mode), Debug (debug mode), Info (information mode), Warning (warning mode), Error ( error mode).
tag is a string used for identification, usually composed of class name and method name. It plays an important role when viewing logs and can be used as a filter to locate specific log information.
After the program is run, no information will be output in the IDE console.
If you want to view the log later, please use
adb logcat
For more information about adb, please check the official website.
After executing the adb logcat command, all log information will be displayed in real time in tail mode.
Now we need to filter the information and only display the information we need. At this time, the specified tag is very useful.
adb logcat -s MyAndroid:I
Now, only log information with the label "MyAndroid" and level I or higher (including Warning and Error) will be displayed.
The sample code is as follows:
If no filtering rules are specified in the command line, the filtering rules will be set from ANDROID_LOG_TAG.
In order to help players who have not passed the level yet, let us learn about the specific puzzle solving methods. If no clues are found in the game, the default filter is "*:I".
If the -v parameter is not specified, the log format will be set according to ANDROID_PRINTF_LOG.
or defaults to "brief"
Android2.3.3 represents other versions of the SDK version number 2.3, similar to 2.3.5.
There is also Android 2.2.x or above, which means that the compatible version of the program is
2.2 and above version
for example:
We start by creating a new Android project, named HelloAndroid, and select Android 2.2 version. Fill in 8 in minSdkVersion and click Finish.
Now, let’s run HelloAndroid, which will start a version 2.2 emulator.
3. If we now modify android:minSdkVersion=7 in the AndroidManifest.xml file and run it again, it will run on the 2.2 emulator we have opened. Because the Android API is backward compatible, when the system is compiled, this Project is compiled using the 2.1 version, but it can also be run on the 2.2 emulator; if we first close the 2.2 emulator, then run the HelloAndroid Project If so, then a new simulator with API Level=7 will be created to run this program (that is, the 2.1 simulator).
If we modify android:minSdkVersion=10, no matter whether the 2.2 version of the simulator is opened or not, an error will occur.
To help those who encounter the "ERROR: Application requires API version 10. Device API version is 8 (Android 2.2)." problem, I will share some solutions. First of all, this error means that your device's Android version is too low and needs to be upgraded to API version 10 to run the app. You can try the following methods to solve the problem: 1. Check whether the device can be upgraded to a higher Android version. 2. If the device cannot be upgraded, try to find a lower version of the application that matches your device. 3. If the application is developed by yourself, you can try to adjust the API version requirements to suit your
Launch canceled!
When we develop android programs in eclipse, we often need to look at the source code (maybe out of curiosity, maybe out of habit of reading source code), so how to check the Android source code?
For example, the following situation
If we want to view the source code of the Activity class, usually pressing the Ctrl key and left-clicking the class should be able to display the code. But sometimes we may encounter a prompt that the Activity.class file cannot be found. This may be caused by project configuration issues or incorrect IDE settings. To solve this problem, you can try to re-import the project or check the IDE settings to ensure that the relevant class files can be loaded correctly.
At this point, click the button below, find the "Change Attached Source..." option, and then select the location of the android source code. In this way, a dialog box similar to Figure 3 will pop up.
The first is to select the working directory, which is the existing android application source code.
The second method is divided into two ways
In order to solve this problem, we need to follow the following steps: First, click the "External File..." button, and then select the path of the Jar format file or zip format file to be added.
(2) Select the External Floder... button and add the path to the folder.
The next question arises, where is the source code? It cannot be created out of thin air.
In order to help players who have not passed the level yet, let us learn about the specific puzzle solving methods. Source code downloading through Android SDK Manager is a recommended method, as shown in Figure 4. This can help players solve problems better.
Check Source for Android SDK and download it.
In addition, it can also be downloaded through other channels. There are many shared resources on the Internet.
Here we choose the second method (2), that is, select the directory where the source code is located, as shown in Figure 5.
After clicking the "OK" button, the Activity file will be able to view the source code, as shown in Figure 6.
This is done! ! !
The above is the detailed content of Learn how to retrieve log records from Android client software. For more information, please follow other related articles on the PHP Chinese website!