This is the 8th day of my participation in the August More Text Challenge. For details, see:August is more challenging

๐Ÿ‘‰ About the author

As we all know, life is a long process of overcoming difficulties, reflecting and moving forward. In this process, there will be a lot of questions and thinking about life, so I decided to share my own thinking, experience and story, in order to find resonance!! Focus on Android/Unity and various game development skills, as well as various resource sharing (website, tools, materials, source code, games, etc.)

๐Ÿ‘‰ Soon to learn

Understand and learn Android Wear development content, including environment building, notification synchronization, voice input, multiple notifications.

๐Ÿ‘‰ background

๐Ÿ™ˆ Xiao Kong (โŒš) : Xiao Zhi, how about my watch?

๐Ÿ™Ž Xiaozhi (๐Ÿ’—) : Yes, it’s very nice.

๐Ÿ™ˆ Xiao Kong (๐Ÿ˜Ž) : Ok, so today we will learn about the development of Wear.

๐Ÿ™Ž Xiaozhi (๐Ÿ˜ฎ) :?? Don’t you just look at the watch?

๐Ÿ‘‰ Practice Process

Development environment construction

The Android Wear development environment, like the Android development environment, is based on the Android SDK, but the official recommendation is to use Android Studio as an IDE. AndroidStudio makes it easy to create, develop, and package Android Wear apps.

The development environment needs to be built on the basis of the Android development environment, mainly starting from the following steps:

  1. Download the Android Wear SDK
  2. Create a wearables simulator
  3. Connect handheld devices and wearables emulators to the development environment
  4. Create an Android Wear project and run it

Download the Android Wear SDK

You need to use SDK Manager to download the SDK of the wearable device. Select the package to be downloaded and click download.

Note: If a later VERSION of the SDK is released, it is recommended to download the previous version of the highest version. Both guarantee the use of new technology and avoid the latest version of the problem

Creating a device Simulator

Connect handheld devices and wearables emulators to the development environment

Since Android Wear devices do not have USB ports and many functions rely on the phone, the development and debugging of the wearables must be done through the phone. The specific steps for connecting the wearable device simulator are as follows:

  1. Install Google Play on your phone. Download the Android Wear app from Google Play and install it on your phone. AndroidWear is a Google app designed to connect AndroidWear devices via Bluetooth.
  2. Connect the phone to the development environment via USB.
  3. Set the AVD’s communication port to the connected phone and reset it every time the phone is connected. Adb -d forward TCP :5601 TCP :5601.
  4. Open the AndroidWear APP on your phone and connect to the emulator on your phone.

The specific connection mode is shown in the figure below:

Note: Since Google services are not available in China, GooglePlay is not installed on most phones. To install GooglePlay, you need to install GooglePlay through the “Google installer” after the Root of your mobile phone, or install the third-party Recovery and then swipe the corresponding zip package into it. The specific operation needs to be solved by the reader, because each phone installation operation may be different. After installing GooglePlay, you need to log in to the Google server to download it. However, the Google website is blocked. You are advised to use fqroute to climb the wall and log in to GooglePlay again to download Android Wear. If you can’t find Android Wear on GooglePlay, you can download it in the domestic software market. Currently, only 360 security market can download it. Note, however, that Android Wear relies on GooglePlay, so installing just Android Wear is not an option.

If the developer has a wearable device, it can also be debugged via Bluetooth. The main steps are as follows:

  1. Turn on USB debugging on your phone
  2. Start Bluetooth debugging on the wearable device (Android Wear system interface currently does not support Chinese), click the screen, open the Wear Menu, slide to the bottom, click Settings to slide to the bottom, if there is no Developer Options, click About, Click Build Number several times to enable Developer mode, swipe right back to the previous interface, and click Developer Options to enable Debug over Bluetooth, ADB debugging
  3. Launch your phone’s AndroidWear app and tap the Settings icon in the upper right corner to open Settings
  4. If you select Debug over Bluetooth at the bottom of the Settings screen, the message Host: disconnected // The Host is disconnected Target: Connected //Android Wear isconnected
  5. The mobile phone connects to the computer through USB and executes the name ADB Forward TCP :4444 localabstract:/adb-hub ADB connect localhost:4444
  6. On the AndroidWear app, you can see that the connection status has changed to Host: connected Target: connected

Create an Android Wear project

AndroidWear apps run directly on the wearable device and have access to its sensors and gpus. These applications are developed using the Android SDK just like any other device, but there are big differences in the UI designers and the functions they use. Here are the biggest differences between wearable apps and handheld apps:

  1. Timeout duration of the system execution. If the wearable app shows an Activity and the user is not interacting with the Activity, the device goes to sleep. When the device is awakened, the wearables display the Home screen instead of the Activity screen. If you need to continuously display something, you can create a notification to display in the Context Stream.
  2. Compared with handheld apps, wearable apps have smaller packages and fewer features. They show only the main UI, a subset of the handheld apps. In general, as much as possible, the function of performing an operation should be placed on the handheld application and the result of the operation returned to the wearable application.
  3. Users can’t download the wearable app directly, but instead tie the wearable app to the handheld app. When the user installs the handheld application, the system will automatically install the wearable application to the wearable device. For development and debugging, you can install the wearable app directly.
  4. Most apis are supported for wearables. However, the following apis are not supported: Android. webKit; android.print; android.app.back; android.appwidget; android.hardware.usb;

A combined handset app that includes a wearable app also needs to be published to Googleplay. Android Wear does not support GooglePlay, so when users download a combination of handheld apps, they automatically synchronize the apps to the wearables. Handheld apps can be used to do computation-based operations, network operations, or other operations, and then return the results to the wearable app.

Just like any other Android project, run AndroidStudio and click Start a new Android Stuidio Project. This will open the wizard for creating an app. However, it should be noted that Phone and Tablet and Wear should be checked at the same time when creating, as shown in the figure:

When the creation operation is complete, AndroidStudio creates a new project containing two modules, mobile and wear, as shown in figure 24.11. The current project includes apps for wearables and handheld devices, creating activities, services, custom layouts, and so on. In handheld devices, it is used to do most of the heavy lifting, such as network communication, interprocess communication, a lot of user interaction, etc. When these operations are complete, you can use Notification or synchronize the data to the wearables.

During development, you can install the app directly to the wearables as before, using adb install or the Play button on AndroidStudio. When the project is complete and ready to release the app to users, the wearable app should be embedded into the handheld app. When a user downloads and installs an application on GooglePlay, the wearable device connected to the mobile phone will automatically install the application.

Note: Debug signature is used in common development, the wearable device application will not be automatically installed on the watch, only after the signature can be automatically installed. Click on the Studio menu Build and select Generate Signed APK… Sign.

At this point, the development environment is set up.

Digest the above content, the next section of the small space with you continue to explore.

๐Ÿ‘‰ other

๐Ÿ“ข by xiao Kong and xiao Kong in Xiao Zhi ๐Ÿ“ข. ๐Ÿ“ข Welcome to like ๐Ÿ‘ save ๐ŸŒŸ leave ๐Ÿ“