GeoCoordinateWatcher and timeout - windows-phone-7

I am new to Windows Phone 8 development and I'm trying to use the GeoCoordinateWatcher class to easily get the latitude and longitude of the user.
My problem is that I want to manage a timeout (the user will be able to customize its value).
I thought the "TryStart(...)" method would help me to do that, but:
tryStart(false, TimeSpan.FromSeconds(10)); => The watcher starts after 10sec
tryStart(false, TimeSpan.FromSeconds(2)); => The watcher starts after 2sec
This method is, for me, pointless as I want the GeoCoordinateWatcher to start immediately (so I'm using the basic method "Start()", but I also want to return an exception like "The timeout has expired" if it takes more than xxx seconds to return coordinates.
Is there an easy way to do that ? Do I have to create a timer or something like that ?
Thanks a lot for your help

If you are using Windows Phone 8, you should use Geolocation API which is a part of Windows Phone Runtime
http://msdn.microsoft.com/en-us/library/windowsphone/develop/windows.devices.geolocation.geolocator.getgeopositionasync.aspx
This provides a simple / easy way to get location without mucking around.
You might want to go through my verbose blog post on possible issues.
http://invokeit.wordpress.com/2013/05/01/geolocator-and-movementthreshold-wpdev-win8dev/

Related

WEC : How to uniquely identify logs in `Forwarded Events` channel

Looking for more information or at least suggestions on alternatives to EventRecordID as an index when using the Windows Event Collector.
When working with an individual server and individual Eventlog, the EventRecordID element can be used as an index to keep your place when crawling through events in order.
However, when using the Windows Event Collector, the events retain their original EventRecordID in the ForwardedEvents log. That makes it difficult at best to keep track of where you were when crawling through events with a script/program.
The date/timestamp doesn't help either, as events can come in from other systems after you have moved past a given date/time.
Does anyone have any suggestions on a way to track, bookmark, or index events in ForwardedEvents?
You can use the BookmarkID
See how to get it with the Microsoft example in C++ here
or like I did with C#
EventLogQuery eventsQuery = new EventLogQuery("ForwardedEvents", PathType.LogName);
EventLogReader logReader = new EventLogReader(eventsQuery);
EventRecord myevent = logReader.ReadEvent();
string bookmark = ReflectionHelper.GetPropertyValue(myevent.Bookmark, "BookmarkText").ToString();
ReflectionHelper is not from me. Source here

Android Beacon Library Reference Application Help (didEnterRegion function)

My region is:
Region region = new Region("backgroundRegion", Identifier.parse("24DDF411-8CF1-440C87CD-E368DAF9C93E"), null, null);
When I start the program I get this message:
06-26 18:03:21.061 7394-7394/? D/BeaconReferenceApp: setting up background monitoring for beacons and power saving
But it doesn't enter in any didEnterRegion function
So, I removed this line: backgroundPowerSaver = new BackgroundPowerSaver(this);
And change scanning times, as it follows:
beaconManager.setBackgroundScanPeriod(1100l);
beaconManager.setBackgroundBetweenScanPeriod(10000l-1100l);
I checked my Beacon UUID and they are 24DDF411-8CF1-440C87CD-E368DAF9C93E
So what is wrong? Why the app doesn't go to the didEnterRegion function?
I already made it work to work with other than AltBeacons... (ranging function works ok!)
My final goal is to get current time when a beacon is discovered...
A few possibilities:
If you are already in the beacon region, you won't get a second callback until the beacon disappears (turn it off for 30 seconds or so, then turn it back on while the app is running.) Alternatively, you can look for a call do didDetermineStateForRegion which is always called when your app starts up, with a flag that tells you if you are inside or outside.
Make sure you have granted runtime permissions to location.
Make sure location is turned on for your phone in settings.
Make sure the beacon is transmitting that identifier using the Locate app https://play.google.com/store/apps/details?id=com.radiusnetworks.locate&hl=en
Make sure you have the proper BeaconParser configured. The question is tagged Eddystone, but shows an iBeacon or AltBeacon-style UUID as the first identifier. Do you have a custom beacon parser configured? What beacon type are you trying to detect?

Non helpfull error message Calabash with page objects pattern

I'm currently using Calabash framework to automate functional testing for a native Android and IOS application. During my time studying it, I stumbled upon this example project from Xamarin that uses page objects design pattern which I find to be much better to organize the code in a Selenium fashion.
I have made a few adjustments to the original project, adding a file called page_utils.rb in the support directory of the calabash project structure. This file has this method:
def change_page(next_page)
sleep 2
puts "current page is #{current_page_name} changing to #{next_page}"
#current_page = page(next_page).await(PAGE_TRANSITION_PARAMETERS)
sleep 1
capture_screenshot
#current_page.assert_info_present
end
So in my custom steps implementation, when I want to change the page, I trigger the event that changes the page in the UI and update the reference for Calabash calling this method, in example:
#current_page.click_to_home_page
change_page(HomePage)
PAGE_TRANSITION_PARAMETERS is a hash with parameters such as timeout:
PAGE_TRANSITION_PARAMETERS = {
timeout: 10,
screenshot_on_error: true
}
Just so happens to be that whenever I have a timeout waiting for any element in any screen during a test run, I get a generic error message such as:
Timeout waiting for elements: * id:'btn_ok' (Calabash::Android::WaitHelpers::WaitError)
./features/support/utils/page_utils.rb:14:in `change_page'
./features/step_definitions/login_steps.rb:49:in `/^I enter my valid credentials$/'
features/04_support_and_settings.feature:9:in `And I enter my valid credentials'
btn_ok is the id defined for the trait of the first screen in my application, I don't understand why this keeps popping up even in steps ahead of that screen, masking the real problem.
Can anyone help getting rid of this annoyance? Makes really hard debugging test failures, specially on the test cloud.
welcome to Calabash!
As you might be aware, you'll get a Timeout waiting for elements: exception when you attempt to query/wait for an element which can't be found on the screen. When you call page.await(opts), it is actually calling wait_for_elements_exist([trait], opts), which means in your case that after 10 seconds of waiting, the view with id btn_ok can't be found on the screen.
What is assert_info_present ? Does it call wait_for_element_exists or something similar? More importantly, what method is actually being called in page_utils.rb:14 ?
And does your app actually return to the home screen when you invoke click_to_home_page ?
Unfortunately it's difficult to diagnose the issue without some more info, but I'll throw out a few suggestions:
My first guess without seeing your application or your step definitions is that #current_page.click_to_home_page is taking longer than 10 seconds to actually bring the home page back. If that's the case, simply try increasing the timeout (or remove it altogether, since the default is 30 seconds. See source).
My second guess is that the element with id btn_ok is not actually visible on screen when your app returns to the home screen. If that's the case, you could try changing the trait definition from * id:'btn_ok' to all * id:'btn_ok' (the all operator will include views that aren't actually visible on screen). Again, I have no idea what your app looks like so it's hard to say.
My third guess is it's something related to assert_info_present, but it's hard to say without seeing the step defs.
On an unrelated note, I apologize if our sample code is a bit outdated, but at the time of writing we generally don't encourage the use of #current_page to keep track of a page. Calabash was written in a more or less stateless manner and we generally encourage step definitions to avoid using state wherever possible.
Hope this helps! Best of luck.

Run background task every X amount of time

I would like to start a service that once in awhile on all platforms has checked is there a notification to appear or not. Is there any nuget to connect all platforms or some examples?
You can use the Device.StartTimer(TimeSpan minutes) method to start a background task that will repeat after the given time span. Here is a code example:
var minutes = TimeSpan.FromMinutes (3);
Device.StartTimer (minutes, () => {
// call your method to check for notifications here
// Returning true means you want to repeat this timer
return true;
});
This is included with Xamarin Forms, so you don't need any platform specific logic.
http://iosapi.xamarin.com/index.aspx?link=M%3AXamarin.Forms.Device.StartTimer(System.TimeSpan%2CSystem.Func%7BSystem.Boolean%7D)
I think that the best that you can do is following:
Unfortunately, the way that these two platforms have evolved to handle executing background code is completely different. As such, there is no way that we can abstract the backgrounding feature into the Xamarin.Forms library. Instead, we going to continue to rely on the native APIs to execute our shared background task.
Further information for this topic can be found here:
https://robgibbens.com/backgrounding-with-xamarin-forms/

Reminder on windowphone

I write a application use notifycation on winphone 8. My application require send URI continuous to server every 30 seconds. My problem, i used reminder of winphone, but it can't use webbrowser call request in reminder.
My code:
public MainPage()
{
InitializeComponent();
var reminder = new Reminder("MyReminder")
{
Content = "Sending uri to server...",
BeginTime = DateTime.Now.AddSeconds(30),
webBrowser1.Navigate(new Uri("http://nhomxe.vn/device_register?uri="http://...", UriKind.Absolute));
};
ScheduledActionService.Add(reminder);
}
I think you're misunderstanding what the Reminder class is for and how to use it.
The Reminder class will display a prompt to the user with a piece of shell UI and allow them to tap on it to open your app. (Similar to an Alarm which also displays UI and allows you to customize the sound that is played but doesn't support a direct link to the app.)
The code you have written doesn't compile because you are writing the code to execute inside the object initializer which won't work. You also appear to have a string concatenation issue but this may just be a spurious quote(").
If you just want to make a request to a URL endpoint you also don't need to load it in a browser.
Assuming that you're wanting to send a message to your server every 30 seconds while the app is running then you could just do this with a Timer.
Like this:
var timer = new Timer(
state => new WebClient().DownloadStringAsync(new Uri("http://blah.blah/")),
null,
TimeSpan.FromSeconds(30),
TimeSpan.FromSeconds(30));
Obviously add error handling, etc.
It is not possible to have your code run every 30 seconds when your app is not running. If you want to do something when your app is not in the foreground then you need to look at using Background Agents.
You can use periodic task if you want to fetch information every 30 mins.

Resources