I am publishing and subscribing to messages with Google Nearby and am receiving onFound and onLost properly, but am not receiving any callbacks on onDistanceChanged or onBleSignalChanged. I know that BLE signal changed is based on using BLE for discovery, but is there a similar limitation for onDistanceChanged? The docs don't seem to indicate there is. Here is my message listener below, thanks for any suggestions!
mMessageListener = new MessageListener() {
#Override
public void onFound(Message message) {
String messageAsString = new String(message.getContent());
Log.d(TAG, "Found message: " + messageAsString);
}
#Override
public void onLost(Message message) {
String messageAsString = new String(message.getContent());
Log.d(TAG, "Lost sight of message: " + messageAsString);
}
#Override
public void onDistanceChanged(Message message, Distance distance) {
super.onDistanceChanged(message, distance);
Log.d(TAG, "New distance "+distance.getMeters()+" to message: " + new String(message.getContent()));
}
#Override
public void onBleSignalChanged(Message message, BleSignal bleSignal) {
super.onBleSignalChanged(message, bleSignal);
Log.d(TAG, "New ble signal " + bleSignal.getRssi() + " to message: " + new String(message.getContent()));
}
};
There are two reasons you may not get that callback:
Unfortunately, the distance callback currently only works for BLE beacon messages. We've fixed the docs to say that, but they won't update on the web until the next Google Play Services SDK release (in a couple weeks). We hope to make it work for more messages in the future.
The BLE signal and distance callbacks aren't called for the PendingIntent version of subscribe().
Related
I have setup pubnub on android using java
And on all other Operating Systems the setup works fine. On Android P however the attach listener always gives this error -
PNStatus(category=PNBadRequestCategory, errorData=PNErrorData(information=null, throwable=PubNubException(errormsg=CLEARTEXT communication to ps.pndsn.com not permitted by network security policy, pubnubError=PubNubError(errorCode=103, errorCodeExtended=0, errorObject=null, message=HTTP Error. Please check network connectivity. Please contact support with error details if issue persists., errorString=null), jso=null, response=null, statusCode=0)), error=true, statusCode=0, operation=PNSubscribeOperation, tlsEnabled=false, uuid=null, authKey=null, origin=null, clientRequest=null, affectedChannels=[5d67fb36f4f95718bf8ec310], affectedChannelGroups=[])
The setup is as follows -
PNConfiguration pnConfiguration = new PNConfiguration();
pnConfiguration.setLogVerbosity(PNLogVerbosity.BODY);
pnConfiguration.setPublishKey(getString(R.string.pubnub_publish_key));
pnConfiguration.setSubscribeKey(getString(R.string.pubnub_subscribe_key));
pnConfiguration.setSecure(false);
pubnub = new PubNub(pnConfiguration);
Then i attach listener like this
pubnub.addListener(new SubscribeCallback() {
#Override
public void status(PubNub pubnub, PNStatus status) {
Log.e("Pubnub:- ", status.toString());
switch (status.getOperation()) {
// let's combine unsubscribe and subscribe handling for ease of use
case PNSubscribeOperation:
case PNUnsubscribeOperation:
// note: subscribe statuses never have traditional
// errors, they just have categories to represent the
// different issues or successes that occur as part of subscribe
switch (status.getCategory()) {
case PNConnectedCategory:
// this is expected for a subscribe, this means there is no error or issue whatsoever
case PNReconnectedCategory:
// this usually occurs if subscribe temporarily fails but reconnects. This means
// there was an error but there is no longer any issue
case PNDisconnectedCategory:
// this is the expected category for an unsubscribe. This means there
// was no error in unsubscribing from everything
case PNUnexpectedDisconnectCategory:
// this is usually an issue with the internet connection, this is an error, handle appropriately
case PNAccessDeniedCategory:
// this means that PAM does allow this client to subscribe to this
// channel and channel group configuration. This is another explicit error
default:
// More errors can be directly specified by creating explicit cases for other
// error categories of `PNStatusCategory` such as `PNTimeoutCategory` or `PNMalformedFilterExpressionCategory` or `PNDecryptionErrorCategory`
}
case PNHeartbeatOperation:
// heartbeat operations can in fact have errors, so it is important to check first for an error.
// For more information on how to configure heartbeat notifications through the status
// PNObjectEventListener callback, consult <link to the PNCONFIGURATION heartbeart config>
if (status.isError()) {
// There was an error with the heartbeat operation, handle here
} else {
// heartbeat operation was successful
}
default: {
// Encountered unknown status type
}
}
}
#Override
public void message(PubNub pubnub, PNMessageResult message) {
String messagePublisher = message.getPublisher();
System.out.println("Message publisher: " + messagePublisher);
System.out.println("Message Payload: " + message.getMessage());
System.out.println("Message Subscription: " + message.getSubscription());
System.out.println("Message Channel: " + message.getChannel());
System.out.println("Message timetoken: " + message.getTimetoken());
}
#Override
public void presence(PubNub pubnub, PNPresenceEventResult presence) {
}
#Override
public void signal(PubNub pubnub, PNSignalResult pnSignalResult) {
System.out.println("Signal publisher: " + signal.getPublisher());
System.out.println("Signal payload: " + signal.getMessage());
System.out.println("Signal subscription: " + signal.getSubscription());
System.out.println("Signal channel: " + signal.getChannel());
System.out.println("Signal timetoken: " + signal.getTimetoken());
}
#Override
public void user(PubNub pubnub, PNUserResult pnUserResult) {
// for Objects, this will trigger when:
// . user updated
// . user deleted
PNUser pnUser = pnUserResult.getUser(); // the user for which the event applies to
pnUserResult.getEvent(); // the event name
}
#Override
public void space(PubNub pubnub, PNSpaceResult pnSpaceResult) {
// for Objects, this will trigger when:
// . space updated
// . space deleted
PNSpace pnSpace = pnSpaceResult.getSpace(); // the space for which the event applies to
pnSpaceResult.getEvent(); // the event name
}
#Override
public void membership(PubNub pubnub, PNMembershipResult pnMembershipResult) {
// for Objects, this will trigger when:
// . user added to a space
// . user removed from a space
// . membership updated on a space
JsonElement data = pnMembershipResult.getData(); // membership data for which the event applies to
pnMembershipResult.getEvent(); // the event name
}
#Override
public void messageAction(PubNub pubnub, PNMessageActionResult pnActionResult) {
PNMessageAction pnMessageAction = pnActionResult.getAction();
System.out.println("Message action type: " + pnMessageAction.getType());
System.out.println("Message action value: " + pnMessageAction.getValue());
System.out.println("Message action uuid: " + pnMessageAction.getUuid());
System.out.println("Message action actionTimetoken: " + pnMessageAction.getActionTimetoken());
System.out.println("Message action messageTimetoken: " + pnMessageAction.getMessageTimetoken());]
System.out.println("Message action subscription: " + pnActionResult.getSubscription());
System.out.println("Message action channel: " + pnActionResult.getChannel());
System.out.println("Message action timetoken: " + pnActionResult.getTimetoken());
}
});
Like i said it works fine in other OS's except 9 and i am using the latest version of pubnub, infact i upgraded to the latest version and the above error was identical.
And i noticed something else, a message which i see in the debugger that only shows up when running in android version 9.
isWhitelistProcess - Process is Whitelisted
I searched for the message and found that its a harmless warning message.
Enabling TLS (SSL) resolves this error:
pnConfiguration.setSecure(true);
The reason is answered in another Stack Overflow thread already. It is not specific to PubNub but because you disabled TLS (SSL) in PubNub, it explicitly called out the PubNub domain in the error.
I am unable to create a group chat where more than 2 (up to 15) nearby android users are able to join a chat room.
startMeshNetwork() starts advertising the connection and discovering.
This is called in onCreate(), as well as in the callback for a successful connection. This is so that the device will continue to join all nearby devices.
public void startMeshNetwork(){
Nearby.getConnectionsClient(this)
.startAdvertising(
/* endpointName= */ "Name here",
/* serviceId= */ "ID here",
mConnectionLifecycleCallback,
new AdvertisingOptions(com.google.android.gms.nearby.connection.Strategy.P2P_CLUSTER));
Nearby.getConnectionsClient(this)
.startDiscovery(
/* serviceId= */ "ID here",
new EndpointDiscoveryCallback() {
#Override
public void onEndpointFound(String endpointId, DiscoveredEndpointInfo info) { Nearby.getConnectionsClient(getApplicationContext())
.requestConnection(
/* endpointName= */ "Name here",
endpointId,
mConnectionLifecycleCallback);
endpoints.add(endpointId);
}
#Override
public void onEndpointLost(String endpointId) {
startMeshNetwork();
}
},
new DiscoveryOptions(com.google.android.gms.nearby.connection.Strategy.P2P_CLUSTER));
}
Code segment that sends payloads to all connected devices
Payload payload = Payload.fromBytes(pendingmessage.getBytes());
for(String endpointId:endpoints)
Nearby.getConnectionsClient(getApplicationContext()).sendPayload(endpointId, payload);
Connections are being formed with this method, however, the payload sending is inconsistent and is only sent to one device.
I am working on an android app (on android studio) where I have successfully implemented the paho mqtt library for a single activity. I have now run into the issue for the case where I need to persist my mqtt client across multiple activities.
Will i need to create a new client for each activity (subscribe to the needed topics again) and pass modified data of the old client through intents to update the new client ? [this seems like a really bad method and I am assuming that there's a more simple straightforward solution that I am missing]
On your paho mqtt class, you can send broadcast message to your activities. Here how I used;
#Override
public void messageArrived(String topic, MqttMessage message) throws Exception {
Log.d("MQTT MESSAGE", "Message arrived: Topic: " + topic + " Message: " + message);
broadcastSendAction("mqttMessage", "Topic: " + topic + " Message: " + message);
}
#Override
public void connectComplete(boolean b, String s) {
Log.d("MQTT MESSAGE", "Connection SUCCESS.");
mqttStatus = true;
broadcastSendAction("mqttConnection", true);
if (!mqttSubs)
subscribeTopic(mSharedPreferences.getString(getResources().getString(R.string.regId), SepMessageUtils.DEFAULT_REGID), client);
}
When AWSIotMqttManager is connected, i subscribe to shadow topics
mMqttManager.subscribeToTopic("$aws/things/4/shadow/update/delta", AWSIotMqttQos.QOS1, new AWSIotMqttNewMessageCallback() {
#Override
public void onMessageArrived(String topic, byte[] data) {
Log.d("DEBUG", "onMessageArrived: " + topic);
}
});
mMqttManager.subscribeToTopic("$aws/things/4/shadow/get/accepted", AWSIotMqttQos.QOS1, new AWSIotMqttNewMessageCallback() {
#Override
public void onMessageArrived(String topic, byte[] data) {
Log.d("DEBUG", "onMessageArrived: " + topic);
}
});
and then publish an empty message, as stated in docs
mMqttManager.publishString("", "$aws/things/4/shadow/get", AWSIotMqttQos.QOS1);
I get no callback.
When i remove subscription to delta, i got it.
Why? How to to subscribe on two topics on app start?
I am working on an Android application that uses Twilio to make phone calls and to send SMS.
While making a call I get the IVRS message "Your call cannot be completed because of two missing digits".
The FROM number is "+18669135337" and TO number is "(949) 439-7570" or "+19494397570"
What could be the reason thats causing this issue?
This is the code snippet thats making the call
public void connect(String toNumber, ConnectionListener listener) {
Map<String, String> parameters = new HashMap<String, String>();
Log.e(TAG, "Calling from " + mFromNumber);
Log.e(TAG, "Calling to " + toNumber);
Log.e(TAG, "mDevice State is " + mDevice.getState());
parameters.put(Constants.KEY_TO_NUMBER, toNumber);
parameters.put(Constants.KEY_FROM_NUMBER, mFromNumber);
mConnection = mDevice.connect(parameters, listener);
Log.e(TAG, "Connection status " + mConnection);
if (mConnection == null) {
Log.w(TAG, "Failed to create new connection");
}
}