29. onMessageReceiveの実装例
@Override
public void onMessageReceived(MessageEvent messageEvent) {
Log.d(TAG, "onMessageReceived: " + messageEvent);
!
// Check to see if the message is to start an activity
if (messageEvent.getPath().equals(START_ACTIVITY_PATH)) {
Intent startIntent = new Intent(this, MainWearActivity.class);
startIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(startIntent);
}
}
MessageEventに登録したPathで
判断するのがいいみたい。
30. 僕がミスった例
リスナーの解除しわすれをしていたため、同じMessage
が何度も飛んできた。
アプリを再起動しても解除されないので???な状況に
07-11 10:54:57.962 5509-5672/com.wearTest.message D/DEVELOPER﹕ ......Wear: successfully received phone to wear communication!
07-11 10:54:57.962 5509-5610/com.wearTest.message D/DEVELOPER﹕ ......Wear: successfully received phone to wear communication!
07-11 10:54:57.962 5509-5660/com.wearTest.message D/DEVELOPER﹕ ......Wear: successfully received phone to wear communication!
07-11 10:54:57.962 5509-5521/com.wearTest.message D/DEVELOPER﹕ ......Wear: successfully received phone to wear communication!
07-11 10:54:57.962 5509-5539/com.wearTest.message D/DEVELOPER﹕ ......Wear: successfully received phone to wear communication!
07-11 10:54:57.972 5509-5570/com.wearTest.message D/DEVELOPER﹕ ......Wear: successfully received phone to wear communication!
07-11 10:54:57.972 5509-5604/com.wearTest.message D/DEVELOPER﹕ ......Wear: successfully received phone to wear communication!
07-11 10:54:57.972 5509-5601/com.wearTest.message D/DEVELOPER﹕ ......Wear: successfully received phone to wear communication!
07-11 10:54:57.972 5509-5566/com.wearTest.message D/DEVELOPER﹕ ......Wear: successfully received phone to wear communication!
07-11 10:54:57.972 5509-5520/com.wearTest.message D/DEVELOPER﹕ ......Wear: successfully received phone to wear communication!
07-11 10:54:57.972 5509-5582/com.wearTest.message D/DEVELOPER﹕ ......Wear: successfully received phone to wear communication!
07-11 10:54:57.972 5509-5567/com.wearTest.message D/DEVELOPER﹕ ......Wear: successfully received phone to wear communication!
07-11 10:54:57.982 5509-5587/com.wearTest.message D/DEVELOPER﹕ ......Wear: successfully received phone to wear communication!
07-11 10:54:58.002 5509-5581/com.wearTest.message D/DEVELOPER﹕ ......Wear: successfully received phone to wear communication!
07-11 10:54:58.052 5509-5581/com.wearTest.message D/DEVELOPER﹕ ......Wear: successfully received phone to wear communication!
07-11 10:54:58.052 5509-5587/com.wearTest.message D/DEVELOPER﹕ ......Wear: successfully received phone to wear communication!
07-11 10:54:58.062 5509-5570/com.wearTest.message D/DEVELOPER﹕ ......Wear: successfully received phone to wear communication!
http://stackoverflow.com/questions/24702402/android-mobile-wear-
app-onmessagereceived-called-multiple-times-for-one-message
Stackoverflowにも事例あり
39. 僕がミスった例
07-15 19:16:10.185 9549-9569/? D/MainActivity﹕ onDataChanged:
com.google.android.gms.wearable.DataEventBuffer@191106b8
07-15 19:16:10.186 9549-9569/? D/MainActivity﹕ request path:/action-add
07-15 19:16:10.203 9549-9569/? W/Binder﹕ Caught a RuntimeException from the binder stub implementation.
java.lang.SecurityException: Permission Denial: reading
com.kayosystem.android.easystopwatch.RecordContentProvider uri content://com.kayosystem.android.easystopwatch/
tb_recordlog from pid=0, uid=10009 requires the provider be exported, or grantUriPermission()
at android.content.ContentProvider.enforceReadPermissionInner(ContentProvider.java:498)
at android.content.ContentProvider$Transport.enforceReadPermission(ContentProvider.java:425)
at android.content.ContentProvider$Transport.query(ContentProvider.java:195)
at android.content.ContentResolver.query(ContentResolver.java:466)
at android.content.ContentResolver.query(ContentResolver.java:410)
at com.kayosystem.android.easystopwatch.MainActivity.registerdCheck(MainActivity.java:326)
at com.kayosystem.android.easystopwatch.MainActivity.onDataChanged(MainActivity.java:211)
at com.google.android.gms.wearable.internal.av.d(Unknown Source)
at com.google.android.gms.wearable.internal.ac$a.onTransact(Unknown Source)
at android.os.Binder.execTransact(Binder.java:404)
07
Wear側からDataLayerを使って変更を通知し、Mobile側
でContentProviderでデータ・アクセスしたら落ちた。
OnDataChangeはWearのプロセスIDからの実行になっている。
処理の前に
long token =Binder.clearCallingIdentity()をよび、処理がおわっ
たら、Binder.restoreCallingIdentity(token)を呼ぶ。
あるいは、runOnUiThreadでも回避できた。
50. PackageManagerの
hasFeatureの結果(LGG)
android.hardware.camera.flash not supported.
android.hardware.camera.front not supported.
android.hardware.consumerir not supported.
android.software.device_admin not supported.
android.hardware.faketouch supported.
android.hardware.faketouch.multitouch.distinct not supported.
android.hardware.faketouch.multitouch.jazzhand not supported.
android.software.home_screen supported.
android.software.input_methods not supported.
51. PackageManagerの
hasFeatureの結果(LGG)
android.software.leanback not supported.
android.software.leanback_only not supported.
android.software.live_wallpaper not supported.
android.hardware.location supported.
android.hardware.location.gps not supported.
android.hardware.location.network not supported.
android.hardware.microphone supported.
android.hardware.nfc not supported.
android.hardware.nfc.hce not supported.
android.hardware.nfc.hce not supported.
52. PackageManagerの
hasFeatureの結果(LGG)
android.software.print not supported.
android.hardware.screen.landscape not supported.
android.hardware.screen.portrait supported.
android.hardware.sensor.accelerometer supported.
android.hardware.sensor.barometer not supported.
android.hardware.sensor.compass supported.
android.hardware.sensor.gyroscope supported.
android.hardware.sensor.heartrate not supported.
android.hardware.sensor.light not supported.
53. PackageManagerの
hasFeatureの結果(LGG)
android.hardware.sensor.proximity not supported.
android.hardware.sensor.stepcounter supported.
android.hardware.sensor.stepdetector supported.
android.software.sip not supported.
android.software.sip.voip not supported.
android.hardware.telephony not supported.
android.hardware.telephony.cdma not supported.
android.hardware.telephony.gsm not supported.
android.hardware.type.television not supported.
android.hardware.touchscreen supported.