Quickblox-android join chat group is not working - android

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

Related

Get user status using PubNub

I have created an application that implements app to app calling using Sinch. It works only when the caller knows the name of the recipient.
To overcome this Sinch suggested to use PubNub to get the user state. They also have a tutorial here. The problem is that tutorial is old and PubNub has updated their API since. I tried to implement the functionality using their new API on my own using their docs, but it is not working or more accurately I don't know how to do it.
My current code is:
public class LoggedUsers extends Activity {
private PubNub pubNub;
String name;
private ArrayList users;
private JSONArray loggedUserList;
ListView UserList;
TextView allUsers;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.user_list);
allUsers = (TextView) findViewById(R.id.JSONFromPubNub);
SharedPreferences sp = getSharedPreferences("User_Details", MODE_APPEND);
try {
name = sp.getString("UserName", "");
} catch (NullPointerException e) {
}
final PNConfiguration pnc = new PNConfiguration();
pnc.setPublishKey("publish key");
pnc.setSubscribeKey("subscribe key");
pnc.setUuid(name);
pubNub = new PubNub(pnc);
users = new ArrayList<String>();
UserList = (ListView) findViewById(R.id.listView);
String user = getUserStatus();
allUsers.setText(user);
final ArrayAdapter adapter = new ArrayAdapter(getApplicationContext(), R.layout.single_item_list, users);
UserList.setAdapter(adapter);
pubNub.addListener(new SubscribeCallback() {
#Override
public void status(PubNub pubnub, PNStatus status) {
if (status.getCategory() == PNStatusCategory.PNUnexpectedDisconnectCategory) {
// This event happens when radio / connectivity is lost
HashMap <String,String> map = new HashMap();
map.put("State","Offline");
pubNub.setPresenceState().channels(Arrays.asList("CallingChannel1")).state(map).uuid(pnc.getUuid());
} else if (status.getCategory() == PNStatusCategory.PNConnectedCategory) {
// Connect event. You can do stuff like publish, and know you'll get it.
// Or just use the connected event to confirm you are subscribed for
// UI / internal notifications, etc
HashMap <String,String> map = new HashMap();
map.put("State","Online");
pubNub.setPresenceState().channels(Arrays.asList("CallingChannel1")).state(map).uuid(pnc.getUuid());
/* if (status.getCategory() == PNStatusCategory.PNConnectedCategory) {
pubnub.publish().channel("awesomeChannel").message("hello!!").async(new PNCallback<PNPublishResult>() {
#Override
public void onResponse(PNPublishResult result, PNStatus status) {
// Check whether request successfully completed or not.
if (!status.isError()) {
// Message successfully published to specified channel.
}
// Request processing failed.
else {
// Handle message publish error. Check 'category' property to find out possible issue
// because of which request did fail.
//
// Request can be resent using: [status retry];
}
}
});
}*/
} else if (status.getCategory() == PNStatusCategory.PNReconnectedCategory) {
HashMap <String,String> map = new HashMap();
map.put("State","Online");
pubNub.setPresenceState().channels(Arrays.asList("CallingChannel1")).state(map).uuid(pnc.getUuid());
// Happens as part of our regular operation. This event happens when
// radio / connectivity is lost, then regained.
} else if (status.getCategory() == PNStatusCategory.PNDecryptionErrorCategory) {
// Handle messsage decryption error. Probably client configured to
// encrypt messages and on live data feed it received plain text.
}
}
#Override
public void message(PubNub pubnub, PNMessageResult message) {
}
#Override
public void presence(PubNub pubnub, PNPresenceEventResult presence) {
}
});
}
public String getUserStatus(){
final StringBuilder allUsers = new StringBuilder();
pubNub.subscribe().channels(Arrays.asList("CallingChannel1")).withPresence().execute();
pubNub.hereNow()
// tailor the next two lines to example
.channels(Arrays.asList("CallingChannel1"))
.includeState(true)
.includeUUIDs(true)
.async(new PNCallback<PNHereNowResult>() {
#Override
public void onResponse(PNHereNowResult result, PNStatus status) {
if (status.isError()) {
// handle error
return;
}
for (PNHereNowChannelData channelData : result.getChannels().values()) {
allUsers.append("---");
allUsers.append("channel:" + channelData.getChannelName());
allUsers.append("occoupancy: " + channelData.getOccupancy());
allUsers.append("occupants:");
for (PNHereNowOccupantData occupant : channelData.getOccupants()) {
allUsers.append("uuid: " + occupant.getUuid() + " state: " + occupant.getState());
}
}
}
});
return allUsers.toString();
}
#Override
protected void onResume() {
super.onResume();
}
}
Here are my problems:
I am trying to display all the data that I receive in a textview (later it will arranged in a listview or a recycler view) but I am getting a blank screen so I am getting null from the server.
The user status should be constantly updated to know if the user changes state (online -> offline) but there seems to be no async calls made in the code so I think it will be executed only once and then the dataset is not being changed.
How can I solve my problems?
PubNub Presence
You can monitor online and state changes using PubNub Presence. When you subscribe, subscribe with presence enabled and you will get state-change, join, leave & timeout events in the presence callback.
Callback callback = new Callback() {
#Override
public void successCallback(String channel, Object message) {
System.out.println(channel + " : "
+ message.getClass() + " : " + message.toString());
// take action on the presence events here
}
#Override
public void connectCallback(String channel, Object message) {
System.out.println("CONNECT on channel:" + channel
+ " : " + message.getClass() + " : "
+ message.toString());
}
#Override
public void disconnectCallback(String channel, Object message) {
System.out.println("DISCONNECT on channel:" + channel
+ " : " + message.getClass() + " : "
+ message.toString());
}
#Override
public void reconnectCallback(String channel, Object message) {
System.out.println("RECONNECT on channel:" + channel
+ " : " + message.getClass() + " : "
+ message.toString());
}
#Override
public void errorCallback(String channel, PubnubError error) {
System.out.println("ERROR on channel " + channel
+ " : " + error.toString());
}
};
try {
pubnub.presence("my_channel", callback);
}
catch (PubnubException e) {
System.out.println(e.toString());
}
It appears Sinch is using a rather old version of the PubNub Android SDK. I would think you could still use PubNub Android SDK v4 to do what you need to do outside of Sinch SDK unless there is some explicit requirements by Sinch to use the same version of the SDK.

