Android-gps listener - android-location

I use this code to get gps sensor data.
mlocManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
mlocListener = new MyLocationListener();
mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 2000, 1, mlocListener);
Why does my gps icon continuously turn on and off?

2000 milliseconds is approximatley 0.0333333 seconds. In your code, you have requested for location updates every 0.0333333 seconds.
mlocManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 2000, 1, mlocListener);
This means for that the GPS doesn't always have to be updating itself. Thats why the GPS icon continuously turns on and off.

Related

Trigger indefinite notification on Windows 10

I'm trying to trigger a notification which has no expiry but must be closed by pressing the top-right X close button. Is this possible?
I've been able to trigger a timed notification which also closes when anywhere else is clicked. With this answer.
[reflection.assembly]::loadwithpartialname("System.Windows.Forms")
[reflection.assembly]::loadwithpartialname("System.Drawing")
$notify = new-object system.windows.forms.notifyicon
$notify.icon = [System.Drawing.SystemIcons]::Information
$notify.visible = $true
$notify.showballoontip(10,"New Chat!","You have received New Chat!",[system.windows.forms.tooltipicon]::None)
Per Microsofts NotifyIcon.ShowBalloonTip Method documentation, the actual timeout property is set by the current system settings.
Minimum and maximum timeout values are enforced by the operating system and are typically 10 and 30 seconds, respectively, however this can vary depending on the operating system. Timeout values that are too large or too small are adjusted to the appropriate minimum or maximum value. In addition, if the user does not appear to be using the computer (no keyboard or mouse events are occurring) then the system does not count this time towards the timeout.
According to a couple of more google searches, you can set the time for your profile through the Registry ( Regedit - HKEY_CURRENT_USER\Control Panel\Accessibility: MessageDuration - didn't work for me).
Through group policy, or using theSystemParametersInfo API which is out of my league to explain any further. Only reference I can find was configuring the Accessibility/System Parameter: SPI_SETMESSAGEDURATION.
Its C++ though and only other article I could find was this one:SystemParametersInfoA function.
Seems possible but, it will definitely be a hassle to get it working.

wxMathPlot with x-axis in milliseconds?

I'm working with Sensor HID device and wxWidgets host application respectively.
Process Flow:
1.Sensor sends float value with time-stamp(in milliseconds) for every few milliseconds to seconds.
2.Host application reads the data and represents it in a chart (x-axis as time and y-axis as float value).
I'm using the mpFXYVector and mpScaleX with mpX_TIME.
If the time-stamp is in milliseconds, x-axis time ticks are not coming properly.
Kindly help me to resolve this issue.
Regards,
Rajan.M
The issue is I've passed the time value in milliseconds directly instead of converting it to seconds!
E.g. 45678 milliseconds to 45.678 seconds

ScheduledAgent and GeoCoordinateWatcher - how to make them work?

I'm trying to get GPS position via GeoCoordinateWatcher running in ScheduledAgent. Unfortunately only location I get is some old one, recorded when application was running. How to get current (latest) location in ScheduledAgent?
I have come across the same problem. Unfortunaty, this is intended behaviour according to the WP7.1 APIs
According to the documentation, "This API, used for obtaining the geographic coordinates of the device, is supported for use in background agents, but it uses a cached location value instead of real-time data. The cached location value is updated by the device every 15 minutes."
http://msdn.microsoft.com/en-us/library/hh202962(v=VS.92).aspx
My 2 Centlys.
it is probably becoz the GeoCoordinateWatcher takes some time (2 seconds or so) to get the new coordinate values and to lock to GPS or Cellular Mast or Wifi or whatever. And it will give you the last recordered position in the meantime.
So, try to hook to the following events
watcher.StatusChanged += new EventHandler< GeoPositionStatusChangedEventArgs>(watcher_StatusChanged);
watcher.PositionChanged += new EventHandler< GeoPositionChangedEventArgs< GeoCoordinate>>(watcher_PositionChanged);
where watcher = new GeoCoordinateWatcher(GeoPositionAccuracy.High);
and call the NotifyComplete(); in your "watcher_PositionChanged" event handler.

Should I rely on the local phone's time for time sensitive app (Windows Phone 7)

I'm building an app where my users will post content. The exact time of the post is an important data point - I need to know exactly when the user hit the "Post" button. Once the post has been captured I'll upload that posting to my web server. My app should still work in offline mode, meaning when there is no internet connectivity the post will be saved locally and uploaded next time the network becomes available.
Question is, how can I guarantee that the time of the post is accurate? Should I rely on the phone's local time? Should I try to create some crazy code that regularly sync's the difference between my servers time and the devices time so I can always know the difference (if there is one). Are there better time management solutions that I'm not aware of?
Thanks,
UPDATE
Here's the server side code that I wrote to ensure that server and client times are perfectly matched. Hope it helps others...
/// <summary>
/// Calculates the actual time the client event occurred.
/// Takes in account that the event and the sending of the
/// event may have happened seprately.
/// </summary>
public static DateTime CalculateClientEventTime(
DateTime serverReceiveTime,
DateTime clientSendTime,
DateTime clientEventTime)
{
// first we need to sync the client and server time
// we also need to subtract any time zone offsets
// then we can subtract the actual time on de ice
DateTime serverReceiveUtc = serverReceiveTime.ToUniversalTime();
DateTime clientSendUtc = clientSendTime.ToUniversalTime();
DateTime clientEventUtc = clientEventTime.ToUniversalTime();
// note: all dates are in utc
// just need to subtract the client TimeSpan from the client Send
// then subtract that TimeSpan from the server utc time
TimeSpan diffBetweenClientEventAndClientSend = (clientSendUtc - clientEventUtc);
return serverReceiveUtc.Subtract(diffBetweenClientEventAndClientSend);
}
I suggest that you do the following:
In online mode: Take the time from your server when the user post their data.
In offline mode: Save the time from the phone. When going online, submit all saved data, and the current time of the phone. Calculate the difference between the phone and your server time to get the real time.
You cannot rely on the phone's time because user can change it and your app can run in diffrent time zones. Use always the sever time or you can get the phone time and calibrate your local timer to get the value of a lag.

Any body have any luck with ShellTileSchedule?

Any body have any luck with ShellTileSchedule? I have followed the Microsoft example and still have gotten no where.
"How to: Update Your Tile Without Push Notifications for Windows Phone"
Has any one seen a complete example that works on a device or emulator?
Yes...I started with the sample at http://channel9.msdn.com/learn/courses/WP7TrainingKit/WP7Silverlight/UsingPushNotificationsLab/Exercise-2-Introduction-to-the-Toast-and-Tile-Notifications-for-Alerts/
and skipped immediately down to "Task 3 – Processing Scheduled Tile Notifications on the Phone." After that I had to wait about 1 hour, leaving the emulator running on my desktop (1 hour is the minimum update interval, indicated as such for "performance considerations."
_shellTileSchedule = new ShellTileSchedule
{
Recurrence = UpdateRecurrence.Interval,
Interval = UpdateInterval.EveryHour,
StartTime = DateTime.Now - TimeSpan.FromMinutes(59),
RemoteImageUri = new Uri(#"http://cdn3.afterdawn.fi/news/small/windows-phone-7-series.png")
};
Note that setting the StartTime to DateTime.Now - 59 minutes did nothing. It still waited a full hour for its first update. I could not find any mechanism to perform "go to this URI and Update yourself NOW!", other than calling out to a web service that tickles a Tile Notification.
as #avidgator said, you'll have to wait an hour.
i have written a tutorial on how to update the tile instantly here:
http://www.diaryofaninja.com/blog/2011/04/03/windows-phone-7-live-tile-schedules-ndash-executing-instant-live-tile-updates
basically it involves opening a push/toast update channel and then getting the phone to send "itself" a live tile update request. this will trigger the phone to go and get the tile "right now"
hope this helps
Are the channels necessary for this kind of update?
Is there a full code example of what has to be done to create an app that just updates its tile?
BTW: How about setting the Recurrence to UpdateRecurrence.Onetime and the StartTime to Now + 20 seconds for testing purposes?
I just got an tile update after an hour without channels and so on. So that answered my first question. But having to wait an hour while trying to develop an app is... unsatisfying.
It is easy. Just use the following code when you setup ShellTileSchedule.
ShellTile applicationTile = ShellTile.ActiveTiles.First();
applicationTile.Update(
new StandardTileData {
BackgroundImage = new Uri("www.ash.com/logo.jpg"),
Title = ""
});

Resources