How to develop Android Wear app

Source: Internet
Author: User
Tags home screen android sdk manager

Android Wear is a platform for connecting Android phones to wearable products. Since its release in the first half of this year, Android Wear has received a lot of attention, both from consumers and from developers, who want their applications ready to allow users to interact with information in a new way.

This article will briefly introduce Android Wear and then introduce the platform for developers.

Android Wear is designed to provide users with the right amount of information at the right time. According to this theme, Google has published design principles to help developers focus on Android Wear applications. We'll take a brief look at this, as well as explore the requirements for application development in an Android Wear environment and how to use the available APIs to help Android developers develop applications for Android Wear platforms.

Android Wear Platform

Android Wear is an open operating system for wearables, and it has a new user interface--this is the result of Google's understanding of how we use our phones and how we can interact more with the environment. For example, data shows that we use mobile phones to view information on average about 150 times a day. Every time we do this, it is possible to get lost in other applications, often consuming a lot of unnecessary time in a task program, and sometimes even forgetting the most important information we have to query.

The first batch of Android Wear hot up is Samsung Gear Live and LG G Watch, the two devices were released at the June Google I/O conference. The watch is the first choice target for Android Wear, which is true: most people use watches every day. These so-called smart watches usually need to be paired with an Android phone, and Google allows users to see the Android Wear platform's usefulness by seamlessly cooperating with the latest Android phones.

In fact, when you start using Android Wear, you need to do the following:

1. android 4.3 device;

2. Android Wear app from Google app market;

3. Pair the Android mobile device with the wear device.

Yes, that's it. As long as you do this, most of the information on your phone can be viewed on a wearable device. You can not only view this information on your watch, but also interact with it, delete it, and so on. This shows that the Android app and the paired device can be run without any effort or with little time--Android phone users can do that.

It is important to note that mobile phones and wearables are connected via Bluetooth. Wearable devices are not currently able to access the network independently, so they need to be connected via a mobile phone.

Although Android Wear is very flexible, it is now most concerned with the watch class.

At the beginning of September, Motorola released the most anticipated smart watch Moto360. It uses an Android Wear system. Thanks to its beautiful design, Moto 360 received great acclaim, and the $250 price was well received by consumers. Other developers, including Asus, have announced plans to release Android Wear smart watches.

Usage patterns

The two main ways to interact with Android Wear devices are "recommendations" and "requirements."

"Recommended", as the name implies, is a timely and useful information that is pushed to the Android Wear device in the form of notifications. The user interface sets this to the form of a card, as shown in.

It is important to note that the wear application recognizes contextual contexts, so it pushes only the information within the text. This type of notification is timely, short, and with minimal interaction with the user.

As for the "demand" usage mode, the user sends a signal to the wearable device via voice and it responds to the message. The device contains a microphone that allows the user to invoke a series of standard execution actions by saying "OK, Google" or clicking on the home screen. The user interface prompts the user to say the action instructions they want to perform. Standard execution actions include "take notes", "Call" and "Send messages". You can register the standard execution instructions on the application, or you can customize the prompt text.

Design concept

Now that we understand the basic usage patterns of Android Wear, it's time to look at the user interface and design guidelines.

As shown below, much of the information presented to the user appears in the form of a card.

Take a look at the different parts of the card. Currently the Android Wear app notification will appear in the standard format above. But we're talking about the smallest amount of information that's good for reading and contextual, and you need to spend some time thinking about when to add text notifications and text that needs to be displayed.

Notifications can be displayed in single or multiple cards. If multiple cards are used, the user needs to swipe from left to right to view the page.

You can even view multiple notifications in a single card with overlays, as shown below.

When designing the Android Wear user experience, there are four key points to remember, every Google Wear design visual creative part, Android Wear app should do:

1. Auto-start: The user should not need to install the application on the wear device separately, wear device is not the phone. Android wear applications should be able to recognize time, place, and activity, and push related cards accordingly.

2. Legibility: Because the user wears the device on the wrist, reading the notification should be as easy as viewing the time of a traditional watch. Remember, pay special attention to the topic: the shorter the better-you can see the point at a glance.

