Get Mode in XMPP/Smack - xmpp

My chat application has a procedure to set the presence/ mode status of the user i.e - Online, Offline, Invisible, Away etc. I am doing this using the following code :-
presence = new Presence(Presence.Type.available);
if (USER_STATE.equalsIgnoreCase("Online")) {
presence.setMode(Presence.Mode.available);
setUserPresence(0);
}else if (USER_STATE.equalsIgnoreCase("Invisible")) {
presence.setMode(Presence.Mode.xa);
setUserPresence(1);
} else if (USER_STATE.equalsIgnoreCase("Away")) {
presence.setMode(Presence.Mode.away);
setUserPresence(2);
} else if (USER_STATE.equalsIgnoreCase("Busy")) {
presence.setMode(Presence.Mode.dnd);
setUserPresence(3);
}
Here when I set the User Presence to Away or Invisible etc. and log out the user. Now when the user is logged in again I want to get the mode of the User that he had set earlier since his last logout. I am getting it as :-
System.out.println("Loggeddd innn");
// Set presence to online!
Presence userPresence = new Presence(Presence.Type.available);
userPresence.setStatus("Hello CCM!");
userPresence.setPriority(24);
userPresence.setMode(userPresence.getMode());
connection.sendPacket(userPresence);
Here I always get NULL in user.getMode() and also I always get Status as Available (shown in openfire portal)
Anybody please help ?

userPresence.setMode(userPresence.getMode()) seems like a no-op to me.
You should store the previous mode on the device itself (eg in SharedPreferences)

Related

Flutter: Calling a function once in a lifetime of the flutter app

I want to call a function when app runs for the first time, which will ask the user to enter firstName , lastName and add a profile picture.
Once the above process is done the function will never again be called during the lifetime of the app.
For something like this you need to check if the user has already entered that data or not. If not then show him the page where he can enter information otherwise take him to HomePage. For this When the user enters the information you need to save it to some persistent storage and check it whenever the app runs. In this way, your function will be called only once until the user deletes the app or clear its memory. You could use the following libraries to store the data.
Hive,
Shared Preference
These libraries save the data in key-value pair and read data faster especially hive.
Use SharePreference
see below code snippet with little advancement in code you can achieve your result.
Future<bool> isFirstTime() async {
var firstTime = SharedPref.pref.getBool('first_time');
if (firstTime != null && !firstTime) {
SharedPref.pref.setBool('first_time', false);
return false;
} else {
SharedPref.pref.setBool('first_time', false);
return true;
}
}

How can I check if the user is playing the game for the first time?

