Not able to get LastActivity of a jabberId - android

I am trying to get last offline time of a particular jabberId by this piece of code.
LastActivityManager lActivityManager = LastActivityManager.getInstanceFor(MessageService.getConnection());
lActivityManager.isLastActivitySupported(to + "#localhost");
Log.v(TAG, "Last Activity: " + lActivityManager.getLastActivity(to + "#localhost"));
LastActivity activity = lActivityManager.getLastActivity(to + "#localhost");
But I am keep getting service-unavailable exception.
I have checked the server configuration but this feature is implemented correctly from server side.

Have you added other jabber id as your roster. If not try adding them then check.
If you are using ejabbered then you can manually add roster from their admin panel for testing.
I used this code snippet to add roster--
Roster.setDefaultSubscriptionMode(Roster.SubscriptionMode.accept_all);
String number = datacollection.get(i).getNo().replace("+", "");
String jid = number + "#localhost";
Collection<RosterEntry> entries = roster.getEntries();
for (RosterEntry entry : entries)
{
System.out.println(entry);
if (entry.getUser().equals(jid))
{
rosterAlreadyAdded = true;
if (entry.getType() != RosterPacket.ItemType.both)
{
// Create a presence subscription packet and send.
Presence presencePacket = new Presence(Presence.Type.subscribe);
presencePacket.setTo(jid);
connection.sendStanza(presencePacket);
}
}
}
if (!rosterAlreadyAdded)
roster.createEntry(jid, jid, null);

Related

android WiFi scanner, list only networks with specific SSID

I need to create WiFi scanner app on android device. I managed to do it, yet there is something I don't know how to deal with.
class WifiReceiver extends BroadcastReceiver {
#Override
public void onReceive(Context context, Intent intent) {
sb = new StringBuilder();
Comparator<ScanResult> comparator = new Comparator<ScanResult>() {
#Override
public int compare(ScanResult o1, ScanResult o2) {
return (o1.level>o2.level ? -1 : (o1.level==o2.level ? 0 : 1));
}
};
lista = wifiManager.getScanResults();
Collections.sort(list, comparator);
for (int i = 0; i < list.size(); i++) {
scanResult = wifiManager.getScanResults().get(i);
sb.append(new Integer(i + 1).toString() + ". " + (list.get(i)).SSID + " " + (list.get(i)).BSSID + " " + (list.get(i)).level + "\n");
}
txt.setText(sb);
wifiManager.startScan();
}
}
There are several WiFi networks in the building with the same SSID, lets say ABCD. I want to save in list, which is List<ScanResult> type, only networks with this specific SSID ABCD without the need to create another field such as list if possible. I woukd be grateful for any help
I assume you mean you want a way to filter the scan and return only the specified ssid, there is no way that I know of on the back-end to do that. You can go through your existing list and pull out the ones you want and save to a new List.
You can also use your existing code and check to see if the ssid matches inside your loop and only build the string if it does.
Most of the time you will be showing a list of available networks in a list or recycler view so usually the secondary list is the way to go.

How to filter the email by the content in android?