3. Effective use of "recommendations" and "Requirements" mode: Android Wear developer page: "Android Wear is like an excellent personal assistant." It only stops when you don't need it at all, and it always gives you answers as you go along. "To provide this experience, developers should consider when to use the" suggest "and" demand "models.

4.0 Low interaction with the user: developing applications and programs is a need to remember that wearables are particularly small. Applications must be easy for users to interact with, meaning they can use sound or simple swipe or tap gestures.

The Android Wear design team has done a lot of work documenting how to effectively integrate design ideas when expanding in existing Android Wear applications. (See the Android Wear Design section.) )

Development details

In this section, we will help you get a basic idea of the key concepts of Android Wear development.

You can choose either Eclipse or Android studio as the Integrated development environment (IDE) for Android Wear. Google recommends using Android studio for development. Download API (4.4 KitKat Wear) via the Android SDK Manager:

Android Studio provides a convenient way to add Android Wear support or create a new project in an existing application: Android Studio uses the component model, where phones and Android Wear are part of a single project.

If you want to create a new project in Android Studio, click File-> New project. On the second page of the wizard, select the composition factor to make sure that the Android Wear module is selected as the constituent factor for your development (see).

Once all options have been selected, the project is automatically generated. You will see this Android project has two modules: mobile and wear. Mobile apps that are used in mobile phones, wear is a program that runs on Android Wear.

The wear application cannot be placed in the Google Store as a separate package. You need to put the mobile and wear apps in the same app apk. When the user downloads the apk on the phone, the Wear app is automatically uploaded to the paired wear device.

The default project generated by Android Studio is nothing special. During testing, we need to write our own code, depending on what we want the "wearable" of the application to do.

Notice

The development of Android Wear can be analyzed from two angles: notification and Android Wear application itself (included in the APK folder).

Users who have already installed the official Android Wear to the phone from the Google Store, and who have paired the phone with the wear device, do not need to make any changes to the notification in the app.

Although this is said, it is sometimes necessary to change it in order for wear to really work.

You can make notifications appear only on your phone or wearables or both. In addition, as mentioned above, developers should consider how to take advantage of the user interface (UI) advantages-the background image, notification title, text, and so on.

Create a handheld notification that will be sent to a wearable device, and Google recommends using the notification-compatible builder. The Android Support library provides a range of categories that you need to add to your project.

If you use Android Studio, you need to add the following compile time for the Build.gradle file in the Mobile module.

Compile "com.android.support:support-v4:20.0.+"

To create a notification, you can try the following code in your mobile app:

Notificationcompat.builder Builder = new Notificationcompat.builder (this);

Builder.setcontenttitle ("New API")

. Setcontenttext ("XYZ API got added to food Category")

. Setsmallicon (R.drawable.ic_mynotification)

. Setcontentintent (Phoneactivitypendingintent);

You can then trigger notifications based on your logic, as follows:

Notificationmanagercompatnotificationmanager = Notificationmanagercompat.from (this);

Notificationmanager.notify (Notificationid, Notificationbuilder.build ());

Now, when users are notified on the wear device, they can click on the notification on the phone or swipe to the left to start the wait mode and then show the start action.

As part of the extension, if you want notifications to appear only on your phone, you can create notifications by specifying setlocalonly.

In the example above, we only show a card, but you can look at the notification card with multiple pages or even folds.

Wearable apps

Although Android Wear supports notifications from mobile phones, it is sometimes not enough. There are several situations, including:

Want to start the activity on the wear device when receiving data on the phone;

Send information from the wear device to the phone, in turn perform some activities or do something in the background;

Create a custom interface on the wear device;

Write a program that can be started and run on the wear device, and can initiate different action commands by receiving voice input.

All of the above mentioned are possible, provided you understand the basics of some wear APIs.

Connectivity and data exchange

In the previous case, the common theme is that both mobile phones and wear devices require a mechanism that can be both contiguous, and then once the connection is established, mutual information is exchanged. This in turn triggers the correct instruction on the appropriate device.

The link between the mobile phone and the wearable device is provided by Google. The Google API client provides an example of this connection.
Mgoogleapiclient = new Googleapiclient.builder (context)

. ADDAPI (WEARABLE.API)

. Addconnectioncallbacks (This)

. Addonconnectionfailedlistener (This)

. build ();

