4

I take reference from official website https://quickblox.com/developers/Android#Download_Android_SDK

gradle compile succeed:

    repositories {
            maven {
                url "https://github.com/QuickBlox/quickblox-android-sdk-releases/raw/master/"
            }
        }
            dependencies {
                 compile "com.quickblox:quickblox-android-sdk-core:2.5.1@aar"   
                 compile("com.quickblox:quickblox-android-sdk-chat:2.5.1@aar") {
                 transitive=true
            }
        }

then i use the code first:
I had the APP_ID...etc

    QBSettings.getInstance().init(getApplicationContext(), APP_ID, AUTH_KEY, AUTH_SECRET);

    QBSettings.getInstance().setAccountKey(ACCOUNT_KEY);

Second step : I reference Guide: Getting Started with Chat API https://quickblox.com/developers/Android_XMPP_Chat_Sample#Guide:_Getting_Started_with_Chat_API

//Prepare chat service
QBChatService.setDebugEnabled(true); // enable chat logging

        QBChatService.setDefaultPacketReplyTimeout(10000);//set reply timeout in milliseconds for connection's packet.
        //Can be used for events like login, join to dialog to increase waiting response time from server if network is slow.


        //configure chat socket
        QBChatService.ConfigurationBuilder chatServiceConfigurationBuilder = new QBChatService.ConfigurationBuilder();
        chatServiceConfigurationBuilder.setSocketTimeout(60); //Sets chat socket's read timeout in seconds
        chatServiceConfigurationBuilder.setKeepAlive(true); //Sets connection socket's keepAlive option.
        chatServiceConfigurationBuilder.setUseTls(true); //Sets the TLS security mode used when making the connection. By default TLS is disabled.

QBChatService.setConfigurationBuilder(chatServiceConfigurationBuilder);

It has a issue that i can't import QBChatService.ConfigurationBuilder so i try to change gradle to compile("com.quickblox:quickblox-android-sdk-chat:2.6.1")

now QBChatService.ConfigurationBuilder can be import

Third step: I take the official step use the code:

// Initialise Chat service
        final QBChatService chatService = QBChatService.getInstance();

        final QBUser user = new QBUser("garrysantos", "garrysantospass");

        QBAuth.createSession(user, new QBEntityCallback<QBSession>() {
            @Override
            public void onSuccess(QBSession qbSession, Bundle bundle) {

                // success, login to chat

                user.setId(qbSession.getUserId());

                chatService.login(user, new QBEntityCallback() {
                    @Override
                    public void onSuccess(Object o, Bundle bundle) {

                    }

                    @Override
                    public void onError(QBResponseException e) {

                    }
                });


            }

            @Override
            public void onError(QBResponseException e) {

            }
        });


        //To handle different connection states use ConnectionListener:
        ConnectionListener connectionListener = new ConnectionListener() {
            @Override
            public void connected(XMPPConnection xmppConnection) {

            }

            @Override
            public void authenticated(XMPPConnection xmppConnection, boolean b) {

            }

            @Override
            public void connectionClosed() {

            }

            @Override
            public void connectionClosedOnError(Exception e) {
                // connection closed on error. It will be established soon
            }

            @Override
            public void reconnectionSuccessful() {

            }

            @Override
            public void reconnectingIn(int i) {

            }

            @Override
            public void reconnectionFailed(Exception e) {

            }
        };

        QBChatService.getInstance().addConnectionListener(connectionListener);


        //logOut
        boolean isLoggedIn = chatService.isLoggedIn();
        if (!isLoggedIn) {
            return;
        }

        chatService.logout(new QBEntityCallback<Void>() {
            @Override
            public void onSuccess(Void aVoid, Bundle bundle) {
                //success
                chatService.destroy();
            }

            @Override
            public void onError(QBResponseException e) {

            }
        });

        //By default Android SDK reconnects automatically when connection to server is lost.
        //But there is a way to disable this and then manage this manually:
        QBChatService.getInstance().setReconnectionAllowed(false);

when i use the step about QBChatDialog , it can't be import again....

ArrayList<Integer> occupantIdsList = new ArrayList<Integer>();
        occupantIdsList.add(34);
        occupantIdsList.add(17);

        QBChatDialog dialog = new QBChatDialog();
        dialog.setName("Chat with Garry and John");
        dialog.setPhoto("1786");
        dialog.setType(QBDialogType.GROUP);
        dialog.setOccupantsIds(occupantIdsList);

//or just use DialogUtils
//for creating PRIVATE dialog
//QBChatDialog dialog = DialogUtils.buildPrivateDialog(recipientId);

//for creating GROUP dialog
        QBChatDialog dialog = DialogUtils.buildDialog("Chat with Garry and John", QBDialogType.GROUP, occupantIdsList);

        QBRestChatService.createChatDialog(dialog).performAsync(new QBEntityCallback<QBChatDialog>() {
            @Override
            public void onSuccess(QBChatDialog result, Bundle params) {

            }

            @Override
            public void onError(QBResponseException responseException) {

            }
        });

so i try to change gradle compile compile("com.quickblox:quickblox-android-sdk-chat:3.3.0")

now QBChatDialog can be imported.

but it has another issues...

Can't not resolve symbol 'QBSettings' and 'QBSession' 

I'm angry now , are you kidding me ?

Why the official step cheat me step by step ?

I'm tired... what should i do ?

Somebody can save me please , any help would be appreciated !

According @Jagapathi kindly responding , i update my code , the next issue is that i can't log in

My toast shows Login error when i click the login button:

private void setupQuickBlox() {
        QBSettings.getInstance().init(getApplicationContext(), APP_ID, AUTH_KEY, AUTH_SECRET);
        QBSettings.getInstance().setAccountKey(ACCOUNT_KEY);
        QBSettings.getInstance().setAutoCreateSession(true);

        //login to quickblox
        String enterAccount = editAccount.getText().toString();
        String enterPassword = editPassword.getText().toString();
        Log.d(TAG,enterAccount);
        Log.d(TAG,enterPassword);
        final QBUser user = new QBUser(enterAccount, enterPassword);
        //login
        QBUsers.signIn(user).performAsync(new QBEntityCallback<QBUser>() {
            @Override
            public void onSuccess(QBUser qbUser, Bundle bundle) {
                SharedPreferences.Editor s = getSharedPreferences("QBid", 0).edit();
                s.putString("id", user.getId().toString());
                s.apply();
                Log.d(TAG,user.getId().toString());
                Toast.makeText(MainActivity.this, "Login success with quickblox", Toast.LENGTH_SHORT).show();
            }

            @Override
            public void onError(QBResponseException e) {
                Toast.makeText(MainActivity.this, "Login error", Toast.LENGTH_SHORT).show();
            }
        });
    }

the code is under my onCreat , so it shows Login error when i satrt the app of course , but when i enter account and password , it still shows Login error , why? I check the log , i can see the account and password that i typed , but i can't see user.getId().toString() on my log , what step is wrong ? i check the account is correct: enter image description here

enter image description here

Here is my key:

static final String APP_ID = "50427";
    static final String AUTH_KEY = "naMGFKMshdLC3s4";
    static final String AUTH_SECRET = "GP8ey4GsQXt2TGu";
    static final String ACCOUNT_KEY = "dHYgix3we3bxxsvMqyuR";

Here is my test Account key: enter image description here

enter image description here

My button onClcik:

buttonLogin.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                setupQuickBlox();
            }
        });

Here is my log: enter image description here

enter image description here

Morton
  • 5,380
  • 18
  • 63
  • 118

1 Answers1

7

I can guide you with Quickblox I am in same position when I started using quickblox.

step 1:-

compile 'com.quickblox:quickblox-android-sdk-core:3.3.0@aar'
compile("com.quickblox:quickblox-android-sdk-chat:3.3.0@aar") {
    transitive = true
}

This is for latest version of quickblox. So don't use old versions .

step 2:-

This is my SetUp Quickblox function you don't forgot to use app_id Auth_key auth_secret and account_key

 private void SetupQuickBlox() {

    QBSettings.getInstance().init(getApplicationContext(), APP_ID, AUTH_KEY, AUTH_SECRET);
    QBSettings.getInstance().setAccountKey(ACCOUNT_KEY);
    QBSettings.getInstance().setAutoCreateSession(true);

    //login to quickblog for


    final QBUser user=new QBUser("USER_NAME OF USER","PASSWORD OF USER");
    // Login
    QBUsers.signIn(user).performAsync(new QBEntityCallback<QBUser>() {
        @Override
        public void onSuccess(QBUser user, Bundle args) {
            // success
            SharedPreferences.Editor s=getSharedPreferences("QBid",0).edit();
            s.putString("id",user.getId().toString());
            s.apply();
            Toast.makeText(HomeActivity.this, "Login succes with quickblox", Toast.LENGTH_SHORT).show();
        }

        @Override
        public void onError(QBResponseException error) {
            // error
        }
    });
}

step:- 3

You are all done Login with quickblox is successful so you can now request DIALOGS or CREATE DIALOg Sessions are automatically created in latest version.

Create New Dialog

private void NewMessage() {
    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            QBChatDialog dialog = DialogUtils.buildPrivateDialog("USER_ID of other user");
            dialog.setName("tester1");

            QBRestChatService.createChatDialog(dialog).performAsync(new QBEntityCallback<QBChatDialog>() {
                @Override
                public void onSuccess(QBChatDialog result, Bundle params) {

                }

                @Override
                public void onError(QBResponseException responseException) {

                }
            });
        }
    });
}

Request List Of Dialog Of Logged In User

I Used ListView And Dialogs result will be in array list which contains LIST of QBCHATDIALOG

