com.google.android.gms.wearable.CapabilityInfo Java Examples

The following examples show how to use com.google.android.gms.wearable.CapabilityInfo. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LoggingUtil.java    From APDE with GNU General Public License v2.0 6 votes vote down vote up
public static void initMessageBroadcaster(final Context context) {
	Wearable.getCapabilityClient(context).addListener(new CapabilityClient.OnCapabilityChangedListener() {
		@Override
		public void onCapabilityChanged(@NonNull CapabilityInfo capabilityInfo) {
			updateBestNode(context);
		}
	}, "apde_receive_logs");
	
	// Can't do this on the main thread
	(new Thread(new Runnable() {
		@Override
		public void run() {
			updateBestNode(context);
		}
	})).start();
}
 
Example #2
Source File: ListenerService.java    From AndroidAPS with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public void onConnected(Bundle bundle) {
    // Log.d(TAG, logPrefix + "onConnected call requestData");

    CapabilityApi.CapabilityListener capabilityListener = new CapabilityApi.CapabilityListener() {

        @Override
        public void onCapabilityChanged(CapabilityInfo capabilityInfo) {
            updatePhoneSyncBgsCapability(capabilityInfo);
            Log.d(TAG, logPrefix + "onConnected onCapabilityChanged mPhoneNodeID:" + mPhoneNodeId
                + ", Capability: " + capabilityInfo);
        }
    };

    Wearable.CapabilityApi.addCapabilityListener(googleApiClient, capabilityListener, CAPABILITY_PHONE_APP);

    Wearable.ChannelApi.addListener(googleApiClient, this);
    requestData();
}
 
Example #3
Source File: MessageApiHandler.java    From PowerSwitch_Android with GNU General Public License v3.0 6 votes vote down vote up
private void setupReachableReceiverActionTrigger() {
    CapabilityApi.GetCapabilityResult result = Wearable.CapabilityApi.getCapability(
            googleApiClient, context
                    .getResources()
                    .getString(eu.power_switch.shared.R.string.RECEIVER_ACTION_TRIGGER_CAPABILITY_NAME), CapabilityApi.FILTER_REACHABLE)
            .await();
    updateReceiverActionTriggerCapability(result.getCapability());

    CapabilityApi.CapabilityListener capabilityListener =
            new CapabilityApi.CapabilityListener() {
                @Override
                public void onCapabilityChanged(CapabilityInfo capabilityInfo) {
                    updateReceiverActionTriggerCapability(capabilityInfo);
                }
            };

    Wearable.CapabilityApi.addCapabilityListener(googleApiClient, capabilityListener,
            context.getResources()
                    .getString(eu.power_switch.shared.R.string.RECEIVER_ACTION_TRIGGER_CAPABILITY_NAME));
}
 
Example #4
Source File: WatchUpdaterService.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
private void updateWearSyncBgsCapability() {
    CapabilityApi.GetCapabilityResult capabilityResult =
            Wearable.CapabilityApi.getCapability(
                    googleApiClient, CAPABILITY_WEAR_APP,
                    CapabilityApi.FILTER_REACHABLE).await(GET_CAPABILITIES_TIMEOUT_MS, TimeUnit.MILLISECONDS);
    CapabilityInfo nodes;
    if (!capabilityResult.getStatus().isSuccess()) {
        Log.e(TAG, "updateWearSyncBgsCapability Failed to get capabilities, status: " + capabilityResult.getStatus().getStatusMessage());
        nodes = null;
    } else {
        nodes = capabilityResult.getCapability();
    }

    if (nodes != null && nodes.getNodes().size() > 0) {
        Log.d(TAG, "Updating wear sync nodes");
        updateWearSyncBgsCapability(nodes);
    }
}
 
Example #5
Source File: ListenerService.java    From xDrip-plus with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onCapabilityChanged(CapabilityInfo capabilityInfo) {
    Node phoneNode = updatePhoneSyncBgsCapability(capabilityInfo);
    Log.d(TAG, "onCapabilityChanged mPhoneNodeID:" + (phoneNode != null ? phoneNode.getId() : ""));//mPhoneNodeId
    //onPeerConnected and onPeerDisconnected deprecated at the same time as BIND_LISTENER

    if (phoneNode != null && phoneNode.getId().length() > 0) {
        if (JoH.ratelimit("on-connected-nodes-sync", 1200)) {
            Log.d(TAG, "onCapabilityChanged event - attempting resync");
            requestData();
        } else {
            Log.d(TAG, "onCapabilityChanged event - ratelimited");
        }
        sendPrefSettings();//from onPeerConnected
    }
}
 
Example #6
Source File: WearDataLayerListenerService.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
public static void sendMessageToWatch(final String path, final byte[] data, String capability){
	Wearable.getCapabilityClient(ApplicationLoader.applicationContext)
			.getCapability(capability, CapabilityClient.FILTER_REACHABLE)
			.addOnCompleteListener(new OnCompleteListener<CapabilityInfo>(){
				@Override
				public void onComplete(@NonNull Task<CapabilityInfo> task){
					CapabilityInfo info=task.getResult();
					if(info!=null){
						MessageClient mc=Wearable.getMessageClient(ApplicationLoader.applicationContext);
						Set<Node> nodes=info.getNodes();
						for(Node node:nodes){
							mc.sendMessage(node.getId(), path, data);
						}
					}
				}
			});
}
 
Example #7
Source File: MainWearActivity.java    From wear-os-samples with Apache License 2.0 6 votes vote down vote up
private void checkIfPhoneHasApp() {
    Log.d(TAG, "checkIfPhoneHasApp()");

    Task<CapabilityInfo> capabilityInfoTask = Wearable.getCapabilityClient(this)
            .getCapability(CAPABILITY_PHONE_APP, CapabilityClient.FILTER_ALL);

    capabilityInfoTask.addOnCompleteListener(new OnCompleteListener<CapabilityInfo>() {
        @Override
        public void onComplete(Task<CapabilityInfo> task) {

            if (task.isSuccessful()) {
                Log.d(TAG, "Capability request succeeded.");
                CapabilityInfo capabilityInfo = task.getResult();
                mAndroidPhoneNodeWithApp = pickBestNodeId(capabilityInfo.getNodes());

            } else {
                Log.d(TAG, "Capability request failed to return any results.");
            }

            verifyNodeAndUpdateUI();
        }
    });
}
 
Example #8
Source File: CompanionNotifyActivity.java    From PixelWatchFace with GNU General Public License v3.0 6 votes vote down vote up
private void checkIfPhoneHasApp() {
  Log.d(TAG, "checkIfPhoneHasApp()");

  Task<CapabilityInfo> capabilityInfoTask = Wearable.getCapabilityClient(this)
      .getCapability(CAPABILITY_PHONE_APP, CapabilityClient.FILTER_ALL);

  capabilityInfoTask.addOnCompleteListener(new OnCompleteListener<CapabilityInfo>() {
    @Override
    public void onComplete(Task<CapabilityInfo> task) {

      if (task.isSuccessful()) {
        Log.d(TAG, "Capability request succeeded.");
        CapabilityInfo capabilityInfo = task.getResult();
        mAndroidPhoneNodeWithApp = pickBestNodeId(capabilityInfo.getNodes());

      } else {
        Log.d(TAG, "Capability request failed to return any results.");
      }

      verifyNodeAndUpdateUI();
    }
  });
}
 
Example #9
Source File: MainMobileActivity.java    From wear-os-samples with Apache License 2.0 6 votes vote down vote up
private void findWearDevicesWithApp() {
    Log.d(TAG, "findWearDevicesWithApp()");

    Task<CapabilityInfo> capabilityInfoTask = Wearable.getCapabilityClient(this)
            .getCapability(CAPABILITY_WEAR_APP, CapabilityClient.FILTER_ALL);

    capabilityInfoTask.addOnCompleteListener(new OnCompleteListener<CapabilityInfo>() {
        @Override
        public void onComplete(Task<CapabilityInfo> task) {

            if (task.isSuccessful()) {
                Log.d(TAG, "Capability request succeeded.");

                CapabilityInfo capabilityInfo = task.getResult();
                mWearNodesWithApp = capabilityInfo.getNodes();

                Log.d(TAG, "Capable Nodes: " + mWearNodesWithApp);

                verifyNodeAndUpdateUI();

            } else {
                Log.d(TAG, "Capability request failed to return any results.");
            }
        }
    });
}
 
Example #10
Source File: WearDataLayerListenerService.java    From TelePlus-Android with GNU General Public License v2.0 6 votes vote down vote up
public static void sendMessageToWatch(final String path, final byte[] data, String capability){
	Wearable.getCapabilityClient(ApplicationLoader.applicationContext)
			.getCapability(capability, CapabilityClient.FILTER_REACHABLE)
			.addOnCompleteListener(new OnCompleteListener<CapabilityInfo>(){
				@Override
				public void onComplete(@NonNull Task<CapabilityInfo> task){
					CapabilityInfo info=task.getResult();
					if(info!=null){
						MessageClient mc=Wearable.getMessageClient(ApplicationLoader.applicationContext);
						Set<Node> nodes=info.getNodes();
						for(Node node:nodes){
							mc.sendMessage(node.getId(), path, data);
						}
					}
				}
			});
}
 
Example #11
Source File: WatchUpdaterService.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
private void updateWearSyncBgsCapability() {
    CapabilityApi.GetCapabilityResult capabilityResult =
            Wearable.CapabilityApi.getCapability(
                    googleApiClient, CAPABILITY_WEAR_APP,
                    CapabilityApi.FILTER_REACHABLE).await(GET_CAPABILITIES_TIMEOUT_MS, TimeUnit.MILLISECONDS);
    CapabilityInfo nodes;
    if (!capabilityResult.getStatus().isSuccess()) {
        Log.e(TAG, "updateWearSyncBgsCapability Failed to get capabilities, status: " + capabilityResult.getStatus().getStatusMessage());
        nodes = null;
    } else {
        nodes = capabilityResult.getCapability();
    }

    if (nodes != null && nodes.getNodes().size() > 0) {
        Log.d(TAG, "Updating wear sync nodes");
        updateWearSyncBgsCapability(nodes);
    }
}
 
Example #12
Source File: ListenerService.java    From xDrip with GNU General Public License v3.0 6 votes vote down vote up
@Override
public void onCapabilityChanged(CapabilityInfo capabilityInfo) {
    Node phoneNode = updatePhoneSyncBgsCapability(capabilityInfo);
    Log.d(TAG, "onCapabilityChanged mPhoneNodeID:" + (phoneNode != null ? phoneNode.getId() : ""));//mPhoneNodeId
    //onPeerConnected and onPeerDisconnected deprecated at the same time as BIND_LISTENER

    if (phoneNode != null && phoneNode.getId().length() > 0) {
        if (JoH.ratelimit("on-connected-nodes-sync", 1200)) {
            Log.d(TAG, "onCapabilityChanged event - attempting resync");
            requestData();
        } else {
            Log.d(TAG, "onCapabilityChanged event - ratelimited");
        }
        sendPrefSettings();//from onPeerConnected
    }
}
 
Example #13
Source File: WearProviderService.java    From cordova-androidwear with Apache License 2.0 5 votes vote down vote up
private void loadNodes() {
	Task<CapabilityInfo> capabilityTask = Wearable.getCapabilityClient(this)
			.getCapability(CORDOVA_CAPABILITY, CapabilityClient.FILTER_REACHABLE);
	capabilityTask.addOnSuccessListener(new OnSuccessListener<CapabilityInfo>() {
		@Override
		public void onSuccess(CapabilityInfo capabilityInfo) {
			WearProviderService.this.onCapabilityChanged(capabilityInfo);
		}
	});
}
 
Example #14
Source File: ListenerService.java    From AndroidAPS with GNU Affero General Public License v3.0 5 votes vote down vote up
private Node updatePhoneSyncBgsCapability(CapabilityInfo capabilityInfo) {
    // Log.d(TAG, "CapabilityInfo: " + capabilityInfo);

    Set<Node> connectedNodes = capabilityInfo.getNodes();
    return pickBestNode(connectedNodes);
    // mPhoneNodeId = pickBestNodeId(connectedNodes);
}
 
Example #15
Source File: DisconnectListenerService.java    From android-FindMyPhone with Apache License 2.0 5 votes vote down vote up
private void updateFindMeCapability(CapabilityInfo capabilityInfo) {
    Set<Node> connectedNodes = capabilityInfo.getNodes();
    if (connectedNodes.isEmpty()) {
        setupLostConnectivityNotification();
    } else {
        for (Node node : connectedNodes) {
            // we are only considering those nodes that are directly connected
            if (node.isNearby()) {
                ((NotificationManager) getSystemService(NOTIFICATION_SERVICE))
                        .cancel(FORGOT_PHONE_NOTIFICATION_ID);
            }
        }
    }
}
 
Example #16
Source File: MainWearActivity.java    From wear-os-samples with Apache License 2.0 5 votes vote down vote up
@Override
protected void onResume() {
    Log.d(TAG, "onResume()");
    super.onResume();

    // Instantiates clients without member variables, as clients are inexpensive to create and
    // won't lose their listeners. (They are cached and shared between GoogleApi instances.)
    Wearable.getMessageClient(this).addListener(this);
    Wearable.getCapabilityClient(this).addListener(
            this, Constants.CAPABILITY_PHONE_APP);

    // Initial check of capabilities to find the phone.
    Task<CapabilityInfo> capabilityInfoTask = Wearable.getCapabilityClient(this)
            .getCapability(Constants.CAPABILITY_PHONE_APP, CapabilityClient.FILTER_REACHABLE);

    capabilityInfoTask.addOnCompleteListener(new OnCompleteListener<CapabilityInfo>() {
        @Override
        public void onComplete(Task<CapabilityInfo> task) {

            if (task.isSuccessful()) {
                Log.d(TAG, "Capability request succeeded.");

                CapabilityInfo capabilityInfo = task.getResult();
                mPhoneNodeId = pickBestNodeId(capabilityInfo.getNodes());

            } else {
                Log.d(TAG, "Capability request failed to return any results.");
            }
        }
    });

    // Enables app to handle 23+ (M+) style permissions.
    mWearBodySensorsPermissionApproved =
            ActivityCompat.checkSelfPermission(this, Manifest.permission.BODY_SENSORS)
                    == PackageManager.PERMISSION_GRANTED;
}
 
Example #17
Source File: ListenerService.java    From AndroidAPS with GNU Affero General Public License v3.0 5 votes vote down vote up
public CapabilityInfo getCapabilities() {

        CapabilityApi.GetCapabilityResult capabilityResult = Wearable.CapabilityApi.getCapability(googleApiClient,
            CAPABILITY_PHONE_APP, CapabilityApi.FILTER_REACHABLE).await(GET_CAPABILITIES_TIMEOUT_MS,
            TimeUnit.MILLISECONDS);

        if (!capabilityResult.getStatus().isSuccess()) {
            Log.e(TAG, logPrefix + "doInBackground Failed to get capabilities, status: "
                + capabilityResult.getStatus().getStatusMessage());
            return null;
        }

        return capabilityResult.getCapability();

    }
 
Example #18
Source File: WearDataLayerListenerService.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onCapabilityChanged(CapabilityInfo capabilityInfo){
	if("remote_notifications".equals(capabilityInfo.getName())){
		watchConnected=false;
		for(Node node:capabilityInfo.getNodes()){
			if(node.isNearby())
				watchConnected=true;
		}
	}
}
 
Example #19
Source File: QuizReportActionService.java    From android-Quiz with Apache License 2.0 5 votes vote down vote up
private void sendResetMessage(GoogleApiClient googleApiClient, CapabilityInfo capabilityInfo) {
    Set<Node> connectedNodes = capabilityInfo.getNodes();
    if (connectedNodes.isEmpty()) {
        Log.w(TAG, "No node capable of resetting quiz was found");
    } else {
        for (Node node : connectedNodes) {
            Wearable.MessageApi.sendMessage(googleApiClient, node.getId(), RESET_QUIZ_PATH,
                    new byte[0]);
        }
    }
}
 
Example #20
Source File: WearDataLayerListenerService.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onCapabilityChanged(CapabilityInfo capabilityInfo){
	if("remote_notifications".equals(capabilityInfo.getName())){
		watchConnected=false;
		for(Node node:capabilityInfo.getNodes()){
			if(node.isNearby())
				watchConnected=true;
		}
	}
}
 
Example #21
Source File: MainMobileActivity.java    From wear-os-samples with Apache License 2.0 5 votes vote down vote up
public void onCapabilityChanged(CapabilityInfo capabilityInfo) {
    Log.d(TAG, "onCapabilityChanged(): " + capabilityInfo);

    mWearNodesWithApp = capabilityInfo.getNodes();

    // Because we have an updated list of devices with/without our app, we need to also update
    // our list of active Wear devices.
    findAllWearDevices();

    verifyNodeAndUpdateUI();
}
 
Example #22
Source File: WearDataLayerListenerService.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
public static void sendMessageToWatch(final String path, final byte[] data, String capability) {
	Wearable.getCapabilityClient(ApplicationLoader.applicationContext)
			.getCapability(capability, CapabilityClient.FILTER_REACHABLE)
			.addOnCompleteListener(task -> {
				CapabilityInfo info = task.getResult();
				if (info != null) {
					MessageClient mc = Wearable.getMessageClient(ApplicationLoader.applicationContext);
					Set<Node> nodes = info.getNodes();
					for (Node node : nodes) {
						mc.sendMessage(node.getId(), path, data);
					}
				}
			});
}
 
