List chat messages QuickBlox History Message - android

It is possible to load all history message according to custom parameter.
Currently we set a according to setPageLimit. But i want to use a custom parameter. . Custom parameter is sh_id,sh_r_id,customer_id, date
private void loadHistory(String dialogId){
QBDialog qbDialog = new QBDialog(dialogId);
QBRequestGetBuilder customObjectRequestBuilder = new QBRequestGetBuilder();
customObjectRequestBuilder.setPagesLimit(150);
QBChatService.getDialogMessages(qbDialog, customObjectRequestBuilder, new QBEntityCallbackImpl<ArrayList<QBChatHistoryMessage>>() {
#Override
public void onSuccess(ArrayList<QBChatHistoryMessage> messages, Bundle args) {
try {
qbShopAdpt = new QBShopkeeperChatAdapter(mContext, new ArrayList<QBMessage>(),customer_id,sh_r_id1);
qbchatlv.setAdapter(qbShopAdpt);
for(QBMessage msg : messages) {
if(customer_id.equals(msg.getProperty("customer_id")) && sh_r_id1.equals(msg.getProperty("sh_r_id")) && SessionManager.getSignIn(mContext).getId()==Integer.valueOf(msg.getProperty("sh_id"))){
showMessage(msg);
}
}
} catch (NullPointerException e) {
Log.e(Tag, e.toString());
}catch (NumberFormatException e) {
Log.e(Tag, e.toString());
}catch (Exception e) {
Log.e(Tag, e.toString());
}
hideProgress();
}
#Override
public void onError(List<String> errors) {
AlertDialog.Builder dialog = new AlertDialog.Builder(mContext);
dialog.setMessage("load chat history errors: " + errors).create().show();
}
});
}

Try by this code for save chat may be this i am not shure
QBChatMessage chatMessage = new QBChatMessage();
chatMessage.setProperty("save_to_history", "1");
get chat by this
QBDialog qbDialog = new QBDialog("53cfc593efa3573ebd000017");
QBRequestGetBuilder requestBuilder = new QBRequestGetBuilder();
requestBuilder.setPagesLimit(100);
QBChatService.getDialogMessages(qbDialog, customObjectRequestBuilder, new
QBEntityCallbackImpl<ArrayList<QBChatMessage>>() {
#Override
public void onSuccess(ArrayList<QBChatMessage> messages, Bundle args) {
}
#Override
public void onError(List<String> errors) {
}
});
Try By this code it may be help you try by this link.
Here is Link

Related

android janus webrtc ondatachannel not triggered

i have made Janus videoroom work normally, now i want to implement DataChannel to send message to each other between devices
i have set data:true when publisher send configure and subscriber join
void sendLocalDescription(BigInteger handleId, JSONObject sdpObj) {
try {
JSONObject msg = new JSONObject();
JSONObject body = new JSONObject();
body.put(REQUEST, BodyRequestMessageType.CONFIGURE.getType());
body.put(AUDIO, options.audio);
body.put(VIDEO, options.video);
body.put(DATA, true);
msg.put(JANUS, SendMessageType.MESSAGE.getType());
msg.put(TRANSACTION, RandomUtil.randomString());
msg.put(SESSION_ID, sessionId);
msg.put(HANDLE_ID, handleId);
msg.put(BODY, body);
msg.put(JESP, sdpObj);
connection.sendMessage(msg.toString());
Log.e(SERVER_TAG, "publisher sendLocalDescription: " + body.toString());
} catch (JSONException e) {
e.printStackTrace();
}
}
and here is for subscriber
private void sendSubscribeMessage() {
try {
JSONObject object = new JSONObject();
object.put(JANUS, SendMessageType.MESSAGE.getType());
object.put(PLUGIN, PLUGIN_VALUE);
object.put(TRANSACTION, RandomUtil.randomString());
object.put(SESSION_ID, sessionId);
object.put(HANDLE_ID, handleId);
JSONObject body = new JSONObject();
body.put(REQUEST, BodyRequestMessageType.JOIN.getType());
body.put(PTYPE, PType.SUBSCRIBER.getType());
body.put(ROOM, options.meetNum);
body.put(PIN, options.pin);
body.put(PRIVATE_ID, privateId);
body.put(FEED, publisherBean.getId());
body.put(DATA, true);
body.put(OFFER_DATA, true);
object.put(BODY, body);
connection.sendMessage(object.toString());
if(publisherBean.isSumulcast()){
sendConfigureSimulcastMessage();
}
} catch (JSONException e) {
e.printStackTrace();
}
}
after create peerconnection for publisher, i have create datachannel:
peerConnection = PCFactoryProxy.instance().createPeerConnection(configuration, this);
dataChannel = peerConnection.createDataChannel("1", new DataChannel.Init());
dataChannel.registerObserver(new DataChannel.Observer() {
#Override
public void onBufferedAmountChange(long l) {
}
#Override
public void onStateChange() {
Log.e(SERVER_TAG, "dataChannel state: " + dataChannel.state().toString());
}
#Override
public void onMessage(DataChannel.Buffer buffer) {
}
});
but i never see onDataChannel triggered, can someone help?
#Override
public void onDataChannel(DataChannel dataChannel) {
LogUtil.e(SERVER_TAG, "PeerConnectionChannelV3 -> onDataChannel: " + dataChannel.label());
this.dataChannel = dataChannel;
// this.dataChannel.registerObserver(this);
// sendDataChannelMessage("test");
}
as i know about DataChannel, when Peer A already has datachannel object, Peer B would receive the datachannel when onDataChannel would be triggered

Sendbird group channel

Currently i have 2 users:
Tester1 and AnotherTester
I've been trying to create a public group channel using my Tester1
but whenever i try to create one.
It's not showing in my list using AnotherTester
Here is my code in creating public group channel
GroupChannelParams params = new GroupChannelParams()
.setPublic(true)
.setDiscoverable(true)
.setEphemeral(false)
// .addUserIds(users)
.setDistinct(false)
.setName(channelName);
GroupChannel.createChannel(params, new GroupChannel.GroupChannelCreateHandler() {
#Override
public void onResult(GroupChannel groupChannel, SendBirdException e) {
if (e != null) { // Error.
Toast.makeText(context, "" + e.getMessage(), Toast.LENGTH_SHORT).show();
Logs.logError(e.getMessage());
retrySendConnection(context, String.valueOf(e.getCode()), e.getMessage());
return;
} else {
// inviteUser(groupChannel);
Logs.logData(groupChannel.getUrl());
Intent i = new Intent(MainActivity.this, channelChatActivity.class);
i.putExtra("channelUrl", groupChannel.getUrl());
startActivity(i);
}
}
});
So Tester1 is the one that created a public group channel
but when i switch to AnotherTester, it doesn't show the public group channel.
Here is my code in retrieving AnotherTester channels
GroupChannelListQuery channelListQuery1 = GroupChannel.createMyGroupChannelListQuery();
channelListQuery1.setIncludeEmpty(true);
channelListQuery1.next(new GroupChannelListQuery.GroupChannelListQueryResultHandler() {
#Override
public void onResult(List<GroupChannel> list, SendBirdException e) {
if (e != null) {
Logs.logError(e.getMessage());// Error.
return;
} else {
groupChannelList.addAll(list);
groupChannelAdapter = new groupChannelAdapter(context, groupChannelList);
initializeRecyclerView(channelAdapter);
}
}
});
i hope you can help me.
You need to do atleast one message in that , then it will show to another user. Please try once to send one message.
Please try this code :-
private void createGroupChannel(List<String> userIds, boolean distinct, final String toID) {
GroupChannel.createChannelWithUserIds(userIds, distinct, "tsg-chat-" + SessionUtils.getCurrentMemberId(this) + "-" + toID, "", "", new GroupChannel.GroupChannelCreateHandler() {
#Override
public void onResult(GroupChannel groupChannel, SendBirdException e) {
if (e != null) {
// Error!
return;
}
}
});
}

IBM Watson Tone Analyzer Gives Empty Response

I am using Tone Analyzer of IBM Watson in my Android Code,but i keep getting java.lang.NullPointerException: Attempt to invoke interface method 'java.lang.Object java.util.List.get(int)' on a null object reference
Following is my code
public class MainActivity extends AppCompatActivity {
final ToneAnalyzer toneAnalyzer =
new ToneAnalyzer("2018-01-19");
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
JSONObject credentials = null; // Convert the file into a JSON object
try {
credentials = new JSONObject(IOUtils.toString(
getResources().openRawResource(R.raw.credentials), "UTF-8"
));
String username = credentials.getString("username");
String password = credentials.getString("password");
toneAnalyzer.setUsernameAndPassword(username, password);
} catch (JSONException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
Button analyzeButton = (Button)findViewById(R.id.analyze_button);
analyzeButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
EditText userInput = (EditText)findViewById(R.id.user_input);
final String textToAnalyze = userInput.getText().toString();
ToneOptions options = new ToneOptions.Builder()
.addTone(Tone.EMOTION)
.html(false).build();
toneAnalyzer.getTone(textToAnalyze, options).enqueue(
new ServiceCallback<ToneAnalysis>() {
#Override
public void onResponse(ToneAnalysis response) {
Log.i("Hii", "onResponse: "+response.getDocumentTone());
List<ToneScore> scores = response.getDocumentTone()
.getTones()
.get(0)
.getTones();
String detectedTones = "";
for(ToneScore score:scores) {
if(score.getScore() > 0.5f) {
detectedTones += score.getName() + " ";
}
}
final String toastMessage =
"The following emotions were detected:\n\n"
+ detectedTones.toUpperCase();
runOnUiThread(new Runnable() {
#Override
public void run() {
Toast.makeText(getBaseContext(),
toastMessage, Toast.LENGTH_LONG).show();
}
});
}
#Override
public void onFailure(Exception e) {
e.printStackTrace();
}
});
}
});
}
}
Can somebody point out what am i doing wrong. I have kept my credentials.json file in raw folder.
I tried writing every emotion in my Android App but i keep getting no response. Any help would be greatly appreciated.