The android default Email is filter by subject, sender or receiver. But how to filter by content? The message body is not saved to database, which is saved to the file in after Android 5.0. Should I put the message body to the database, which do like before Android 5.0? And then filter the content according the keyword? Please give me some advice, Thanks!
case BODY:
final ContentValues dbValues = new ContentValues(values);
// Prune out the content we don't want in the DB
dbValues.remove(BodyColumns.HTML_CONTENT);
dbValues.remove(BodyColumns.TEXT_CONTENT);
// TODO: move this to the message table
longId = db.insert(Body.TABLE_NAME, "foo", dbValues);
resultUri = ContentUris.withAppendedId(uri, longId);
// Write content to the filesystem where appropriate
// This will look less ugly once the body table is folded into the message table
// and we can just use longId instead
if (!values.containsKey(BodyColumns.MESSAGE_KEY)) {
throw new IllegalArgumentException(
"Cannot insert body without MESSAGE_KEY");
}
final long messageId = values.getAsLong(BodyColumns.MESSAGE_KEY);
// Ensure that no pre-existing body files contaminate the message
deleteBodyFiles(context, messageId);
writeBodyFiles(getContext(), messageId, values);
break;
public static String buildLocalSearchSelection(Context context, long mailboxId,
String queryFilter, String queryFactor) {
StringBuilder selection = new StringBuilder();
selection.append(" (");
queryFilter = queryFilter.replaceAll("\\\\", "\\\\\\\\")
.replaceAll("%", "\\\\%")
.replaceAll("_", "\\\\_")
.replaceAll("'", "''");
String[] queryFilters = queryFilter.split(" +");
boolean isAll = false;
if (queryFactor.contains(SearchParams.SEARCH_FACTOR_ALL)) {
isAll = true;
}
if (queryFactor.contains(SearchParams.SEARCH_FACTOR_SUBJECT) || isAll) {
selection.append(buildSelectionClause(queryFilters, MessageColumns.SUBJECT));
}
if (queryFactor.contains(SearchParams.SEARCH_FACTOR_SENDER) || isAll) {
selection.append(buildSelectionClause(queryFilters, MessageColumns.FROM_LIST));
}
if (queryFactor.contains(SearchParams.SEARCH_FACTOR_RECEIVER) || isAll) {
selection.append(buildSelectionClause(queryFilters, null));
}
selection.delete(selection.length() - " or ".length(), selection.length());
selection.append(")");
return selection.toString();
}
it can use the ' MessageColumns.SNIPPET' to filter the email content.

Receiving only default message in Android GCM using Amazon SNS

I am implementing a notification service on the server, to push out notifications to both Android and Iphones.
The problem I am having at the moment is that the Android device which I am testing on, is only receiving the default message.
My code is as follows :-
Main Program
string smsMessageString = "{\"default\": \"This is the default message which must be present when publishing a message to a topic. The default message will only be " +
" used if a message is not present for one of the notification platforms.\"," +
"\"APNS\": {\"aps\": {\"alert\": \"Check out these awesome deals!\",\"url\": \"www.amazon.com\"}}," +
"\"GCM\": {\"data\": {\"message\": \"Check out these awesome deals!\",\"url\": \"www.amazon.com\"}}," +
"\"ADM\": {\"data\": {\"message\": \"Check out these awesome deals!\",\"url\": \"www.amazon.com\"}}}";
var smsMessage = new SmsMessageObj
{
smsMessageSubject = "Test Message",
smsMessageBody = smsMessageString
};
snsClient.SendPush(endpointArn, smsMessage);
and the SendPush is as follows :-
public void SendPush(string endpointArn, SmsMessageObj msg)
{
if (string.IsNullOrEmpty(endpointArn))
throw new Exception("Endpoint ARN was null");
var pushMsg = new PublishRequest
{
Message = msg.smsMessageBody,
MessageStructure = "json",
Subject = msg.smsMessageSubject,
TargetArn = endpointArn
};
_client.Publish(pushMsg);
}
Do I need to include anything more so that I can get the "correct" Android notification?
Do I need anything in the app.config?
Thanks for your help and time
I have resolved this question. All I needed to do was to stringify the Json. Maybe it will help someone else in the future. So what I did was :-
var apns_Json = "{\"aps\": {\"alert\": \"Check out these awesome deals_Apple!\",\"url\": \"www.amazon.com\"}}";
var gcm_Json = "{\"data\": {\"message\": \"Check out these awesome deals_Google!\",\"url\": \"www.amazon.com\"}}";
var adm_Json = "{\"data\": {\"message\": \"Check out these awesome deals!\",\"url\": \"www.amazon.com\"}}";
string smsMessageString = "{\"default\": \"This is the default message which must be present when publishing a message to a topic. The default message will only be " +
" used if a message is not present for one of the notification platforms.\"," +
"\"APNS\": " + JsonConvert.ToString(apns_Json) + "," +
"\"GCM\": " + JsonConvert.ToString(gcm_Json) + "," +
"\"ADM\": " + JsonConvert.ToString(adm_Json) + "}";

