https://mbientlab.com/androiddocs/latest/project_setup.htm
Create an Empty project in Android Studio.
And setting three files (AndroidManifest.xml, build.grade(project:) and build.grade(Module:app))
AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.lee.mbinetsensor"> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:roundIcon="@mipmap/ic_launcher_round" android:supportsRtl="true" android:theme="@style/AppTheme"> <service android:name="com.mbientlab.metawear.android.BtleService" /> <activity android:name=".MainActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> </application> </manifest>
build.grade(project:)
buildscript { repositories { jcenter() } dependencies { classpath 'com.android.tools.build:gradle:2.3.3' // NOTE: Do not place your application dependencies here; they belong // in the individual module build.gradle files } } allprojects { repositories { jcenter() ivy { url "https://mbientlab.com/releases/ivyrep" layout "gradle" } } } task clean(type: Delete) { delete rootProject.buildDir }build.grade(Module:app)apply plugin: 'com.android.application' android { compileSdkVersion 26 buildToolsVersion "26.0.1" defaultConfig { applicationId "com.example.lee.mbinetsensor" minSdkVersion 19 targetSdkVersion 26 versionCode 1 versionName "1.0" testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" } buildTypes { release { minifyEnabled false proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' } } } dependencies { compile fileTree(dir: 'libs', include: ['*.jar']) androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { exclude group: 'com.android.support', module: 'support-annotations' }) compile 'com.android.support:appcompat-v7:26.+' compile 'com.android.support.constraint:constraint-layout:1.0.2' testCompile 'junit:junit:4.12' compile 'com.mbientlab:metawear:3.2.2'}Now, we can start own programming in MainActivity.java.package com.example.lee.mbinetsensor; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.content.ServiceConnection; import android.os.Bundle; import android.os.IBinder; import android.support.v7.app.AppCompatActivity; import android.util.Log; import com.mbientlab.metawear.android.BtleService; import com.mbientlab.metawear.module.Accelerometer; public class MainActivity extends AppCompatActivity implements ServiceConnection { private BtleService.LocalBinder serviceBinder; private Accelerometer accelerometer; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); ///< Bind the service when the activity is created getApplicationContext().bindService(new Intent(this, BtleService.class), this, Context.BIND_AUTO_CREATE); } @Override public void onDestroy() { super.onDestroy(); ///< Unbind the service when the activity is destroyed getApplicationContext().unbindService(this); } @Override public void onServiceConnected(ComponentName name, IBinder service) { ///< Typecast the binder to the service's LocalBinder class serviceBinder = (BtleService.LocalBinder) service; Log.i("Sensor","service connected"); } @Override public void onServiceDisconnected(ComponentName componentName) { } }







No comments:
Post a Comment