In the start module, search for TODO: Add activity recognition and boot complete permissions in the AndroidManifest.xml and add the following code to the element.Implementation ':play-services-location:18.0.0' TODO: Review play services library required for activity recognition. Just review the declared dependency we require. Search for the TODO: Review play services library required for activity recognition in the adle file for the start module.To use the Sleep API in your app, you must declare a dependency to the Google Location and Activity Recognition API and specify the .permission.ACTIVITY_RECOGNITION permission in the app manifest. In the next section, we'll review the required library and permissions.ģ. We haven't actually added any code to track sleep yet, that will be in the coming sections. On your device, you should see the application: In the toolbar, select the start configuration from the drop-down selector, select your device, and then click the green triangle (Run) button next to it:.Connect your Android device to your computer.BootReceiver.kt: Re-registers to the Sleep API when device boot is complete, in order to continue listening to Sleep API events.SleepReceiver.kt: Extracts sleep events from the API and stores them to the database.MainActivity.kt: Render the app main screen when the user launches the app. The complete module can be used for checking your work, or for you to reference if you encounter any issues. In other words, you'll add code from each step to start. We'll be using the start module, which is the starting point for this codelab. In addition, if you get a prompt saying "Reload for language changes to take effect?" or something similar, select "Yes." Understand the starter projectĪll right, you're set up and ready to add activity recognition. This will allow Android Studio to pull in all the necessary components. We recommend that you wait until this has finished before making code changes. During this time you will see a spinner in the status bar at the bottom of Android Studio: Please note that Android Studio might take several seconds to compile the project in the background for the first time. There are two folder icons ( start and complete). (If you are in the Project view, you will need to expand the project to see the same thing.) In the upper-left corner of the project window, you should see something like the following image if you are in the Android view. (You won't be pushing any changes back to the Git repo.) You can click " Ignore" or the " X" in the upper right. Start Android Studio, and select "Open an existing Android Studio project" from the Welcome screen and open the project directory.Īfter the project has loaded, you may also see an alert that Git isn't tracking all your local changes. Then you can simply run the following command to clone the project. If it's not installed, follow these instructions to install it. Check whether you have git by typing git -version in the terminal / command line. To get you started as quickly as possible, we have prepared a starter project for you to build on. A device running Android 10 (API level 29) or higher.A recent version of Android Studio with Android Build Tools v21 or higher.Retrieve the API events and display on the UI. In this codelab, you're going to build an Android app to detect the user's sleep time.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |