Monodroid: wake application - xamarin.android

How is it possible to wake the application from code?
I am writing a simple timer and when time goes out it displays picture on main activity. But this means that application should stay on screen all the time. If user switches to another app (or simply presses Home) my Activity is no longer visible and I need to show it on screen again (switch back to my application) in the way similar to standard Android Phone or Timer pops up.
So there actually are 2 questions:
How to get application on "top" of screen?
How to correctly display application when screen is locked?

For that you would need a service that starts your activity when that timer triggers.
You can take a look at the Android Alarm Clock source code for how to have an Activity Shown even on the lock screen: https://github.com/android/platform_packages_apps_alarmclock/blob/master/src/com/android/alarmclock/AlarmAlertFullScreen.java
Note especially lines 85 to 90, here flags are added so that it is allowed to be shown on the Lock Screen. This should of course work with Mono for Android as well.
There is also a nice answer here to your questions: Wake Android Device up
It should be fairly easy to port to Mono for Android.

Related

callkit default UI for outgoing call

I use outgoing call only in the app on iOS 10.3.3. If I do not have connected headphones to iPhone then pressing on lock button will end the call. But what if I have connected headphones?
Sometimes (after lock) I see native UI. Sometimes I see just time counter without any buttons (like speaker, mute, etc). Is there any special flag (or I should implement some delegate?) to allow see native callkit screen after pressing lock button? It looks like I tried everything here...
P.S. I know this screen could be showed while user take a call while iphone locked. But I would like (and I got it several times at least) to get this screen on lock device.
Did I miss something?
I hope that is the native iOS behaviour, callkit works similar to the native calls.
So customisation can't be done on call screens in lock mode.

Objective C - Detect if finger is held on screen at app startup

