/* You don't need it if you don't use Google fit API To use the Google Fit for Android, you need an OAuth 2.0 client ID for Android applications. Follow the link (OAuth 2.0) to obtain the OAuth 2.0 client ID.
*/
I use Android Studio to develop Android wear. I use LG G Watch R for android wear.
Create New Project:
And click "next" -> select "Empty Activity" -> "Next"->"Next" -> select "Always On Wear Activity"-> "Next" -> "Finish"
And Permissions in AndroidManifest.xml under mobile and in AndroidManifest.xml under wear like:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.lee.helloworld"> <uses-permission android:name="android.permission.INTERNET" /> <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /> <uses-permission android:name="android.permission.BODY_SENSORS" /> <uses-permission android:name="android.permission.BLUETOOTH" /> <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" /> <uses-permission android:name="android.permission.WAKE_LOCK" /> <application
In build.gradle (Module:mobile, Module:wear) add :// you don't need it if you don't use Google fit API
compile 'com.google.android.gms:play-services-fitness:9.8.0'
My LG G Watch R's android version is 2.0.0. You can check on your android wear device by( setting -> System -> About -> version) So, I set the compile like:
compile 'com.google.android.support:wearable:2.0.0'
*If there is error in the line, plz click (Alt+ Enter) and select "Disable Inspection" *
In build.gradle(Project: Helloworld), add maven :
allprojects {
repositories {
jcenter()
maven {
url "https://maven.google.com" }
}
}
Now, we are ready to program our Android wear APP.
In this poster, I only make codes in the "MainActivity" under "wear".
SensorManager mSensorManager;
@Override protected void onCreate(Bundle savedInstanceState) {//Default Code super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); setAmbientEnabled(); mContainerView = (BoxInsetLayout) findViewById(R.id.container); mTextView = (TextView) findViewById(R.id.text); mClockView = (TextView) findViewById(R.id.clock);// Get the Sensor Service using SensorManager mSensorManager = ((SensorManager) getSystemService(SENSOR_SERVICE));//Get Sensor List List<Sensor> sensorList = mSensorManager.getSensorList(Sensor.TYPE_ALL); // Check Sensor list and display in TextView on your android wear.for(Sensor s: sensorList){ mTextView.setText(mTextView.getText()+s.getName()); }
And, click "Run" or Shift+F10 for running your app on Android Wear.
Thank you for reading my post. Hopefully, you found that helpful.







No comments:
Post a Comment