When I am trying to call joinRoom() or createRoom() method.I am getting two different error
"registration-required(407)"
"feature-not-implemented(501) Will me done soon".
for reference purpose,I have posted code also.I already posted this issue on quickblox discussion board but nobody has solution.
QBChatService.getInstance().joinRoom(roomName, roomReceivingListener);
String roomName="myroom";
roomReceivingListener = new RoomListener()
{
#Override
public void onCreatedRoom(QBChatRoom qbChatRoom)
{
Log.i("TAG", "on Created Room listener");
chatRoom = qbChatRoom;
//chatRoom.addMessageListener(chatMessageListener);
}
#Override
public void onJoinedRoom(QBChatRoom qbChatRoom)
{
Log.i("TAG", "on Joined Room listener");
chatRoom = qbChatRoom;
//QBChatService.getInstance().joinRoom(chatRoom, roomReceivingListener);
//chatRoom.addMessageListener(chatMessageListener);
}
#Override
public void onError(String msg)
{
Log.i("TAG", "on join Room error listener");
}
};
Related
I tried to read data from firebase db and return values to another method.To do that I added interface and use it as a callback function and tried to wait until data filled. But it still give the null pointer exception.
private interface FirebaseCallback {
void onCallBack(Card card);
}
// method to read travel Cards
public void readCard(final FirebaseCallback fb) {
cardNo = (EditText)findViewById(R.id.editTextCardNo);
ValueEventListener cardListner = new ValueEventListener() {
#Override
public void onDataChange(DataSnapshot dataSnapshot) {
if(dataSnapshot.exists()) {
travelCard = dataSnapshot.getValue(Card.class);
fb.onCallBack(travelCard);
}
else displayMessage(inValidTravelCard);
}
#Override
public void onCancelled(DatabaseError databaseError) {
Log.d("ERROR : ", databaseError.getMessage());
}
};
String cn = cardNo.getText().toString();
Query q = FirebaseDatabase.getInstance().getReference("Card").orderByChild("cardNumber").equalTo(cn).limitToFirst(1);
q.addListenerForSingleValueEvent(cardListner);
}
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_card_reader);
System.out.println("fffffffffffffffffffffffffffffff " + " BEFORE>..........................");
readCard(new FirebaseCallback() {
#Override
public void onCallBack(Card card) {
Log.d("card = ",card.getAccountId());
}
});
System.out.println("fffffffffffffffffffffffffffffff " + " After>..........................");
}
});
}
Here's the ERROR :
Here's the database
If you parse the stack trace you get the error message you get is println needs a message, triggered from Log.d. In the code you shared, there are two statements that could trigger that message:
Log.d("ERROR : ", databaseError.getMessage());
And
Log.d("card = ",card.getAccountId());
It seems quite unlikely that databaseError.getMessage() returns nothing, so it's more likely that card.getAccountId() returns nothing or null. A simple solution is to check for that:
Log.d("card = ", card.getAccountId() != null ? card.getAccountId() : "No account ID found on card");
Null pointer exceptions are extremely common, and knowing how to troubleshoot them is a skill that will serve you well. I recommend studying: What is a NullPointerException, and how do I fix it?.
I am using Twilio Programmable chat APIs in android for 1 to 1 chat.
Following is my usecase:
1) I create a unique channel name
2) Check if the channel already exists or not
if channel exists:
user joins channel
else
create a channel with unique name
user joins channel
end
Now, what is happening is, when I am trying to join the channel, it is giving me the error: "Member already exists". So, at this point if I try to check the members of the channel, I get the Member object to be null.
I have 2 doubts at this point:
1) Shouldn't the user object contain this member if it is already a part of the channel?
2) If the user is already a part of the channel, I should be able to send mesages to the channel, by just adding the channelListener, which in this case is not happening.
I don't understand the issue. Following are my code snippets:
ChatClient.Properties props = new ChatClient.Properties.Builder()
.createProperties();
ChatClient.create(ChatActivity.this, accessToken, props, mChatClientCallback);
private CallbackListener<ChatClient> mChatClientCallback =
new CallbackListener<ChatClient>() {
#Override
public void onSuccess(ChatClient chatClient) {
mChatClient = chatClient;
//loadChannels();
Log.i(TAG, "Success creating Twilio Chat Client");
createOrJoinChannel();
}
#Override
public void onError(ErrorInfo errorInfo) {
Log.i(TAG,"Error creating Twilio Chat Client: " + errorInfo.getMessage());
}
};
private void createOrJoinChannel(){
//Only SID or unique name of channel can be supplied as parameter
mChatClient.getChannels().getChannel(UNIQUE_CHANNEL_NAME, new CallbackListener<Channel>() {
#Override
public void onSuccess(Channel channel) {
if (channel != null) {
joinChannel(channel);
} else {
Log.i(TAG, "Error occurred in getting channel");
}
}
#Override
public void onError(ErrorInfo errorInfo) {
Log.i(TAG,"Error retrieving channel: " + errorInfo.getMessage());
createChannel();
}
});
}
private void joinChannel(final Channel channel) {
Log.i(TAG, "inside join channel" + channel.getUniqueName());
Log.i(TAG, "channel status: " + channel.getStatus());
Members members = channel.getMembers();
if(members!=null){
ArrayList<Member> list = (ArrayList<Member>) members.getMembersList();
for(int i=0; i<list.size(); i++){
Log.i(TAG, "member " + i + list.get(i).getIdentity());
}
}else{
Log.i(TAG, "null object"); //Getting this even when I get
//"Member already exists" error
}
channel.join(new StatusListener() {
#Override
public void onSuccess() {
mGeneralChannel = channel;
mGeneralChannel.addListener(mDefaultChannelListener);
}
#Override
public void onError(ErrorInfo errorInfo) {
//Error joining channel: Member already exists
Log.i(TAG,"Error joining channel: " + errorInfo.getMessage());
});
}
private void createChannel(){
mChatClient.getChannels().createChannel(FRIENDLY_CHANNEL_NAME,
Channel.ChannelType.PUBLIC, new CallbackListener<Channel>() {
#Override
public void onSuccess(Channel channel) {
if (channel != null) {
setUniqueNameAndJoin(channel);
}
}
#Override
public void onError(ErrorInfo errorInfo) {
Log.i(TAG,"chats: " + "Unique name could not be set: " + errorInfo.getMessage());
}
});
}
private void setUniqueNameAndJoin(final Channel channel){
channel.setUniqueName(UNIQUE_CHANNEL_NAME, new StatusListener() {
#Override
public void onSuccess() {
Log.i(TAG, "channel with unique name created " + channel.getUniqueName());
joinChannel(channel);
}
#Override
public void onError(ErrorInfo errorInfo) {
super.onError(errorInfo);
}
});
}
private ChannelListener mDefaultChannelListener = new ChannelListener() {
#Override
public void onMessageAdded(final Message message) {
Log.i(TAG, "Message added");
ChatActivity.this.runOnUiThread(new Runnable() {
#Override
public void run() {
// need to modify user interface elements on the UI thread
mMessages.add(message);
mMessagesAdapter.notifyItemInserted(mMessages.size()-1);
}
});
}
#Override
public void onMessageUpdated(Message message, Message.UpdateReason updateReason) {
Log.i(TAG, "Message updated: " + message.getMessageBody());
}
#Override
public void onMessageDeleted(Message message) {
Log.d(TAG, "Message deleted");
}
#Override
public void onMemberAdded(Member member) {
Log.i(TAG, "Member added: " + member.getIdentity());
}
#Override
public void onMemberUpdated(Member member, Member.UpdateReason updateReason) {
}
#Override
public void onMemberDeleted(Member member) {
}
#Override
public void onTypingStarted(Channel channel, Member member) {
}
#Override
public void onTypingEnded(Channel channel, Member member) {
}
#Override
public void onSynchronizationChanged(Channel channel) {
}
};
Can someone please explain to me, what am I doing wrong or what should be the correct way of doing things? Thanks in advance!
Twilio developer evangelist here.
You need to check the channel's status for your current user, using channel.getStatus(). There's a good example of this in the Android chat tutorial.
if (this.currentChannel.getStatus() == Channel.ChannelStatus.JOINED) {
// already in the channel, load the messages
} else {
// join the channel
}
i have integrated quickblox android SDk in my app and there are more than 500 dialogs group in list and when i try to join any group chat room, I am not getting entered in either of onSuccess() and onError() ,control flow just goes bypassing callback methods by using below code.
qbChatDialog.initForChat(QBChatService.getInstance());
qbChatDialog.addMessageListener(chatMessageListener);
DiscussionHistory discussionHistory = new DiscussionHistory();
discussionHistory.setMaxStanzas(0);
if (!qbChatDialog.isJoined()) {
qbChatDialog.join(discussionHistory, new QBEntityCallback() {
#Override
public void onSuccess(Object o, Bundle bundle) {
if (qbChatDialog != null) {
getMessage(qbChatDialog, false);
}
}
#Override
public void onError(QBResponseException e) {
Log.e("QB Join", e.toString());
Toast.makeText(QBChatActivity.this, "" + e.toString(), Toast.LENGTH_LONG).show();
}
});
} else {
if (qbChatDialog != null) {
getMessage(qbChatDialog, false);
}
}
I think the problem is Group type .
if you want to create a public group which anyone can join then you should create with QBDialogType.PUBLIC_GROUP.
In case of QBDialogType.GROUP participants should be add at the time of creation and only those participants can join the group which were added .
Solution is create your dialog with type QBDialogType.PUBLIC_GROUP if you want it to public .
QBChatDialog qbChatDialog=new QBChatDialog();
qbChatDialog.setType(QBDialogType.PUBLIC_GROUP);// For public group
qbChatDialog.setType(QBDialogType.GROUP);// For private group
I am trying to create a simple android app that controls my robot. All the communication is done using mqtt and eclipse paho for android, but I am very new to the protocol. I cannot find a simple explanation of how to get data from a subscribed topic. The best one I found was HiveMQ android tutorial
but that did not explain how to get the data from the callbacks. Any assistance would be appreciated.
For android I have used Paho Android project, very simple to use, here are the steps:
Intialize a client, set required options and connect.
MqttAndroidClient mqttClient = new MqttAndroidClient(BaseApplication.getAppContext(), broker, MQTT_CLIENT_ID);
//Set call back class
mqttClient.setCallback(new MqttCallbackHandler(BaseApplication.getAppContext()));
MqttConnectOptions connOpts = new MqttConnectOptions();
IMqttToken token = mqttClient.connect(connOpts);
Subscribe to a topic.
token.setActionCallback(new IMqttActionListener() {
#Override
public void onSuccess(IMqttToken arg0) {
mqttClient.subscribe("TOPIC_NAME" + userId, 2, null, new IMqttActionListener() {
#Override
public void onSuccess(IMqttToken asyncActionToken) {
Log.d(LOG_TAG, "Successfully subscribed to topic.");
}
#Override
public void onFailure(IMqttToken asyncActionToken, Throwable exception) {
Log.d(LOG_TAG, "Failed to subscribed to topic.");
}
});
}
#Override
public void onFailure(IMqttToken arg0, Throwable arg1) {
Log.d(LOG_TAG, errorMsg);
}
});
Define your callback handler class.
public class MqttCallbackHandler implements MqttCallbackExtended {
#Override
public void connectComplete(boolean b, String s) {
Log.w("mqtt", s);
}
#Override
public void connectionLost(Throwable throwable) {
}
#Override
public void messageArrived(String topic, MqttMessage mqttMessage) throws Exception {
Log.w("Anjing", mqttMessage.toString());
}
#Override
public void deliveryComplete(IMqttDeliveryToken iMqttDeliveryToken) {
}
}
Also set following in manifest file.
<service android:name="org.eclipse.paho.android.service.MqttService" >
</service>
Would recommend visiting their project on GitHub and going through samples online.
Eclipse Paho Android
Hoping this helps. If you have more questions please visit
Android step by step guide using Eclipse Paho
Cheers !
i'm using smack 4.1 library where i'm unable to revived message event.
here is my code-
Chat chat = connection.getChatManager().createChat("user2#openfireserver", new MessageListener() {
#Override
public void processMessage(Chat arg0, Message arg1) {
System.out.println(arg1.getBody());
}
});
chat.sendMessage("test message");
debug report-
<message id="WrfOv-14" to="user1#openfireserver/Smack" from="user2#openfireserver/Smack" type="chat"><body>my test application</body><thread>56b1a75c-69a5-4a12-b12a-d24e072a2ce7</thread></message>
receive chat show in debug but not getting event in processMessage method.
(may my question is duplicate but i'm not find relevant answer)
I have used Smack 4.1 library in one of my Android projects. The following code snippet worked for me.
ChatManager.getInstanceFor(connection).addChatListener(new ChatManagerListener() {
#Override
public void chatCreated(Chat chat, boolean createdLocally) {
chat.addMessageListener(new ChatMessageListener() {
#Override
public void processMessage(Chat chat, Message message) {
if (message.getType() == Message.Type.chat || message.getType() == Message.Type.normal) {
if(message.getBody()!=null) {
Toast.makeText(this,message.getFrom() + " : " + message.getBody(),Toast.LENGTH_LONG).show();
}
}
}
});
}
});
Here is an example for smack-4.1.0-beta3-SNAPSHOT-2015-02-09:
It works for me, try it.
private void onAutthenticated() {
ChatManager.getInstanceFor(mConnection).addChatListener(ChatConnection.this);
}
#Override
public void chatCreated(Chat chat, boolean b) {
chat.addMessageListener(new ChatMessageListener() {
#Override
public void processMessage(Chat chat, Message message) {
if (message.getType().equals(Message.Type.chat) || message.getType().equals(Message.Type.normal)) {
Log.d(TAG, message.getFrom());
Log.d(TAG, message.getBody());
}
}
});
}
For Receiving any Type of Message, you can use following code
StanzaTypeFilter message_filter = new StanzaTypeFilter(Message.class);
connection.addSyncStanzaListener(new StanzaListener() {
#Override
public void processPacket(Stanza packet) throws NotConnectedException {
Message message = (Message)packet;
if(message.getType() == Message.Type.chat) {
//single chat message
} else if(message.getType() == Message.Type.groupchat) {
//group chat message
} else if(message.getType() == Message.Type.error) {
//error message
}
}
}, message_filter);
I think the create methord and the add methord are not same. create methord does not register a listener,but the add methord does register.When I see the api doc, I have the same question with you,but the doc does not give me an answer.So i guess this may be where the problem exists.