はじめに
これまで3回に渡ってnRF51822ブランクモジュールをARM mbed 対応機器にするための方法について掲載してきましたが、今回から mbedによるBLEプログラミング実践編をスタートいたします。
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
if (mLiveCard == null) {
Log.d(TAG, "Publishing LiveCard");
mLiveCard = mTimelineManager.createLiveCard(LIVE_CARD_TAG);
// Keep track of the callback to remove it before unpublishing.
mCallback = new ChronometerDrawer(this);
mLiveCard.setDirectRenderingEnabled(true).getSurfaceHolder().addCallback(mCallback);
Intent menuIntent = new Intent(this, MenuActivity.class);
menuIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
mLiveCard.setAction(PendingIntent.getActivity(this, 0, menuIntent, 0));
mLiveCard.publish(PublishMode.REVEAL);
Log.d(TAG, "Done publishing LiveCard");
} else {
// TODO(alainv): Jump to the LiveCard when API is available.
}
return START_STICKY;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
if (mLiveCard == null) {
mLiveCard = new LiveCard(this, LIVE_CARD_TAG);
// Keep track of the callback to remove it before unpublishing.
mCallback = new ChronometerDrawer(this);
mLiveCard.setDirectRenderingEnabled(true).getSurfaceHolder().addCallback(mCallback);
Intent menuIntent = new Intent(this, MenuActivity.class);
menuIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
mLiveCard.setAction(PendingIntent.getActivity(this, 0, menuIntent, 0));
mLiveCard.attach(this);
mLiveCard.publish(PublishMode.REVEAL);
} else {
mLiveCard.navigate();
}
return START_STICKY;
}
<uses-permission android:name="com.google.android.glass.permission.DEVELOPMENT" />
@Override
public void onResume() {
super.onResume();
openOptionsMenu();
}
@Override
public void onAttachedToWindow() {
super.onAttachedToWindow();
openOptionsMenu();
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
if (mLiveCard == null) {
Log.d(TAG, "Publishing LiveCard");
mLiveCard = mTimelineManager.createLiveCard(LIVE_CARD_TAG);
// Keep track of the callback to remove it before unpublishing.
mCallback = new ChronometerDrawer(this);
mLiveCard.setDirectRenderingEnabled(true).getSurfaceHolder().addCallback(mCallback);
Intent menuIntent = new Intent(this, MenuActivity.class);
menuIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
mLiveCard.setAction(PendingIntent.getActivity(this, 0, menuIntent, 0));
mLiveCard.publish(PublishMode.REVEAL);
Log.d(TAG, "Done publishing LiveCard");
} else {
// TODO(alainv): Jump to the LiveCard when API is available.
}
return START_STICKY;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
if (mLiveCard == null) {
mLiveCard = new LiveCard(this, LIVE_CARD_TAG);
// Keep track of the callback to remove it before unpublishing.
mCallback = new ChronometerDrawer(this);
mLiveCard.setDirectRenderingEnabled(true).getSurfaceHolder().addCallback(mCallback);
Intent menuIntent = new Intent(this, MenuActivity.class);
menuIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
mLiveCard.setAction(PendingIntent.getActivity(this, 0, menuIntent, 0));
mLiveCard.attach(this);
mLiveCard.publish(PublishMode.REVEAL);
} else {
mLiveCard.navigate();
}
return START_STICKY;
}
<uses-permission android:name="com.google.android.glass.permission.DEVELOPMENT" />
@Override
public void onResume() {
super.onResume();
openOptionsMenu();
}
@Override
public void onAttachedToWindow() {
super.onAttachedToWindow();
openOptionsMenu();
}
public class HelloService extends Service {
@Override
public IBinder onBind(Intent arg0) {
return null;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Intent aIntent = new Intent();
aIntent.setClassName("com.example.helloactivity","com.example.helloactivity.MainActivity");
aIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(aIntent);
return START_STICKY;
}
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.helloactivity"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="15"
android:targetSdkVersion="15" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:icon="@drawable/ic_launcher"
android:name="com.example.helloactivity.MainActivity"
android:label="@string/app_name" >
</activity>
<service
android:name="com.example.helloactivity.HelloService"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="com.google.android.glass.action.VOICE_TRIGGER" />
</intent-filter>
<meta-data
android:name="com.google.android.glass.VoiceTrigger"
android:resource="@xml/voice_trigger_start" />
</service>
</application>
</manifest>
<intent-filter>
<action android:name="com.google.android.glass.action.VOICE_TRIGGER" />
</intent-filter>
<meta-data
android:name="com.google.android.glass.VoiceTrigger"
android:resource="@xml/voice_trigger_start" />
public class HelloService extends Service {
@Override
public IBinder onBind(Intent arg0) {
return null;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Intent aIntent = new Intent();
aIntent.setClassName("com.example.helloactivity","com.example.helloactivity.MainActivity");
aIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(aIntent);
return START_STICKY;
}
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.helloactivity"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="15"
android:targetSdkVersion="15" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:icon="@drawable/ic_launcher"
android:name="com.example.helloactivity.MainActivity"
android:label="@string/app_name" >
</activity>
<service
android:name="com.example.helloactivity.HelloService"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="com.google.android.glass.action.VOICE_TRIGGER" />
</intent-filter>
<meta-data
android:name="com.google.android.glass.VoiceTrigger"
android:resource="@xml/voice_trigger_start" />
</service>
</application>
</manifest>
<intent-filter>
<action android:name="com.google.android.glass.action.VOICE_TRIGGER" />
</intent-filter>
<meta-data
android:name="com.google.android.glass.VoiceTrigger"
android:resource="@xml/voice_trigger_start" />
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.google.android.glass.sample.timer"
android:versionCode="2"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="15"
android:targetSdkVersion="15" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_timer"
android:label="@string/app_name" >
<activity
android:name="com.google.android.glass.sample.timer.MenuActivity"
android:label="@string/app_name"
android:theme="@style/MenuTheme"
android:enabled="true" >
</activity>
<activity
android:name="com.google.android.glass.sample.timer.SetTimerActivity"
android:label="@string/app_name"
android:enabled="true" >
</activity>
<activity
android:name="com.google.android.glass.sample.timer.SelectValueActivity"
android:label="@string/app_name"
android:enabled="true" >
</activity>
<service
android:name="com.google.android.glass.sample.timer.TimerService"
android:icon="@drawable/ic_timer"
android:label="@string/app_name"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="com.google.android.glass.action.VOICE_TRIGGER" />
</intent-filter>
<meta-data
android:name="com.google.android.glass.VoiceTrigger"
android:resource="@xml/voice_trigger_start" />
</service>
</application>
</manifest>
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
if (mLiveCard == null) {
//LiveCardを生成したい
mLiveCard = mTimelineManager.createLiveCard(LIVE_CARD_TAG);
//レンダリング用Drawerを追加したい
mLiveCard.setDirectRenderingEnabled(true).getSurfaceHolder().addCallback(mTimerDrawer);
//Menu用Activityの生成と追加をしたい
Intent menuIntent = new Intent(this, MenuActivity.class);
menuIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
mLiveCard.setAction(PendingIntent.getActivity(this, 0, menuIntent, 0));
//LiveCardを表示したい
mLiveCard.publish(PublishMode.REVEAL);
} else {
// TODO(alainv): Jump to the LiveCard when API is available.
}
return START_STICKY;
}
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.google.android.glass.sample.timer"
android:versionCode="2"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="15"
android:targetSdkVersion="15" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_timer"
android:label="@string/app_name" >
<activity
android:name="com.google.android.glass.sample.timer.MenuActivity"
android:label="@string/app_name"
android:theme="@style/MenuTheme"
android:enabled="true" >
</activity>
<activity
android:name="com.google.android.glass.sample.timer.SetTimerActivity"
android:label="@string/app_name"
android:enabled="true" >
</activity>
<activity
android:name="com.google.android.glass.sample.timer.SelectValueActivity"
android:label="@string/app_name"
android:enabled="true" >
</activity>
<service
android:name="com.google.android.glass.sample.timer.TimerService"
android:icon="@drawable/ic_timer"
android:label="@string/app_name"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="com.google.android.glass.action.VOICE_TRIGGER" />
</intent-filter>
<meta-data
android:name="com.google.android.glass.VoiceTrigger"
android:resource="@xml/voice_trigger_start" />
</service>
</application>
</manifest>
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
if (mLiveCard == null) {
//LiveCardを生成したい
mLiveCard = mTimelineManager.createLiveCard(LIVE_CARD_TAG);
//レンダリング用Drawerを追加したい
mLiveCard.setDirectRenderingEnabled(true).getSurfaceHolder().addCallback(mTimerDrawer);
//Menu用Activityの生成と追加をしたい
Intent menuIntent = new Intent(this, MenuActivity.class);
menuIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
mLiveCard.setAction(PendingIntent.getActivity(this, 0, menuIntent, 0));
//LiveCardを表示したい
mLiveCard.publish(PublishMode.REVEAL);
} else {
// TODO(alainv): Jump to the LiveCard when API is available.
}
return START_STICKY;
}
Android KitKat Hacks プロが教えるテクニック & ツール
株式会社ブリリアントサービス 著
NFC Hacks プロが教えるテクニック&ツール
株式会社ブリリアントサービス 著
Androidプログラミングの教科書
藤田 竜史、要 徳幸、住友 孝郎、日高 正博、小林 慎治、木村 尭海 著
入門Androidアプリケーションテスト
瀬戸 直喜/株式会社ブリリアントサービス 著
実践スマートフォンアプリケーション開発
株式会社ブリリアントサービス、八木 俊広、原 昇平、かわかみ ひろき 著
ジオモバイルプログラミング
郷田まり子/宅間俊志/近藤昭雄 著
ANDROID HACKS プロが教えるテクニック&ツール
株式会社ブリリアントサービス 著