Example #23
Source File: MainActivity.java    From wear-os-samples with Apache License 2.0 5 votes vote down vote up
/** Find the connected nodes that provide at least one of the given capabilities. */
private void showNodes(final String... capabilityNames) {

    Task<Map<String, CapabilityInfo>> capabilitiesTask =
            Wearable.getCapabilityClient(this)
                    .getAllCapabilities(CapabilityClient.FILTER_REACHABLE);

    capabilitiesTask.addOnSuccessListener(
            new OnSuccessListener<Map<String, CapabilityInfo>>() {
                @Override
                public void onSuccess(Map<String, CapabilityInfo> capabilityInfoMap) {
                    Set<Node> nodes = new HashSet<>();

                    if (capabilityInfoMap.isEmpty()) {
                        showDiscoveredNodes(nodes);
                        return;
                    }
                    for (String capabilityName : capabilityNames) {
                        CapabilityInfo capabilityInfo = capabilityInfoMap.get(capabilityName);
                        if (capabilityInfo != null) {
                            nodes.addAll(capabilityInfo.getNodes());
                        }
                    }
                    showDiscoveredNodes(nodes);
                }
            });
}
 
Example #24
Source File: WearDataLayerListenerService.java    From Telegram with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void onCapabilityChanged(CapabilityInfo capabilityInfo) {
	if ("remote_notifications".equals(capabilityInfo.getName())) {
		watchConnected = false;
		for (Node node : capabilityInfo.getNodes()) {
			if (node.isNearby())
				watchConnected = true;
		}
	}
}
 
Example #25
Source File: WearableUtil.java    From APDE with GNU General Public License v2.0 5 votes vote down vote up
public static void checkWatchAvailable(final Context context, final ResultCallback callback) {
	(new Thread(new Runnable() {
		@Override
		public void run() {
			boolean successful = false;
			
			try {
				CapabilityInfo info = Tasks.await(Wearable.getCapabilityClient(context).getCapability("apde_run_watch_sketches", CapabilityClient.FILTER_REACHABLE));
				
				for (Node node : info.getNodes()) {
					if (node.isNearby()) {
						successful = true;
						break;
					}
				}
			} catch (ExecutionException | InterruptedException e) {
				e.printStackTrace();
			}
			
			if (successful) {
				callback.success();
			} else {
				callback.failure();
			}
		}
	})).start();
}
 
Example #26
Source File: LoggingUtil.java    From APDE with GNU General Public License v2.0 5 votes vote down vote up
private static void updateBestNode(Context context) {
	bestNodeId = null;
	
	try {
		CapabilityInfo info = Tasks.await(Wearable.getCapabilityClient(context).getCapability("apde_receive_logs", CapabilityClient.FILTER_REACHABLE));
		for (Node node : info.getNodes()) {
			if (node.isNearby()) {
				bestNodeId = node.getId();
			}
		}
	} catch (Exception e) {
		// Don't call printStackTrace() because that would make an infinite loop
		Log.e("apde", e.toString());
	}
}
 
Example #27
Source File: WearProviderService.java    From cordova-androidwear with Apache License 2.0 4 votes vote down vote up
@Override
public void onCapabilityChanged(@NonNull CapabilityInfo capabilityInfo) {
	LOGD(TAG, "onCapabilityChanged: " + capabilityInfo);

	syncNodes(capabilityInfo.getNodes());
}
 
Example #28
Source File: CrossbowListenerService.java    From CrossBow with Apache License 2.0 4 votes vote down vote up
@Override
@CallSuper
public void onCapabilityChanged(CapabilityInfo capabilityInfo) {
}
 
Example #29
Source File: MessageApiHandler.java    From PowerSwitch_Android with GNU General Public License v3.0 4 votes vote down vote up
private void updateReceiverActionTriggerCapability(CapabilityInfo capabilityInfo) {
    connectedNodes = capabilityInfo.getNodes();
}
 
Example #30
Source File: WatchUpdaterService.java    From AndroidAPS with GNU Affero General Public License v3.0 4 votes vote down vote up
private void updateWearSyncBgsCapability(CapabilityInfo capabilityInfo) {
    Log.d("WatchUpdaterService", logPrefix + "CabilityInfo: " + capabilityInfo);
    Set<Node> connectedNodes = capabilityInfo.getNodes();
    mWearNodeId = pickBestNodeId(connectedNodes);
}