착용 가능 메시지 API를 사용하여 휴대 전화와 웨어러블간에 메시지를 보내려고합니다. 전화 (물리적 One plus plus)와 스마트 워치 (Physical Sony Smartwatch 3)는 서로 연결됩니다. 메시지를 보내면 보낸 것으로 다시보고됩니다. 그러나 Mobile이나 웨어러블 응용 프로그램의 WearableServiceListener는 이러한 메시지에 응답하지 않습니다.Android 6.1 및 Smartwatch가 WearableListenerService와 통신하지 않습니다.
는 내가 확인했다 :
이
패키지 이름
매니페스트를 애플리케이션 ID
내가 문제를 찾기 위해 다른 무엇을 확인할 수 있나요? 감사합니다.
public class MainActivityPhone extends AppCompatActivity implements GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {
private Node connectedPhone;
private static String WEAR_PATH = "/from_phone";
private final String TAG = MainActivityPhone.class.getSimpleName();
GoogleApiClient googleApiClient;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
googleApiClient = new GoogleApiClient.Builder(this)
.addConnectionCallbacks(this)
.addOnConnectionFailedListener(this)
.addApi(Wearable.API)
.build();
googleApiClient.connect();
}
public void phoneButtonHandler(View view){
sendMessage();
}
@Override
public void onConnectionSuspended(int i) {
Log.e(TAG,"connection suspended");
}
@Override
public void onConnectionFailed(ConnectionResult connectionResult) {
Log.e(TAG,"connection failed");
}
@Override
public void onConnected(Bundle bundle) {
Wearable.NodeApi.getConnectedNodes(googleApiClient)
.setResultCallback(new ResultCallbacks<NodeApi.GetConnectedNodesResult>() {
@Override
public void onSuccess(@NonNull NodeApi.GetConnectedNodesResult nodes) {
for (Node node : nodes.getNodes()) {
if (node != null && node.isNearby()) {
connectedPhone = node;
Log.i(TAG, "Connected to " + connectedPhone.getDisplayName());
}
}
}
@Override
public void onFailure(@NonNull Status status) {
if (connectedPhone == null) {
Log.i(TAG, "not connected!");
}
}
});
}
@Override
protected void onStart() {
super.onStart();
googleApiClient.connect();
}
@Override
protected void onStop() {
super.onStop();
googleApiClient.disconnect();
}
private void sendMessage(){
if(connectedPhone != null && googleApiClient != null) {
Wearable.MessageApi.sendMessage(googleApiClient, connectedPhone.getId(), WEAR_PATH, "alarm".getBytes()).setResultCallback(new ResultCallbacks<MessageApi.SendMessageResult>() {
@Override
public void onSuccess(@NonNull MessageApi.SendMessageResult sendMessageResult) {
Log.e(TAG, "message sent");
}
@Override
public void onFailure(@NonNull Status status) {
Log.e(TAG, "connection failed!" + status.getStatusMessage());
}
});
}
else{
Toast.makeText(this,"failed to send, no connection",Toast.LENGTH_SHORT).show();
}
}
입니다.
<service android:name=".ListenerFromWear">
<intent-filter>
<action android:name="com.google.android.gms.wearable.MESSAGE_RECEIVED" />
</intent-filter>
</service>
두 모듈
:android {
compileSdkVersion 24
buildToolsVersion "24.0.2"
defaultConfig {
applicationId "com.leon_wolf.bigpresenter.connectphoneandwatch"
minSdkVersion 23
targetSdkVersion 24
versionCode 1
versionName "1.0"