How to resolve the issue of No response from server in asmack when create MUC Group Some times?

I am developing a one chat application in this i am using asmack library, this code for creating Muc room.
public void createGroup(String group){
String[] temp=group.split("/");
String groupName=temp[0];
String unique=temp[1];
System.out.println("Group_name!!!"+groupName);
System.out.println("Unique!!!" + unique);
try {
MultiUserChat mMultiUserChat = new MultiUserChat(mXMPPConnection, unique + "#muc.202.65.158.173");
// For Providing Nick Name To Conference.
AndFilter var7 = new AndFilter(new PacketFilter[]{new FromMatchesFilter((unique+"#muc.202.65.158.173").toLowerCase() + "/" + groupName), new PacketTypeFilter(Presence.class)});
PacketCollector var8 = this.mXMPPConnection.createPacketCollector(var7);
Presence var5 = (Presence)var8.nextResult((long)SmackConfiguration.getPacketReplyTimeout());
/* if(var5 == null){
Log.e("NEW EROOR:","Catch the Error");
}else {*/
mMultiUserChat.create(groupName);
//setConfig(mMultiUserChat, groupName);
String userjID = mConfig.userName + "#" + mConfig.server;
for (int i = 0; i < NewGroupWindow.selectedjids.length; i++) {
mMultiUserChat.invite(NewGroupWindow.selectedjids[i], "Please join this room");
}
System.out.println("Room Created!!!");
mMultiUserChat.join(userjID);
mMultiUserChat.changeSubject(groupName);
new GetGroups().execute();
//}
}
catch(XMPPException xe){
}
}
This is code for creating room and invite the members to the group.
The above code is working perfectly, some times it's showing "No response from server".
Please give me any idea how to resolve this
Thanks...

Getting "recipient-unavailable(404)" while joining the Group after getting the invitation for Multiuser Chat

I am Creating Group in android using following code
MultiUserChat muc = new MultiUserChat(connection, groupName + "#conference.jabber.org");
setConfig(muc, groupName);
muc.create(groupName);
muc.join("ABC");
groups.add(groupName);
private void setConfig(MultiUserChat multiUserChat, String groupName) {
try {
Form form = multiUserChat.getConfigurationForm();
Form submitForm = form.createAnswerForm();
for (Iterator<FormField> fields = submitForm.getFields(); fields
.hasNext();) {
FormField field = (FormField) fields.next();
if (!FormField.TYPE_HIDDEN.equals(field.getType())
&& field.getVariable() != null) {
submitForm.setDefaultAnswer(field.getVariable());
}
}
List<String> owners = new ArrayList<String>();
owners.add("abc" + "#" + "#conference.jaber.org");
submitForm.setAnswer("muc#roomconfig_roomowners", owners);
submitForm.setAnswer("muc#roomconfig_roomname", groupName);
submitForm.setAnswer("muc#roomconfig_publicroom", true);
submitForm.setAnswer("muc#roomconfig_persistentroom", true);
multiUserChat.sendConfigurationForm(submitForm);
} catch (Exception e) {
e.printStackTrace();
}
}
After this Code My group Appears in the XMPP Server, and then I send the invitation using following Code
muc.invite("abab#" + "jabber.org", "Lets have ");
Then the next user USER2 also receives the Invitation, when try to join the Group using
MultiUserChat mucJoin = new MultiUserChat(connection, groupName);
mucJoin.join("USER2");
Then I got the Error "recipient-unavailable(404)".
Please let me know where I am doing wrong, and why I am getting this Error.
Thanks
Bajwa
I got the solution of my problem, I was configuring the room before creating and joining it as below
setConfig(muc, groupName);
muc.create(groupName);
muc.join("ABC");
groups.add(groupName);
and I just changed the steps as below
muc.create(groupName);
muc.join("ABC");
groups.add(groupName);
setConfig(muc, groupName);
I am accepting my answer.

Categories

Resources