I want to show a text for the first time running like "Hi, my name is NAVI." and then when the player will start the game again the next time it will another text for example "Welcome back."
Using player prefs is probably the easiest solution, though definitely not the only one*.
Due to the lack of boolean playerpref I usually opt to use SetInt/GetInt instead, but that's personal preference. You could also do it with a string or float.
private void Start()
{
if(PlayerPrefs.GetInt("HasLaunched", 0) == 0)//Game hasn't launched before. 0 is the default value if the player pref doesn't exist yet.
{
//Code to display your first time text
}
else
{
//Code to show the returning user's text.
}
PlayerPrefs.SetInt("HasLaunched", 1); //Set to 1, so we know the user has been here before
}
Playerpref stores values between sessions, so the next session will still have "HasLaunched" set to 1. This is however stored on the local device. so users can manually reset it if they'd really want to.
If you ever want to show the "first launch" text again, simply set HasLaunched back to zero, or delete it altogether with DeleteKey("HasLaunched");
*There are plenty of alternative solutions, like storing it in a config file locally, or using a remote database (this would be required if you don't want users to be able to reset it). They would however come down to the same principle. Setting a value to true or 1 somewhere, and checking that value on launch.

Symbol Barcode Reader on_read issue

I have a Moto Mc9096 device, EDMK SDK, VS2008 etc all of the prereq's
I'm having an issue where once I've scanned a barcode it constantly repeats the event. normally when this happens its a flag or status needs changing but there are no obvious settings to stop it reading again.
code below
private void Barcode_Read(object sender, ReaderData readerdata)
{
if (readerdata.Text != null)
{
if (readerdata.Text == "abc")
{
MessageBox.Show(readerdata.text);
}
}
}
Notes
I've tried
bar.Dispose();
bar.Reader.Actions.Flush();
bar.ReaderData.Dispose() ;
with no success. the EnabledScanner is set on form load and off during form close.
My expectation was when the user scans a barcode it fires the read event once.
but it constantly fires after the users first scan.
You might want to check the aimType property, by default it should be AIM_TYPE_TRIGGER but other settings allow a single trigger pull to perform multiple scans (AIM_TYPE_CONTINUOUS_READ) so perhaps that has been changed.
You should have some samples installed by the SDK at file:///C:/Users/Public/Motorola%20EMDK%20for%20.NET/v2.9/SampLauncher2008.htm (by default) that show best practice.

How to wait the p2 profile gets completed

We are using p2 to update our RCP application, and this worked so far quite well until today I realized in some case the P2 IProfile was emty (not null but empty) and always of course return emty result queries.
This happend when launching the application only, meaning that if I request the same profile later in time, I get a complete profile.
The Javadoc of IProfile mention the fact that profile is a snapshot of a particular state.
So it seems I am querying the ProfileRegistry to early and the profile is not yet complete.
I could not find any way on the javadoc to wait for a profile to be filled properly.
I would be grateful to anyone that would help me solve this problem nicely, because using a sleep (which works) is not an acceptable solution.
Thanks.
here is the ugly solution I am implemented, basically testing the time stam to be sure the profile has been loaded
// there seems to be a bug because if the agent is created too quickly then the profile is empty.
// so we loop until we get a proper profile
do {
try {
Thread.sleep(50);
} catch (InterruptedException e) {
interrupted = true;
}
if (agent != null) {
agent.stop();
}
agent = agentProvider.createAgent(getP2AgentUri());
IProfileRegistry profRegistry = (IProfileRegistry) agent.getService(IProfileRegistry.SERVICE_NAME);
profile = profRegistry.getProfile(getP2ProfileId());
} while (profile != null && profile.getTimestamp() == 0 && !interrupted && !progress.isCanceled());
The profile I use is SELF but I use a method to get the ProfileId because I have JUnit tests that are base on another external p2 profile.

WMI and Win32_DeviceChangeEvent - Wrong event type returned?

I am trying to register to a "Device added/ Device removed" event using WMI. When I say device - I mean something in the lines of a Disk-On-Key or any other device that has files on it which I can access...
I am registering to the event, and the event is raised, but the EventType propery is different from the one I am expecting to see.
The documentation (MSDN) states : 1- config change, 2- Device added, 3-Device removed 4- Docking. For some reason I always get a value of 1.
Any ideas ?
Here's sample code :
public class WMIReceiveEvent
{
public WMIReceiveEvent()
{
try
{
WqlEventQuery query = new WqlEventQuery(
"SELECT * FROM Win32_DeviceChangeEvent");
ManagementEventWatcher watcher = new ManagementEventWatcher(query);
Console.WriteLine("Waiting for an event...");
watcher.EventArrived +=
new EventArrivedEventHandler(
HandleEvent);
// Start listening for events
watcher.Start();
// Do something while waiting for events
System.Threading.Thread.Sleep(10000);
// Stop listening for events
watcher.Stop();
return;
}
catch(ManagementException err)
{
MessageBox.Show("An error occurred while trying to receive an event: " + err.Message);
}
}
private void HandleEvent(object sender,
EventArrivedEventArgs e)
{
Console.WriteLine(e.NewEvent.GetPropertyValue["EventType"]);
}
public static void Main()
{
WMIReceiveEvent receiveEvent = new WMIReceiveEvent();
return;
}
}
Well, I couldn't find the code. Tried on my old RAC account, nothing. Nothing in my old backups. Go figure. But I tried to work out how I did it, and I think this is the correct sequence (I based a lot of it on this article):
Get all drive letters and cache
them.
Wait for the WM_DEVICECHANGE
message, and start a timer with a
timeout of 1 second (this is done to
avoid a lot of spurious
WM_DEVICECHANGE messages that start
as start as soon as you insert the
USB key/other device and only end
when the drive is "settled").
Compare the drive letters with the
old cache and detect the new ones.
Get device information for those.
I know there are other methods, but that proved to be the only one that would work consistently in different versions of windows, and we needed that as my client used the ActiveX control on a webpage that uploaded images from any kind of device you inserted (I think they produced some kind of printing kiosk).
Oh! Yup, I've been through that, but using the raw Windows API calls some time ago, while developing an ActiveX control that detected the insertion of any kind of media. I'll try to unearth the code from my backups and see if I can tell you how I solved it. I'll subscribe to the RSS just in case somebody gets there first.
Well,
u can try win32_logical disk class and bind it to the __Instancecreationevent.
You can easily get the required info
I tried this on my system and I eventually get the right code. It just takes a while. I get a dozen or so events, and one of them is the device connect code.