You can establish or close the link in the appropriate exercise cycle, as follows:
@Override protected void OnStart () {Super.onstart ();

Mgoogleapiclient.connect ();   } @Override protected void OnStop () {super.onstop (); Mgoogleapiclient.disconnect (); }

Once you establish a connection, you can view different API examples to facilitate data transmission and synchronization between devices:

Node API: The API is used for two devices to connect or detach to keep track through the Nodelistener interface method.

Message API: The API is used for both parties to send messages to each other. This requires that the receiver (MessageListener) have a listener that can receive messages.

Data API: This API is used for synchronization between devices. The platform is responsible for providing synchronization mechanisms for both parties. You need to complete the Datalistener interface before you can receive messages. It is recommended that you create an instance on the wearable Device listener service platform and listen to events that interest you.

The data-tier interface is shown below, choosing a suitable one for you.

Tatic interface Datalistener {void ondatachanged (dataeventbufferdataevents);}

Static interface MessageListener {void onmessagereceived (messageeventmessageevent);}

Static interface Nodelistener {void onpeerconnected (node node); void onpeerdisconnected (node node);}

The rest of the functionality-the instructions that need to be taken for specific information-depends entirely on the functional needs of the application.

Execution instance

To understand the overall situation, let's look at an instance application, including mobile phones and wear components. To make things simple, the mobile app will have a separate activity instruction name--mainactivity.java. It designs a button that sends a message to the wear application when clicked.

First, let's look at the situation with Mainactivity.java on the mobile app (the Main method is as follows):

public class Mainactivity extends Activity implements Googleapiclient.connectioncallbacks,
Googleapiclient.onconnectionfailedlistener {

.....

protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.main);
Mgoogleapiclient = new Googleapiclient.builder (this)
. ADDAPI (WEARABLE.API)
. Addconnectioncallbacks (This)
. Addonconnectionfailedlistener (This)
. build ();
}

@Override
protected void OnStart () {
Super.onstart ();
Mgoogleapiclient.connect ();
}

@Override
protected void OnStop () {
Mgoogleapiclient.disconnect ();
Super.onstop ();
}

Button Click
public void Onsendmessage (view view) {
Get Connected Nodes
Collectionnodes = Getnodes ();

For each node-send the message across
for (String node:nodes) {
Sendmessageresult result = Wearable.MessageApi.sendMessage (
Mgoogleapiclient, node, "/startactivity", null). await ();
if (!result.getstatus (). Issuccess ()) {
Log Message Success
}
}
}

@Override
public void onconnectionsuspended (inti) {
LOG.E (TAG, ...);
}

@Override
public void onconnectionfailed (Connectionresultconnectionresult) {
LOG.E (TAG, ...);
}

For the receiver-the wear device, we have written a service program that expands Wearablelistenerservice. With this service, you can initialize the GOOGLEAPI client and other callback signals, such as googleapiclient.connectioncallbacks. Finally, we provide the messagereceived instance as follows:

@Override
public void onmessagereceived (messageeventmessageevent) {
if (Messageevent.getpath (). Equals ("/startactivity")) {

Intent startintent = new Intent (this, wearactivity.class);
Startintent.addflags (Intent.flag_activity_new_task);
StartActivity (startintent);
}

Custom interface and voice actions

In addition to the data api,wear provides the conditions for developers to create custom interfaces using different parts.

Today, you have unofficial repositories available.

Voice integration provides the standard function of voice input, which translates speech into text. There is also "demand" usage mode, where users can wake up applications or action commands via voice.

Wear platform system provides "note", "Send Information" and other action instructions, through which developers can let the application in the manifest file register standard active components.

Similarly, users can start an activity instruction by saying "start" activity name "" to the Wear device. All you need to do is provide a file attribute for the activity in the activity list.

For the first wearable device based on Android Wear-the smart watch, Android Wear is a great platform to create wearable apps.

Speaking of wearables applications, Google has always stressed that developers need to respect users and follow the user's desire to design. With existing applications, the difficulty of writing wearables applications is minimized. There are many applications designed for wearable devices in the App Store, including the ever-growing watch app, the user's favorite app. Considering the growing number of vendors announcing the Android Wear product program, as well as the global market share of Android OS, developers should invest more time on the platform.

How to develop Android Wear app

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.