Am working on one android project. i stored the getting response in the ArrayList while parsing from the JsonArray. now i want just display the values to required text views.
Here am doing.
public void updateRedemptionRequestDetails(){
//Dismiss dialog
dlgProgress.dismiss();
// Get the status
String status=redemptionRequestDetailsResponse.getStatus();
if(status.equals("success")){
List<RedemptionRequestDetailsResource> redemptionRequestDetailsResource = redemptionRequestDetailsResponse.getData();
if(!redemptionRequestDetailsResource.isEmpty() && redemptionRequestDetailsResource.size()==0 ){
redemptionRequestDetailsResources.addAll(redemptionRequestDetailsResource);
populateRedemptionDetails(redemptionRequestDetailsResources);
}
}else if ( status.equals("failed")) {
//Show toast based on error code
generalMethods.showToastMessage(context,redemptionRequestDetailsResponse.getErrorcode());
}
}
Can anyone please shed some lights on this.how can i get the values in specified string and display them.
Here my model class
public class RedemptionRequestDetailsResource {
private String rdmId;
private String rdmUniqueBatchTrackingId;
private String rdmLoyaltyId;
private String rdmStatus;
private String rdmCashPaymentStatus;
private String rdmProductCode;
public String getRdmId() {
return rdmId;
}
public void setRdmId(String rdmId) {
this.rdmId = rdmId;
}
public String getRdmUniqueBatchTrackingId() {
return rdmUniqueBatchTrackingId;
}
public void setRdmUniqueBatchTrackingId(String rdmUniqueBatchTrackingId) {
this.rdmUniqueBatchTrackingId = rdmUniqueBatchTrackingId;
}
public String getRdmLoyaltyId() {
return rdmLoyaltyId;
}
public void setRdmLoyaltyId(String rdmLoyaltyId) {
this.rdmLoyaltyId = rdmLoyaltyId;
}
public String getRdmStatus() {
return rdmStatus;
}
public void setRdmStatus(String rdmStatus) {
this.rdmStatus = rdmStatus;
}
public String getRdmCashPaymentStatus() {
return rdmCashPaymentStatus;
}
public void setRdmCashPaymentStatus(String rdmCashPaymentStatus) {
this.rdmCashPaymentStatus = rdmCashPaymentStatus;
}
public String getRdmProductCode() {
return rdmProductCode;
}
public void setRdmProductCode(String rdmProductCode) {
this.rdmProductCode = rdmProductCode;
}
}
here my populateRedemptionDetails method
public void populateRedemptionDetails(List<RedemptionRequestDetailsResource> requestDetailsResource) {
List<RedemptionRequestDetailsResource> redemptionRequestDetailsResource = requestDetailsResource;
TextView txtLoyaltyId = (TextView)rootView.findViewById(R.id.txtLoyaltyId);
txtLoyaltyId.setText(redemptionRequestDetailsResource.getRdmLoylatyId());
}
i tried like this but it throwing error.
The if condition is wrong, it will never enter:
if (!redemptionRequestDetailsResource.isEmpty() && redemptionRequestDetailsResource.size()==0) {
}
it should be:
if (!redemptionRequestDetailsResource.isEmpty()) {}
also, small tip, when using equals, you should put the constant on the left side of the call, like this:
"success".equals(status)
this is to prevent NullPointerExceptions
Related
i'm using retrofit for service calls.it's return 5 data sets.each data set contain 6 values.each data set contain one actual values and others are null.how can get actual values without null values?
POST man response is like bellow
{
"status": true,
"message": "successfully count new orders",
"data": [
{
"order_count": "3"
},
{
"pending_order": "0"
},
{
"schedule": "2017-11-18 12:00",
"id_order": "272",
"reference": "KB-838704"
},
{
"deli_orders": "0"
},
{
"store_count": "0"
}
]
}
Webservice call
WebserviceAPI apiService =retrofit.create(WebserviceAPI.class);
Call<OrderResponse> call = apiService.getSummery("countnew",token_acces);
call.enqueue(new Callback<OrderResponse>() {
#Override
public void onResponse(Call<OrderResponse> call, Response<OrderResponse> response) {
OrderResponse result = response.body();
List<Order> data=result.getData();
status=result.isStatus();
msg= result.getMessage();
for (Order a:data)
{
try {
Log.d("ress",""+a.getOrder_count()+" : "+a.getPending_order()+" : "+a.getReference()
+" : "+a.getSchedule()+" : "+a.getDeli_orders()+" : "+a.getStore_count());
//update
if( !(a.getOrder_count().contentEquals("null"))){
Log.d("ress","new order "+a.getOrder_count());
//txtNewOrder.setText(a.getOrder_count());
}
if( !(a.getPending_order().contentEquals("null"))){
Log.d("ress","pending "+a.getPending_order());
// txtPendingOrder.setText(a.getPending_order());
}
if( !(a.getReference().contentEquals("null"))){
Log.d("ress","reference "+a.getReference());
//txtRecentOrder.setText(a.getReference());
}
if( !(a.getSchedule().contentEquals("null"))){
Log.d("ress","time "+a.getSchedule());
//txtRemainingTime.setText(a.getSchedule());
}
if( !(a.getDeli_orders().contentEquals("null"))){
Log.d("ress"," delivered "+a.getDeli_orders());
//txtDeliveredOrder.setText(a.getDeli_orders());
}
if( !(a.getStore_count().contentEquals("null"))){
Log.d("ress","store "+a.getStore_count());
//txtStoreOrder.setText(a.getStore_count());
}
}catch (NullPointerException e){
}
}
}
#Override
public void onFailure(Call<OrderResponse> call, Throwable t) {
Log.d("fragres",""+t.getMessage());
}
});
Update : Order.java
public class Order {
String order_count;
String pending_order;
String schedule;
String id_order;
String reference;
String deli_orders;
String store_count;
public String getOrder_count() {
return order_count;
}
public void setOrder_count(String order_count) {
this.order_count = order_count;
}
public String getPending_order() {
return pending_order;
}
public void setPending_order(String pending_order) {
this.pending_order = pending_order;
}
public String getSchedule() {
return schedule;
}
public void setSchedule(String schedule) {
this.schedule = schedule;
}
public String getId_order() {
return id_order;
}
public void setId_order(String id_order) {
this.id_order = id_order;
}
public String getReference() {
return reference;
}
public void setReference(String reference) {
this.reference = reference;
}
public String getDeli_orders() {
return deli_orders;
}
public void setDeli_orders(String deli_orders) {
this.deli_orders = deli_orders;
}
public String getStore_count() {
return store_count;
}
public void setStore_count(String store_count) {
this.store_count = store_count;
}
}
Logcat
when i check null inside for loop,it's display only first value (num 3)
i want to get :
1st value from 1 data set,2 nd value from 2nd data set,3rd and 4th value from 3 data set,5th value from 4th data set,6th value from 5th data set
In my app, I'm storing a list of data for each user with this ConnectionInformation.java.
package trickandroid.fulllogin;
/**
* Created by Simon Peter on 19-May-17.
*/
public class ConnectionInformation {
String due, selectArea, connectionNum, doorNum, conName, phoneNum, aadharNum, rationNum;
public ConnectionInformation(){
}
public ConnectionInformation(String due, String selectArea, String connectionNum, String doorNum, String conName, String phoneNum, String aadharNum, String rationNum) {
this.connectionNum = connectionNum;
this.doorNum = doorNum;
this.conName = conName;
this.phoneNum = phoneNum;
this.aadharNum = aadharNum;
this.rationNum = rationNum;
this.selectArea = selectArea;
this.due = due;
}
public String getDue() {
return due;
}
public void setDue(String due) {
this.due = due;
}
public String getSelectArea() {
return selectArea;
}
public void setSelectArea(String selectArea) {
this.selectArea = selectArea;
}
public String getConnectionNum() {
return connectionNum;
}
public void setConnectionNum(String connectionNum) {
this.connectionNum = connectionNum;
}
public String getDoorNum() {
return doorNum;
}
public void setDoorNum(String doorNum) {
this.doorNum = doorNum;
}
public String getConName() {
return conName;
}
public void setConName(String conName) {
this.conName = conName;
}
public String getPhoneNum() {
return phoneNum;
}
public void setPhoneNum(String phoneNum) {
this.phoneNum = phoneNum;
}
public String getAadharNum() {
return aadharNum;
}
public void setAadharNum(String aadharNum) {
this.aadharNum = aadharNum;
}
public String getRationNum() {
return rationNum;
}
public void setRationNum(String rationNum) {
this.rationNum = rationNum;
}
}
Adding data to the firebase works very fine. This is my database structure.
This is my showData() method where .getDoorNum() is called to display it on the ListView.
private void showData(DataSnapshot dataSnapshot) {
if (expandableListView.getVisibility()==View.VISIBLE) {
for (DataSnapshot ds : dataSnapshot.getChildren()) {
ConnectionInformation cInfo = new ConnectionInformation();
cInfo.setDoorNum(ds.child(userID).child("Connection Detail").child(areaName).child(key).getValue(ConnectionInformation.class).getDoorNum());
cInfo.setPhoneNum(ds.child(userID).child("Connection Detail").child(areaName).child(key).getValue(ConnectionInformation.class).getPhoneNum());
cInfo.setAadharNum(ds.child(userID).child("Connection Detail").child(areaName).child(key).getValue(ConnectionInformation.class).getAadharNum());
cInfo.setRationNum(ds.child(userID).child("Connection Detail").child(areaName).child(key).getValue(ConnectionInformation.class).getRationNum());
ArrayList<String> users = new ArrayList<>();
users.add(cInfo.getDoorNum());
users.add(cInfo.getPhoneNum());
users.add(cInfo.getAadharNum());
users.add(cInfo.getRationNum());
ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, users);
expandableListView.setAdapter(adapter);
}
}
}
I use this code for deleting the child.
disBTN.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
mdata.child(oldArea).child(key).removeValue();
connection.child(oldArea).child(key).removeValue();
toast("Connection Number " + oldNum + " Disconnected Successfully");
startActivity(new Intent(DisconnectActivity.this,AreaGridActivity.class));
}
});
The code works fine in the database but my app crashes with this error...
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String trickandroid.fulllogin.ConnectionInformation.getDoorNum()' on a null object reference
at trickandroid.fulllogin.DetailsActivity.showData(DetailsActivity.java:449)
at trickandroid.fulllogin.DetailsActivity.access$100(DetailsActivity.java:33)
at trickandroid.fulllogin.DetailsActivity$3.onDataChange(DetailsActivity.java:129)
at com.google.android.gms.internal.zzbpx.zza(Unknown Source)
at com.google.android.gms.internal.zzbqx.zzZS(Unknown Source)
at com.google.android.gms.internal.zzbra$1.run(Unknown Source)
at android.os.Handler.handleCallback(Handler.java:751)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:154)
at android.app.ActivityThread.main(ActivityThread.java:6236)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:891)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:781)
https://gist.github.com/SimonPeter1909/d70be328dd6d9b099a8a96454922432fDetailsActivity.java
I have tried many ways but I can't pass the error...
The situation here is that you have a ValueEventListener which is triggered once when the listener is added, and then again any time the data changes. The listener is explicitly expecting to find an entry with a certain areaName and key.
This is fine the first time the listener runs, but then on button click you delete the entry with that areaName and key. This triggers the listener again(you changed the data), the listener tries to do something with the entry at that areaName and key, it doesn't exist, you get a NullPointerException.
There are a number of ways to avoid this, but you probably need to rethink the flow and exactly what you want to happen.
A quick fix here could be to try checking if the entry is there before trying to use it:
if(ds.child(userID).child("Connection Detail").child(areaName).child(key).exists()) {
ConnectionInformation cInfo = new ConnectionInformation();
cInfo.setDoorNum(ds.child(userID).child("Connection Detail").child(areaName).child(key).getValue(ConnectionInformation.class).getDoorNum());
cInfo.setPhoneNum(ds.child(userID).child("Connection Detail").child(areaName).child(key).getValue(ConnectionInformation.class).getPhoneNum());
...
...
} else {
//that entry doesn't exist, do something else
}
not enough info, but i think you are callig getDoorNum, when there is no string in there . try
if (!yourmodelclassobject.getDoorNum()==null)
{
//then print your value or whatever is that you do}
or please post little more info
I'm trying to get the data from Firebase, but when I debug my app I can see that the app has found the key I put, but I received no data on the value:
DatabaseReference taxiref = childRef.child(chapa);
taxiref.addValueEventListener(new ValueEventListener() {
#Override
public void onDataChange(DataSnapshot dataSnapshot) {
Sesion.taxis.add(dataSnapshot.getValue(Taxi.class));
}
#Override
public void onCancelled(DatabaseError databaseError) {
}
});
As you can see in the following code, that my structure from Firebase:
"taxis" : {
"bbb222" : {
"año" : 1998,
"modelo" : "Gol",
"ubicaciones" : {
"u1" : {
"fecha" : "20-12-2016 12:30",
"latitud" : 31231231,
"longitud" : 2131241
},
"u2" : {
"fecha" : "20-12-2016 12:31",
"latitud" : 31231232,
"longitud" : 2131243
}
}
},
And as you can see on the following image when I debugged the code the key I got is correct, but I didn't receive any value, could somebody help me with that?
Here its the taxi.java class:
public class Taxi {
private String año;
private String modelo;
private String chapaTaxi;
private LinkedList<Ubicaciones> ubicaciones;
public void diagramarRecorrido() {
for (Ubicaciones u : getUbicaciones()) {
u.ubicarMapa();
}
}
public String getAño() {
return año;
}
public void setAño(String año) {
this.año = año;
}
public String getModelo() {
return modelo;
}
public void setModelo(String modelo) {
this.modelo = modelo;
}
public String getChapaTaxi() {
return chapaTaxi;
}
public void setChapaTaxi(String chapaTaxi) {
this.chapaTaxi = chapaTaxi;
}
public LinkedList<Ubicaciones> getUbicaciones() {
return ubicaciones;
}
public void setUbicaciones(LinkedList<Ubicaciones> ubicaciones) {
this.ubicaciones = ubicaciones;
}
}
Sorry guys my bad, childRef was a variable:
private static DatabaseReference childRef= ref.child("taxis");
and that was the problem as you can see the child its taxis but I had Taxis thats why I never got any results from the firebase, thanks to all for all your help.
I got tired using this library, this is my first time using it and made a lot of success ways, but i'm a bit confused in getting the following Json :
{
"Guides":
{
"English": {"ArabicSony":"Test1","ArabicNexus":"Test2","ArabicSamsung":"Test3","ArabicHTC":"Test4"}
,"Arabic": {"EnglishSony":"Test1","EnglishNexus":"Test2","EnglishSamsung":"Test3","EnglishHTC":"Test4"}
}
}
Googled and saw a lot of guides and answered, and made my List like this :
public class PostItem {
List<PostItemArabic> Arabic;
List<PostItemEnglish> English;
}
class PostItemArabic{
private String ArabicSony;
private String ArabicNexus;
private String ArabicSamsung;
private String ArabicHTC;
public String getArabicSony() {
return ArabicSony;
}
public void setArabicSony(String arabicSony) {
ArabicSony = arabicSony;
}
public String getArabicNexus() {
return ArabicNexus;
}
public void setArabicNexus(String arabicNexus) {
ArabicNexus = arabicNexus;
}
public String getArabicSamsung() {
return ArabicSamsung;
}
public void setArabicSamsung(String arabicSamsung) {
ArabicSamsung = arabicSamsung;
}
public String getArabicHTC() {
return ArabicHTC;
}
public void setArabicHTC(String arabicHTC) {
ArabicHTC = arabicHTC;
}
}
class PostItemEnglish{
private String EnglishSony;
private String EnglishNexus;
private String EnglishSamsung;
private String EnglishHTC;
public String getEnglishSony() {
return EnglishSony;
}
public void setEnglishSony(String englishSony) {
EnglishSony = englishSony;
}
public String getEnglishNexus() {
return EnglishNexus;
}
public void setEnglishNexus(String englishNexus) {
EnglishNexus = englishNexus;
}
public String getEnglishSamsung() {
return EnglishSamsung;
}
public void setEnglishSamsung(String englishSamsung) {
EnglishSamsung = englishSamsung;
}
public String getEnglishHTC() {
return EnglishHTC;
}
public void setEnglishHTC(String englishHTC) {
EnglishHTC = englishHTC;
}
}
My Model :
private class Model {
private List<PostItem> Guides;
public List<PostItem> getGuides() {
return Guides;
}
public void setGuides(List<PostItem> roms_center) {
this.Guides = roms_center;
}
}
And printing the result like this :
List<PostItem> Guides = response.body().getGuides();
for(int i = 0 ; i < Guides.size() ; i ++ ) {
for (int b = 0; b < Guides.get(i).English.size() ; b++){
Log.LogInfo("English Result Is: " + Guides.get(i).English.get(i).getEnglishHTC());
Log.LogInfo("English Result Is: " + Guides.get(i).English.get(i).getEnglishNexus());
Log.LogInfo("English Result Is: " + Guides.get(i).English.get(i).getEnglishSamsung());
Log.LogInfo("English Result Is: " + Guides.get(i).English.get(i).getEnglishSony());
}
for (int b = 0; b < Guides.get(i).Arabic.size() ; b++){
Log.LogInfo("Arabic Result Is: " + Guides.get(i).Arabic.get(i).getArabicHTC());
Log.LogInfo("Arabic Result Is: " + Guides.get(i).Arabic.get(i).getArabicNexus());
Log.LogInfo("Arabic Result Is: " + Guides.get(i).Arabic.get(i).getArabicSamsung());
Log.LogInfo("Arabic Result Is: " + Guides.get(i).Arabic.get(i).getArabicSony());
}
}
My work isn't correct, and getting a lot of errors,
Here's the last error i got :
`Expected BEGIN_ARRAY but was BEGIN_OBJECT at line 3 column 18 path $.Guides
What's the way to make it correct ? `
Based on your models when you try to get the guides list your telling retrofit to populate an array. Retrofit is then getting the data and finding that it is a single object and not array. So you need to update your model to reflect the data returned. For example:
class PostItem {
List<Language> mLanguages;
}
class Language{
String mLanguageTitle; //for example english
List<String> mData; //for this is your list of data
}
Then in your activity instead of getting guides you would get just a post item for example:
response.body().getPostItem();
Hope it helps !
First of all, you can use the retrofit Gson library.
You can handle this in two ways:
Option 1: reformat your languages in your json to be an array like Doug says.
{
"Guides":
[
{"Lang":"English","ArabicSony":"Test1","ArabicNexus":"Test2","ArabicSamsung":"Test3","ArabicHTC":"Test4"}
, {"Lang":"Arabic","EnglishSony":"Test1","EnglishNexus":"Test2","EnglishSamsung":"Test3","EnglishHTC":"Test4"}
]
}
Then you will need to redesign your class to reflect this structure.
Like Doug sayd:
class PostItem {
List<Language> mLanguages;
}
Option 2: Create a custom json desirializer in your class. this will take the Json and break it down into whatever structure you want it to be.
public class PostItem implements JsonDeserializer
#Override
public MyDesirializer deserialize(JsonElement json, Type type,
JsonDeserializationContext context) throws JsonParseException {
JsonObject jarabic = (JsonObject) json.get("Arabic");
//whatever manipulations you want to do (fill with your own code)
PostItem item = new PostItem();
item.arabic = jarabic;
...
...
return item;
}
I want send composing event in Group (Multiuser) chat in xmpp, I am using asmack library, I have done same functionality with One to One chat.
I am using below code:
mMessageEventManager = new MessageEventManager(XMPPConnectApplication.getInstance().getXmppConnection());
mMessageEventManager.addMessageEventNotificationListener(new MessageEventNotificationListener() {
#Override
public void offlineNotification(String arg0, String arg1) {
}
#Override
public void displayedNotification(String arg0, String arg1) {
}
#Override
public void deliveredNotification(String arg0, String arg1) {
}
#Override
public void composingNotification(String from, String to) {
Log.e("Receiver-composingNotification",from + " is started typing......"+to);
}
#Override
public void cancelledNotification(String from, String to) {
Log.e("Receiver-cancelledNotification",from + " is stopped typing......"+to);
}
});
Please let me know if you have any idea for the same.
Any help will be appreciated.
Yes, I have idea about it and I have done just before 1 week.
I have used MessageEventManager to manage Chat States.
private MessageEventManager mMessageEventManager;
Add this method for Chat State Receiving Listener:
private void chatStateRecognizer(){
Thread thread = new Thread(new Runnable() {
#Override
public void run() {
mMessageEventManager = new MessageEventManager(mXmppConnection);
mMessageEventManager.addMessageEventNotificationListener(new MessageEventNotificationListener() {
#Override
public void offlineNotification(String arg0, String arg1) {
}
#Override
public void displayedNotification(String arg0, String arg1) {
}
#Override
public void deliveredNotification(String from, String arg1) {
}
#Override
public void composingNotification(String from, String to) {
Log.i("Receiver:Compose state",from + " is started typing......"+to);
}
#Override
public void cancelledNotification(String from, String to) {
Log.i("Receiver:Stop state",from + " is stopped typing......"+to);
}
});
}
});
thread.start();
}
Create one Model class name with GroupInfoModel.java:
public class GroupInfoModel implements Comparable<GroupInfoModel>, Serializable{
private static final long serialVersionUID = 1L;
private String memberId = "", memberName = "";
private boolean isAdmin;
public String getMemberId() {
return memberId;
}
public void setMemberId(String memberId) {
this.memberId = memberId;
}
public String getMemberName() {
return memberName;
}
public void setMemberName(String memberName) {
this.memberName = memberName;
}
public boolean isAdmin() {
return isAdmin;
}
public void setAdmin(boolean isAdmin) {
this.isAdmin = isAdmin;
}
#Override
public int compareTo(GroupInfoModel another) {
return getMemberName().compareTo(another.getMemberName());
}
}
Now take ArrayList of GroupInfoModel.java class:
private ArrayList<GroupInfoModel> groupDetailsList = new ArrayList<GroupInfoModel>();
private boolean isComposingStarted;
on onCreate() of Activity / Fragment:
groupDetailsList.clear();
ServiceDiscoveryManager discoManager = ServiceDiscoveryManager.getInstanceFor(mXmppConnection);
DiscoverItems items = discoManager.discoverItems(mRoomId);
for (Iterator<Item> it = items.getItems(); it.hasNext();) {
DiscoverItems.Item item = (DiscoverItems.Item) it.next();
String occupant = item.getEntityID();
occupant = occupant.split("/")[1];
GroupInfoModel groupInfoModel = new GroupInfoModel();
groupInfoModel.setAdmin(false);
groupInfoModel.setMemberId(occupant+"#"+mServiceNameHere);
groupInfoModel.setMemberName(occupant);
groupDetailsList.add(groupInfoModel);
}
Now add TextWatcher on your EditText of Compose Message (Chat view) screen:
#Override
public void onTextChanged(CharSequence s, int start, int before, int count) {
if(s.toString().length()==1&&!isComposingStarted){
isComposingStarted = true;
if(chatType.equals("OneToOneChat")){
mMessageEventManager.sendComposingNotification(myJabberId, friendJabberId);
}else if(chatType.equals("GroupChat")){
for (int i = 0; i < groupDetailsList.size(); i++) {
if(!groupDetailsList.get(i).getMemberId().contains(myJabberId)){
mMessageEventManager.sendComposingNotification(groupDetailsList.get(i).getMemberId(), roomId);
}
}
}
}else if(s.toString().length()==0){
isComposingStarted = false;
if(chatType.equals("OneToOneChat")){
mMessageEventManager.sendCancelledNotification(myJabberId, friendJabberId);
}else if(chatType.equals("GroupChat")){
for (int i = 0; i < groupDetailsList.size(); i++) {
if(!groupDetailsList.get(i).getMemberId().contains(myJabberId)){
mMessageEventManager.sendCancelledNotification(groupDetailsList.get(i).getMemberId(), roomId);
}
}
}
}
}
I strongly recommended that use above code in Application class, you can modify methods as your requirements.
Done.
// send multi user chat typing status
public static void sendMUCTypingStatus(ChatState state)
{
// check if you are connected to group
if(multiUserChat != null)
{
try{
// create packet
Message statusPacket = new Message();
// set body to null
statusPacket.setBody(null);
// set packet type to group chat
statusPacket.setType(Message.Type.groupchat);
// set subject to null
statusPacket.setSubject(null);
// set to the group name
statusPacket.setTo(multiUserChat.getRoom());
// set from my current jis example : me#domain.com
statusPacket.setFrom(new MyPrefrence(XmppBase.context).getUsername());
// get the chat state extension and pass our state
ChatStateExtension extension = new ChatStateExtension(state);
// add the extention to our packet
statusPacket.addExtension(extension);
// get the connection and send the packet
Utils.getConnection().sendStanza(statusPacket);
} catch (SmackException.NotConnectedException e) {
e.printStackTrace();
}
}
}
Usage :
sendMucTypingStatus(ChatState.composing);
watch this : Quick overview of using
With RxJava and Jake Wharton's RxBinding, it's quite simple to do:
RxTextView.afterTextChangeEvents(editText)
.observeOn(Schedulers.io())
.skip(1)
.map({ input ->
// FIRE ChatState.composing EVENT HERE
input // just returning the argument here
})
.debounce(2, TimeUnit.SECONDS)
.observeOn(Schedulers.io())
.subscribe {
// FIRE ChatState.active EVENT HERE
}
Remember that we will have to write code to catch these events via smack stanzaListener and display it on the UI accordingly!
Code is written in Kotlin, but it is fairly straight forward.