I'd like to perform an action when the user has their finger held on the screen when my app startups.
To give an example: When the App launches and the launch screen is showing up, the user has a finger on the screen as long as the first ViewController appears. When the first ViewController gets into the viewDidAppear() function, I want to detect, that the users finger is on the screen and perform an action, like f.ex. jumping straight into the lastest received email. Basically this is supposed to be a kind of shortcut to an main action.
Is there any method to detect an already laying finger on the screen? To be exactly I'd like to check for the tap in viewDidAppear()
Unless the nature of Time has changed since the last time I checked, your app cannot detect what the user was doing before the app launched. The app, ex hypothesi, was not running at that time. And the mere presence of a finger on the screen during app launch will not generate a touch event that the app can detect.
The system can detect it, however, since is running before your app launches. That is why Apple added force-touch Shortcuts (for appropriate hardware). The only way you can do what you're asking is to rely on that API. Hardware that lacks this feature will simply have to do without this feature.
(After all, this is how Apple makes money: by trying to make users jealous of hardware they don't have, so that they buy new hardware. You would want to rob Apple of its income by reading this feature backwards onto old hardware, even if you could, now would you?)

How to avoid an Apple Watch 2 App to stop running after a few seconds the screen turns into black?

I am developing an Apple Watch2 App. My app stops running after a few seconds the screen turns into black but I want my app to run on the screen even after the screen turns into black. So that the user can see my app anytime on the screen by not tapping to the app icon again.
I tried to add a timer and then an animation and also made dynamic UI changes to avoid my app to stop running but it didn't work - after a few seconds the screen turns into black, the app stops and the main watch clock screen comes into display.
I saw that it is possible to do this functionality in "Apple Workout App". When the user starts a timer, even if the screen turns into black, the app doesn't stop running so the user checks the timer anytime she/he wants. So please let me know how I can get this functionality?
Thanks,
E.
You can't control this from your app; The user selects the behaviour for their watch using the Apple Watch app on their phone. They can select "Show watch face" (the default) or "Resume Last Activity". They can also select how long the display stays on for on a tap; either 15 or 70 seconds.
Some Apple apps such as Maps, Remote and Timer can override this setting and if a fitness app has an active HealthKit workout activity then the watch will also resume the last activity on wrist raise/face tap. If your app isn't using HealthKit for a workout activity then you have to live with the behaviour the user has selected.

iOS app printing while running in the background

I have an iOS app that automatically prints a receipt to a thermal receipt printer when an order comes in and works great. However, if the app is in the background, it does not print. Is it possible to allow it to print while running in the background?
There are only a few occasions you are allowed to run certain tasks in the background. See the Apple documentation: https://developer.apple.com/library/ios/documentation/iphone/conceptual/iphoneosprogrammingguide/ManagingYourApplicationsFlow/ManagingYourApplicationsFlow.html#//apple_ref/doc/uid/TP40007072-CH4-SW20
For example: playing audio, fetching the user location, sending notification or certain data from network in the background is allowed. Running your own logic during a background service is, as far as I understood, not allowed (like running it one hour after your app is gone to sleep/background mode).
The only thing that is perhaps an option, is to utilize the time your app has to finish an task after the home button is pressed. There is a timelimit however of 10 or 15 minutes.
I don't know if this is suitable for your situation?
See this stackoverflow question: iOS application executing tasks in background
And this particular piece of code to run the task in the background: https://stackoverflow.com/a/11809211/2740112
Another option is to use Guided Access, which is introduced since iOS6.
With it, you can prevent exiting the app. It's only usefull when using only the app on the device that needs to be used.
Information below from http://www.assistiveware.com/support/faq/page/136:
To turn on Guided Access, do the following:
Go to the Settings app on your device's home screen.
Tap General.
Tap Accessibility.
Under the Learning section (scroll down if necessary), tap Guided Access.
Toggle Guided Access to ON.
Tap Set Passcode and enter a four digit passcode. You will be prompted to enter it again.
(Optional) Toggle Enable Screen Sleep to ON if you want to be able to put your device to sleep with the Power button, otherwise the Power button will be disabled.
To start Guided Access for an app and prevent it from being exited, do the following:
Open the app that you want to lock in.
Quickly press your device's Home button three times to bring up the Guided Access menu.
Tap the Start button in the top right corner of the screen to activate Guided Access. A message stating "Guided Access Started" will briefly appear.
To end Guided Access for an app so it can be exited, do the following:
Quickly press your device's Home button three times to bring up the Guided Access menu.
Enter your four digit passcode when prompted.
Tap the End button in the top left corner of the screen to end Guided Access. A message stating "Guided Access Ended" will briefly appear.
Here's the knowledgebase article of Apple: http://support.apple.com/kb/ht5509

Monitoring Significant Location Changes, App closed GPS signal (Arrow)

First of all I hope don't repeat any topic, I have spent a lot of time reading on internet about this before ask.
I'm developing an app for iOS => 5 and I need get the user location, but I don't need always a great accurate position, so when the app goes to background I change the normal location mode to Significant Location Changes and when the app come to foreground I stop the significant location change mode and get back the normal location mode, that's all goes fine,
my problem is when the app goes to background mode or even the user KILL the app the GPS signal (the purple arrow) still appear ALWAYS, even after restart the device, the only way to make disappear it is un-installing the or disabling the significant location changes when the app goes to background, but I need this mode working when the user goes to background mode, maybe not when the app is killed.
I don't know how to stop the service when the user kill the app... because event "applicationWillTerminate" is not called if you have multitask ON.
My main reason because I don't want the purple arrow appear always, even the app is killed is because I don't want the user think the app is drying the battery... so the user won't want the app installed.
First question: Is normal that the purple arrow appear always, even the app is killed if the Significant location change is enabled for the app?
Second question: Is any way to change this, to stop the service at least when the app is killed to hide the purple arrow?
Thank you all.
Sorry for my english if something is wrong.
After few days researching to be sure about this service, seems like there is NO way to use significant locations change in the background without the arrow in the top bar. I have been testing with different apps and reading through internet and nothing to solve this.
The only ""way to solve"" this is disable multitask mode in the app and disable the significant locations change in the event "applicationWillTerminate" but don't make sense... I'm losing the background location always not only when the app is killed... so is not useful.
It's bad... is a really good service to get locations saving battery but as user and developer I don't want an app that make appear this icon ALWAYS even after the app is killed, as developer I don't want that people uninstall the app for this reason and as normal user I don't know what mean this icon if is normal GPS or Significant locations change and what mean this... if my battery is being drain or not.
The other option to get locations in background task but has a big impact over the battery....
I hope apple fix this in future versions... adding at least a new arrow or showing only when a new location arrive instad of always or allowing to stooped when the app is killed.
All this has been researched over iOS - 6.1
Thanks to all.
When you use the significant location change service, the OS keeps your app running. If the app is in the background and is killed, the OS restarts it, so the purple arrow will always show. When a new location is detected, the app is restarted. From the docs:
If you leave this service running and your app is subsequently suspended or terminated, the service automatically wakes up your app when new location data arrives. At wake-up time, your app is put into the background and given a small amount of time to process the location data. ... To stop the significant change location service, call the stopMonitoringSignificantLocationChanges method.
Hmmm, interesting. I've just seen that problem with another app - seeing the arrow still active made me want to disable location updates for that app so the problem is real. Best thing I can think of is to have some kind of timer to disable the location monitoring after a certain amount of time if that is appropriate for your app.

Resources