AsyncHttpPost force close when there is not internet

I used fragment in my application and when there is not internet app getting force close . I don't know what can I do . please help me
this code works perfect but when internet lost the application get error and force close
i use method to check internet by ping but it makes my app too slow
public static void get_detail(final int pages){
MainActivity.logo11.setImageResource(R.drawable.loading);
AsyncHttpPost post = new AsyncHttpPost(
"domain"
);
post.setTimeout(30000);
MultipartFormDataBody body = new MultipartFormDataBody();
body.addStringPart("City",MainActivity.sp.getString("City",null));
body.addStringPart("Cate","all");
body.addStringPart("Page", String.valueOf(pages));
post.setBody(body);
AsyncHttpClient.getDefaultInstance().executeString(post, new AsyncHttpClient.StringCallback() {
#Override
public void onCompleted(final Exception e, AsyncHttpResponse source, final String result) {
if(e != null){
MainActivity.activity.runOnUiThread(new Runnable() {
#Override
public void run() {
Toast.makeText(MainActivity.activity,"network error",Toast.LENGTH_LONG).show();
refresh.setRefreshing(false);
e.printStackTrace();
}
});
}
if(!result.equals("")){
MainActivity.activity.runOnUiThread(new Runnable() {
#Override
public void run() {
MainActivity.logo11.setImageResource(R.drawable.logo);
if(page==0){
hash_all.clear();
}
items.clone();
try {
JSONArray jsonArray = new JSONArray(result);
for (int i = 0 ;i<jsonArray.length();i++){
JSONObject object = jsonArray.getJSONObject(i);
HashMap<String , Object> hash_add = new HashMap<String, Object>();
hash_add.put("ID",object.getString("ID"));
hash_add.put("Username",object.getString("Username"));
hash_add.put("Title",object.getString("Title"));
hash_add.put("Descript",object.getString("Descript"));
hash_all.add(hash_add);
items = new String[hash_all.size()];
}
ad.notifyDataSetChanged();
refresh.setRefreshing(false);
}catch (Exception e){
e.printStackTrace();
}
}
});
}else {
Toast.makeText(MainActivity.activity,"error",Toast.LENGTH_LONG).show();
}
}
});
}

Image is not attached in quickblox for android

I have made a demo for sending image to private chat using QuickBlox, I am struggling to attach an image with the chat message, I have gone through its document and have used the below Links, with no luck
Attach an image
My code is as below:
chatMessage = new QBChatMessage();
sendButton = (Button) findViewById(R.id.chatSendButton);
sendButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
final String messageText = messageEditText.getText().toString();
if (TextUtils.isEmpty(messageText)) {
return;
}
// Send chat message
//
// send a message
// ...
int fileId = R.raw.ic_launcher;
InputStream is = ChatActivity.this.getResources()
.openRawResource(fileId);
File file = FileHelper.getFileInputStream(is,
"sample_file.png", "myFile");
Boolean fileIsPublic = true;
QBContent.uploadFileTask(file, fileIsPublic, messageText,
new QBEntityCallbackImpl<QBFile>() {
#Override
public void onSuccess(QBFile qbFile, Bundle params) {
String publicUrl = qbFile.getPublicUrl();
System.out
.println("==========image uploaded success++++++++"
+ publicUrl);
id = qbFile.getId();
System.out
.println("===================image id+++++++++++"
+ id + "");
}
#Override
public void onError(List<String> errors) {
System.out
.println("==========image uploaded Errors++++++++"
+ errors.toString());
}
}, new QBProgressCallback() {
#Override
public void onProgressUpdate(int progress) {
}
});
QBAttachment atach = new QBAttachment("image");
atach.setId(id+"");
ArrayList<QBAttachment> aryatch = new ArrayList<QBAttachment>();
aryatch.add(atach);
chatMessage.setAttachments(aryatch);
chatMessage.setBody(messageText);
chatMessage.setProperty(PROPERTY_SAVE_TO_HISTORY, "1");
chatMessage.setDateSent(new Date().getTime() / 1000);
try {
chat.sendMessage(chatMessage);
} catch (XMPPException e) {
Log.e(TAG, "failed to send a message", e);
} catch (SmackException sme) {
Log.e(TAG, "failed to send a message", sme);
}
messageEditText.setText("");
if (dialog.getType() == QBDialogType.PRIVATE) {
showMessage(chatMessage);
}
}
});
Well it clear where the mistake is
your id is null here
atach.setId(id+"");
because it will != nil only in onSuccess block of uploadFileTask
So the right way is to forward all attachments logic inside onSuccess block of uploadFileTask
Because these QuickBlox request are asynchronous

Categories

Resources