registration-required(407) Error Quickblox android

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");
}
};

Role ACL doesn't work using Parse's Android Local Datastore:

The issue is straightforward:
Create a user and add it to a role
Create an object and give it role ACL
The user will be able to find and pin the object, however, the object cannot be retrieved from the local datastore. If I switch to user or public ACL, the object is retrieved.
Example:
public void findAndPinInBackground(ParseQuery<ParseObject> query, final MyCallback callback) {
query.findInBackground(new FindCallback<ParseObject>() {
public void done(final List<ParseObject> eventList, ParseException e) {
if (e == null) {
ParseObject.pinAllInBackground(eventList, new SaveCallback() {
#Override
public void done(ParseException e) {
if (e == null) {
Log.d(TAG, "Pinned " + eventList.size() + " objects");
callback.onTaskCompleted();
} else {
callback.onTaskFailed(e);
}
}
});
} else {
callback.onTaskFailed(e);
}
}
});
}
Log: "Pinned 1 objects"
ParseQueryAdapter<ParseObject> eventsAdapter = new ParseQueryAdapter<ParseObject>(getActivity(), new ParseQueryAdapter.QueryFactory<ParseObject>() {
public ParseQuery<ParseObject> create() {
ParseQuery query = new ParseQuery("Event");
query.orderByAscending("name");
query.fromLocalDatastore();
return query;
}
}, android.R.layout.simple_list_item_1);
eventsAdapter.addOnQueryLoadListener(new ParseQueryAdapter.OnQueryLoadListener<ParseObject>() {
#Override
public void onLoading() { }
#Override
public void onLoaded(List<ParseObject> parseObjects, Exception e) {
Log.d(TAG, "Retrieved " + parseObjects.size() + " objects");
}
});
Log: "Retrieved 0 objects"
Facebook has confirmed this is a known bug.
Is there a workaround?
The iOS documentation now mentions this:
To access this data protected by Role based ACLs, you will need to
ignore ACLs when executing a Local Datastore query:
PFQuery *query = [[[PFQuery queryWithClassName:#"Note"]
fromLocalDatastore]
ignoreACLs];
https://parse.com/docs/ios/guide#local-datastore-security
It seems the same applies to Android, which has the ignoreACLs in the API:
public ParseQuery<T> ignoreACLs()
Ignore ACLs when querying from the Local Datastore.
This is particularly useful when querying for objects with Role based
ACLs set on them.
https://parse.com/docs/android/api/com/parse/ParseQuery.html#ignoreACLs%28%29
I also experience the same issue so what i did is the following:
Before you pin the object to the local data store do the following:
ParseACL acl = user.getACL();
// Read access only for the logged in user (not public!)
acl.setReadAccess(ParseUser.getCurrentUser(),true);
user.setACL(acl);
user.pinInBackground();
Hope it helps.

Getting Score of user from Google Play Game Service?

I am new to Android App development. I want to retrieve user's score from Google Play Game service and i am using following code to get the high score but i do not have any knowledge how it returns the value and how to save it.
Games.Leaderboards.loadCurrentPlayerLeaderboardScore(getApiClient(), getString(R.string.highscore), LeaderboardVariant.TIME_SPAN_ALL_TIME, LeaderboardVariant.COLLECTION_PUBLIC);
Saving it to int or string does not worked.
The complete parameters for loadCurrentPlayerLeaderboardScore is like below
Games.Leaderboards.loadCurrentPlayerLeaderboardScore(getApiClient(),
getString(R.string.word_attack_leaderboard),
LeaderboardVariant.TIME_SPAN_ALL_TIME,
LeaderboardVariant.COLLECTION_PUBLIC).setResultCallback(
new ResultCallback<LoadPlayerScoreResult>() {
#Override
public void onResult(LoadPlayerScoreResult arg0) {
LeaderboardScore c = arg0.getScore();
long score = c.getRawScore();
}
}
R.string.word_attack_leaderboard is leaderboards id which get from google play game service
The method:
loadCurrentPlayerLeaderboardScore (GoogleApiClient apiClient, String leaderboardId, int span, int leaderboardCollection)
returns
PendingResult<Leaderboards.LoadPlayerScoreResult>
Then you must use the getScore() method of the Leaderboards.LoadPlayerScoreResult class to get it.
Please see these links...
The loadCurrentPlayerLeaderboardScore method
The LoadPlayerScoreResult in the PendingResult
EDIT: Here's how you can use it.
Games.Leaderboards.loadCurrentPlayerLeaderboardScore().setResultCallback(new ResultCallback<LoadPlayerScoreResult>() {
#Override
public void onResult(LoadPlayerScoreResult arg0) {
LeaderboardScore c = arg0.getScore();
}
});
This is how you get the score.
4 years later I was having a similar problem with this situation. Some stuff has been deprecated and stuff no longer works. So for those of you who want to know how to do it now, in 2018... check this answer-
First you have to get the LeaderBoardClient with
mLeaderboardsClient = Games.getLeaderboardsClient(MainActivity.this, googleSignInAccount);
Next you can the score
mLeaderboardsClient.loadCurrentPlayerLeaderboardScore(getString(R.string.leaderboard_id), LeaderboardVariant.TIME_SPAN_ALL_TIME, LeaderboardVariant.COLLECTION_PUBLIC)
.addOnSuccessListener(this, new OnSuccessListener<AnnotatedData<LeaderboardScore>>() {
#Override
public void onSuccess(AnnotatedData<LeaderboardScore> leaderboardScoreAnnotatedData) {
long score = 0L;
if (leaderboardScoreAnnotatedData != null) {
if (leaderboardScoreAnnotatedData.get() != null) {
score = leaderboardScoreAnnotatedData.get().getRawScore();
Toast.makeText(MainActivity.this, Long.toString(score), Toast.LENGTH_SHORT).show();
Log.d(TAG, "LeaderBoard: " + Long.toString(score));
} else {
Toast.makeText(MainActivity.this, "no data at .get()", Toast.LENGTH_SHORT).show();
Log.d(TAG, "LeaderBoard: .get() is null");
}
} else {
Toast.makeText(MainActivity.this, "no data...", Toast.LENGTH_SHORT).show();
Log.d(TAG, "LeaderBoard: " + Long.toString(score));
}
}
})
.addOnFailureListener(new OnFailureListener() {
#Override
public void onFailure(#NonNull Exception e) {
Toast.makeText(MainActivity.this, "Failure", Toast.LENGTH_SHORT).show();
Log.d(TAG, "LeaderBoard: FAILURE");
}
});
The 3 parameters to .loadCurrentPlayerLeaderboardScore are as follows
ID of the leaderboard to load the score from.
Time span to retrieve data for. Valid values are TIME_SPAN_DAILY, TIME_SPAN_WEEKLY, or TIME_SPAN_ALL_TIME.
The leaderboard collection to retrieve scores for. Valid values are either COLLECTION_PUBLIC or COLLECTION_SOCIAL.

Windows Azure Website Communicate with Android Device

Requirement of project: communication between windows azure Website and android device using azure mobile services
1)Website is build in VB.NET using Microsoft Windows Azure (server side)
2)Android Application is on Android Device (client side)
The client (Android user) should be able to send data from android device (client side) to Website (Server side) and vice-versa To make this possible i.e. Communcation Between client and sever I am using Mobile Services provided by Microsoft Windows Azure (server side) which use GCM (Google Cloud Messaging)
I have Followed all steps according to the documentation
http://www.windowsazure.com/en-us/develop/mobile/tutorials/get-started-with-push-android/
Also followed all steps as been provided in the above link documentation of Microsoft windows azure
but when I try to send message from Android device towards the website the following error occurs
Error: com.microsoft.windowsazure.mobileservices.MobileServiceException: Error while processing request
Note: GCM (Google Cloud Messaging) gives us an gcm.jar file which is used in the android app to send data towards Server i.e website
ONCREATE CODE
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_to_do);
GCMRegistrar.checkDevice(this);
GCMRegistrar.checkManifest(this);
mRegistationId = GCMRegistrar.getRegistrationId(this);
if (mRegistationId.equals("")) {
GCMRegistrar.register(this, SENDER_ID);
}
mProgressBar = (ProgressBar) findViewById(R.id.loadingProgressBar);
// Initialize the progress bar
mProgressBar.setVisibility(ProgressBar.GONE);
try {
// Create the Mobile Service Client instance, using the provided
// Mobile Service URL and key
mClient = new MobileServiceClient(
"url of website",
"POBHgxwAktyxUdeRRpcFyqEcsppwiS99",
this).withFilter(new ProgressFilter());
// Get the Mobile Service Table instance to use
mToDoTable = mClient.getTable(ToDoItem.class);
mTextNewToDo = (EditText) findViewById(R.id.textNewToDo);
// Create an adapter to bind the items with the view
mAdapter = new ToDoItemAdapter(this, R.layout.row_list_to_do);
ListView listViewToDo = (ListView) findViewById(R.id.listViewToDo);
listViewToDo.setAdapter(mAdapter);
// Load the items from the Mobile Service
refreshItemsFromTable();
}
catch (MalformedURLException e) {
createAndShowDialog(new Exception("There was an error creating the Mobile Service. Verify the URL"), "Error");
}
}
On BUTTON click event addItem() is called
public void addItem(View view) {
if (mClient == null) {
return;
}
try
{
// Create a new item
ToDoItem item = new ToDoItem();
item.setText(mTextNewToDo.getText().toString());
item.setComplete(false);
// Insert the new item
mToDoTable.insert(item, new TableOperationCallback<ToDoItem>() {
public void onCompleted(ToDoItem entity, Exception exception, ServiceFilterResponse response) {
if (exception == null) {
if (!entity.isComplete()) {
mAdapter.add(entity);
}
} else {
createAndShowDialog(exception, "Error");
}
}
});
item.setRegistrationId(mRegistationId.equals("") ?
GCMIntentService.getRegistrationId() : mRegistationId);
mTextNewToDo.setText("");
}
catch(Exception ex)
{
}
}
public void checkItem(ToDoItem item) {
if (mClient == null) {
return;
}
// Set the item as completed and update it in the table
item.setComplete(true);
mToDoTable.update(item, new TableOperationCallback<ToDoItem>() {
public void onCompleted(ToDoItem entity, Exception exception, ServiceFilterResponse response) {
if (exception == null) {
if (entity.isComplete()) {
mAdapter.remove(entity);
}
} else {
createAndShowDialog(exception, "Error");
}
}
});
}
private void refreshItemsFromTable() {
// Get the items that weren't marked as completed and add them in the
// adapter
mToDoTable.where().field("complete").eq(val(false)).execute(new TableQueryCallback<ToDoItem>() {
public void onCompleted(List<ToDoItem> result, int count, Exception exception, ServiceFilterResponse response) {
if (exception == null) {
mAdapter.clear();
for (ToDoItem item : result) {
mAdapter.add(item);
}
} else {
createAndShowDialog(exception, "Error");
}
}
});
}
private void createAndShowDialog(Exception exception, String title) {
createAndShowDialog(exception.toString(), title);
}
private void createAndShowDialog(String message, String title) {
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage(message);
builder.setTitle(title);
builder.create().show();
}
private class ProgressFilter implements ServiceFilter {
#Override
public void handleRequest(ServiceFilterRequest request, NextServiceFilterCallback nextServiceFilterCallback,
final ServiceFilterResponseCallback responseCallback) {
runOnUiThread(new Runnable() {
#Override
public void run() {
if (mProgressBar != null) mProgressBar.setVisibility(ProgressBar.VISIBLE);
}
});
nextServiceFilterCallback.onNext(request, new ServiceFilterResponseCallback() {
#Override
public void onResponse(ServiceFilterResponse response, Exception exception) {
runOnUiThread(new Runnable() {
#Override
public void run() {
if (mProgressBar != null) mProgressBar.setVisibility(ProgressBar.GONE);
}
});
if (responseCallback != null) responseCallback.onResponse(response, exception);
}
});
}
}
Figured out that the tutorial is using ' instead of ", which in my case was the problem. The issue was in the Insert script on azure. Hope it helps you :-)

Categories

Resources