private void receiveChatList() {
    QBRequestGetBuilder requestBuilder = new QBRequestGetBuilder();
    requestBuilder.setLimit(100);

    QBRestChatService.getChatDialogs(null, requestBuilder).performAsync(
            new QBEntityCallback<ArrayList<QBChatDialog>>() {
                @Override
                public void onSuccess(final ArrayList<QBChatDialog> result, Bundle params) {
                    int totalEntries = params.getInt("total_entries");
                    Log.wtf("chat",""+result);
                    TrumeMsgAdapter adapter=new TrumeMsgAdapter(TrueMeMessagesActivity.this,result);
                    chatlistView.setAdapter(adapter);
                    chatlistView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                        @Override
                        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                            startActivity(new Intent(TrueMeMessagesActivity.this,ChatingActivity.class).putExtra("dialog",result.get(position)));
                        }
                    });

                }
                @Override
                public void onError(QBResponseException responseException) {

                }
            });
}

My Adapter Code

public class TrumeMsgAdapter extends BaseAdapter {

private ArrayList<QBChatDialog> chatlist;
private Context context;

public TrumeMsgAdapter(Context c,ArrayList<QBChatDialog> chatlist){
    this.chatlist=chatlist;
    this.context=c;
}
@Override
public int getCount() {
    return chatlist.size();
}

@Override
public Object getItem(int position) {
    return null;
}

@Override
public long getItemId(int position) {
    return 0;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View List;
    LayoutInflater inflater = (LayoutInflater) context
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    if (convertView == null) {
        List = inflater.inflate(R.layout.trume_msg_adapter, null);
        TextView username=(TextView) List.findViewById(R.id.UserName);
        TextView lastmessage=(TextView)List.findViewById(R.id.lastmessage);
        username.setText(chatlist.get(position).getName());
        lastmessage.setText(chatlist.get(position).getLastMessage());
    } else {
        List = convertView;
        TextView username=(TextView) List.findViewById(R.id.UserName);
        TextView lastmessage=(TextView)List.findViewById(R.id.lastmessage);
        username.setText(chatlist.get(position).getName());
        lastmessage.setText(chatlist.get(position).getLastMessage());
    }

    return List;
}
}
halfer
  • 19,824
  • 17
  • 99
  • 186
jagapathi
  • 1,635
  • 1
  • 19
  • 32
  • Thank you so much ! There is no responding in recently days , i do not respect any more for help even though , i will try your step by step to figure our my issue , if i have any question that i will ask for your help again . Thanks @Jagapathi ! – Morton Mar 10 '17 at 09:02
  • Thanks for the upvote I added code upto getting chat dialogs For getting chat messages have any trouble i can help have a good day – jagapathi Mar 10 '17 at 09:22
  • Hi @Jagapathi , should i forget my step just follow your guide ? I can't log in , i update my issue . – Morton Mar 10 '17 at 10:06
  • all your keys are perfect? My Login code works perfect as i am working on quickblox chat two days back – jagapathi Mar 10 '17 at 10:40
  • u r using manual login then separate initialization and login with two different function – jagapathi Mar 10 '17 at 10:49
  • I think the key is correct , i update it , take a look please , and my button function call SetUpQuickBlox(); again , can you see that may be what's the issue ? – Morton Mar 10 '17 at 11:57
  • can u post the error here in comment just print E in Onerror function – jagapathi Mar 10 '17 at 12:02
  • E/error: com.quickblox.core.exception.QBResponseException: User's email unconfirmed this is the error – jagapathi Mar 10 '17 at 12:12
  • but there is no exception happen , do you mean that i should put the try-catch for QBResponseException ? – Morton Mar 10 '17 at 12:17
  • The request was well-formed but was unable to be followed due to validation errors. Possible causes: create a user with existent login or email. provide values in wrong format to create some object. create a another user for testing – jagapathi Mar 10 '17 at 12:18
  • i got it , i update it , the comments is it,take a look please ! – Morton Mar 10 '17 at 12:24
  • that means that should i key in user's email ? – Morton Mar 10 '17 at 12:25
  • Strange , i check the account , i had email for Rogan. – Morton Mar 10 '17 at 12:26
  • which user r u using for login ? Try to create seperate user with diffrent email and try – jagapathi Mar 10 '17 at 12:27
  • Ping me ur social site contact to discuss way to many comments here . – jagapathi Mar 10 '17 at 12:29
  • It's Rogan , his data that include three variables with Email、Login、Password , i also create a new user that is SteveNash , it's no working too. i update it on question , the social site that the account is Logan – Morton Mar 10 '17 at 12:38
  • @Jagapathi your answer is very useful after stuck in this chat documentation for 3 days, but I still stuck in some issues, If you kindly help me I will be very grateful for that. 1- if I need to create a new dialog and I don't have the other user Id, just I have it's email how to get user id? I tried to get it by API but I stuck in how to get QB-Token header. – Tefa Apr 15 '17 at 23:42