Is there an Android standard or coding convention / best practice that says whether or not an app should Exit (not running in background) or minimize (running in background) when the user "backs-out" of an app?
For example, you are on the home page of an app. What is the best-practice for handling the back press?
The obvious answer is to let android handle it's own back button press, which in turn exits the app. But is it okay to override and minimize?
Maybe this will help
"App follows Android Design guidelines and uses common UI patterns and icons:
App does not redefine the expected function of a system icon (such as the Back button)".
Android Core Standard Policies
That depends on the kind of application you are making in my opinion.
If for example you have an application that needs to save something to a database or whatever when the user clicks the back button, I would agree you just minimize the app. But even then, after the app has done saving, it should exit.
But if possible I would suggest you exit the application, this will also let the phone free up memory/CPU which can be used by other applications etc. It will also save battery.
And of course, this is the expected behaviour for an Android user: If you go back, you close the application. You don't want to confuse your users ;-)
Related
Original Question (Listen to hardware buttons press)
I am wondering if it is possible to listen to the hardware buttons of a phone using Ionic / Cordova.
The important thing is that this should also work when the user is not currently using the app like somehow through a background service?
Basically I want to take a screenshot when the user presses the volume down and the power button at the same time in a hybrid app using Ionic. The app then offers to edit that screenshot or save it directly.
I have done some research and found the cordova events to listen to those buttons. I also read that the pause event should be fired when the power button is pressed. Anyhow, I don't think listening to those events would work outside of that app?
Original Question Conclusion
After some more research I conclude that this is not really possible using Cordova / Ionic. Even the native implementations of this problem seem to be more of a hack than a clean solution. The reason for this is, that the app currently on top should have the control of handling the various button events. You could interfere with another app and you always need to run a background service. Anyhow, all the solutions I saw seem too dirty for me.
Updated Question / Reevaluation of the problem
Basically I want to take a screenshot when the user presses the volume down and the power button at the same time in a hybrid app
using Ionic.
If I can't solve the current problem I have to rethink it. So:
Actually, I just want the user to have the ability to take a screenshot in a way that offers a good usability experience.
There are various ways I can do that as an alternative to pressing two hardware buttons simultaneously.
Option 1: User presses a button "Take screenshot" -> the app goes in the background, a screenshot is taken from the underlying app, the app comes back to the foreground.
AFAIK this wouldn't even work in iOS, only Android offers a "draw on top of other applications", so in iOS the screenshot would simply be taken from the home screen in all cases...?
Option 2: User presses a button "Take screenshot" -> the app goes in the background and a notification is pushed.
This notification could say "Tap to take a screenshot". The notification panel (which is always drawn on top of other applications) disappears, the screenshot is taken and the app pops up. This could be done using Local Notifications and listening to the on clear, cancel etc. events.
The notification could even have custom buttons using OneSignal (see Action Buttons). One button could say "Add screenshot", another one could say "Done", so the user could even take multiple screenshots at once.
Option 3: A button could be added to the shortcuts that triggers the take a screenshot action. I don't know if that is even possible and if that works on all devices.
I would say the best solution would be to go with Option 2: Custom Action Buttons on a Notification. Notifications should be a must have on all devices and should always be drawn on top of the current app. So the user just swipes down the notifications and presses a button to take a screenshot.
I don't really have any prior knowledge to this topic so I would be glad if somebody could confirm or improve my thinking process.
Edit:
I have done a bit of research into this, mainly just to satisfy my own curiosity. I came across this plugin
https://github.com/katzer/cordova-plugin-background-mode/blob/master/README.md
It allows you to carry out task in the background.
Please note this from the readme file.
Store Compliance
Infinite background tasks are not official supported on most mobile operation systems and thus not compliant with public store vendors. A successful submssion isn't garanteed.
Use the plugin by your own risk!
This probably isn't a big deal on Android but there is an open issue with regards to Apple app store submissions being rejected. Read through the issue to see how others over one this.
https://github.com/katzer/cordova-plugin-background-mode/issues/122
Original Answer:
If you want to take a screenshot there is this plugin:
https://github.com/gitawego/cordova-screenshot/blob/master/README.md
Maybe you could listen for some other events whilst using the pause listener. If they are activated then using the screenshot plugin referenced above call:
navigator.screenshot.save(function(error,res){
if(error){
console.error(error);
}else{
console.log('ok',res.filePath);
}
});
I want to create an accessibility feature for Android where a hint appears whenever a person presses or long-presses on an app icon. To do, this I have a few questions:
How to identify when a user clicks on the icon of an app on the
homescreen or app launcher?
How to make use of this event to then
pull appropriate information and present it to the user?
Do I need to develop a custom launcher app to be able to identify user presses etc.? Or can I somehow retrieve this information from whatever launcher a user uses and give the hint?
There are a couple of different ways to get after the information you are looking for.
The first option is to create a custom launcher, as you suggested. This has obvious drawbacks. Most obviously, having to re-create an entire launcher applications is obviously difficult, and likely to create more issues than fixes. You could search out an open source launcher application, and attempt to add your feature to this, however you'd then be reliant on the purveyors of this codebase to accept your feature.
The second, and the way I'd recommend, to access this information is through accessibility services. This information is available to services like TalkBack. It is essential to how they function. The difficulties you'll face here are interacting properly with the numerous launchers available out there. However, most of these launchers are based off of a similar starting point, which is the Android base open source launcher. As such, the portions of the launcher that you care to interact with should be coded very similarly in most launcher examples.
The downside to this approach is that only one accessibility service can be active on a device at a time. So, users who are partially blind, who may want to use your feature and TalkBack at the same time, won't be able to. It is of course to you to determine which set of difficulties/benefits you'd prefer to deal with, but these are your options.
I want to be able to tap the statusbar and the contents in the displayed app to be scrolled up to the top.
Is it technically possible that an app intercept my tap and send the appropriate command to the active app? I have noticed for example that AntTek quick settings shows a drop-down window when swiping down from statusbar. While using the app I did also notice that even by just tapping the statusbar (before beginning to move the finger down), the app seems to already interact with the touch as it dims the screen brightness in preparation to display it's "window" (sorry I use the MS Windows term), so clearly a statusbar tap CAN be sensed by an app.
Starting from this, I wonder if such an app could then send a message to the active program telling it to scroll up.
Is that possible? And if yes, the message must be customized to a particular app (let's say the browser as the most important) or is it standardized so the apps speak the same language between themselves?
I am not a programmer so answers with codesamples might be less helpful than a plain english explanation. Finding out that is possible would lead rather to pursuing a programmer to implement the idea rather than starting to develop it myself.
Thanks :-)
There is an XPosed-module which seems to do exactly what you want.
To use XPosed-modules, you'll need to root your phone and install the XPosed-framework.
The XPosed-module is called "Statusbar Scroll to Top" and its repository can be found here:
http://repo.xposed.info/module/com.mohammadag.statusbarscrolltotop
This will work for almost all app-lists, but for example won't work for browser-content.
If you want to scroll to the top of the page in a browser, then you'll probably do best to get a browser which can do that on its own. (For example Habit Browser has it built-in and respective plugins are available for Firefox.)
Yes it is possible. HiroMacro and Frep can do this, but it requires root. https://play.google.com/store/apps/details?id=com.prohiro.macro&hl=en
(how do they simulate mouse and keyboard interactions on other applications? i have no clue :/ anyone?)
Is it technically possible that an app intercept my tap and send the appropriate command to the active app?
No. One app cannot send fake input to another app, for security reasons.
An android app comprises of several activities. Each activity display a GUI that allows the user to perform a specific task. To take the user from one activity to another, app must use an Intent to define our app’s intent to do something.
An intent can be explicit in order to start a specific component (a specific Activity instance) or implicit in order to start any component that can handle the intended action.
Interacting one app to other app in android
google docs link
Is there any way to programmatically pause an Android app in Phonegap? I would like to mimic the behavior that occurs when you hit the HOME button. I've already had to overwrite the back button handler using this, and while in most cases I want it to do my action, when in a particular state the user would expect the app to minimize, and I want to replicate this behavior.
Keep in mind, on Android this is not the same as closing the app. That is quite easy to do with device.exitApp(); but I would like it to remember its state and keep running in the background. Especially if there's still an asynchronous job being done in the background.
Is there a feature in Phonegap to achieve this?
Possible duplicate of Manually pause an application in Android Phonegap, but I couldn't find some of the tools the OP mentioned there such as navigator, so I was nervious to totally edit and rewrite their post
The simple answer appears to be: no.
However, for anyone else that comes down this path, its not impossible. It's just that there isn't a feature of Phonegap to do it for you.
The Android equivalent of "sleeping an app" is actually just opening another intent. Specifically, opening the "Home" intent would sleep the running app and bring you back to the home screen. But as far as I can tell from asking around and scoping the docs, Phonegap doesn't have a direct way of opening intents.
What you (supposedly) can do is one of two things:
This plugin is supposed to be promising
Call the Java code that does it yourself using the means described here
Mind you, as of right now I've decided to not go any further with this, so I make no promises about either of those means, having not attempted them myself.
I invite anyone else who decides to pursue this further to update their experience here.
I am creating an Android application for a customer which will be pre-installed and distributed together with the handsets. Now the customer asked me to lock down the ROM to prevent the future users from using anything else apart from this one app. I.e. no browsing, no email, nothing which could create any costs etc.
Now after some googling it seems to be relatively straightforward to remove applications from an Android image. But even if I can remove the web browser, email client, the Android Market App etc, how can I make sure that the user will not reinstall those apps via the USB connector? As Android is just Linux I am sure there are ways of denying all users the right to install new applications (or actually denying them pretty much anything apart from using this one app).
If somebody could point me in the right direction it would be much appreciated.
EDIT:
To clarify things a bit, the customer does not want to use the android devices as phones, even though they are phones. With 100€ touch screen phones becoming available, it becomes viable to use those phones for just one specific purpose. In my customers case, the device will be used as something like a POS system: the employee uses the phone to process a certain kind of customer request, and for this the app needs to have a data connection which will accrue costs of course. Now obviously contracts can be set up that will oblige employees to pay any irregular costs themselves, but why make it that complicated?
This is not about taking freedom away from users but rather about using android phones as general purpose touch screen devices with a data connection that employees can use in a business environment without shooting themselves in the foot with unexpected high data connection cost.
There's not really a whole lot you need to do to make a single-purpose device. If you play your cards right, it should be something you can do without having to tinker with the ROM.
The quick-and-easy route would be to deploy your application as a replacement for the stock launcher, just like any of the other home replacements that are available. Setting that as the default would cover most of the opportunities for casual tampering, since it would leave no other way to launch or install anything else. The only other things I can think of off the top of my head that you'd need to do are snag the search button so it doesn't bring up the default Android search box atop your app and the green key so the phone app won't come up.
You would, of course, need a way to get to the original launcher to maintain the device and install new versions of your app. I'd accomplish that using a "Maintenance" menu item somewhere that asks for some form of authentication (e.g., a password), changes the home app back to the original and launches it. When you're done doing what you need to do, set your app as the default launcher and you're back in business.
Edit to address MAINERROR (now Octavian Damiean)'s comment:
Any activity in any application can register itself as a home application by adding an intent filter on the android.intent.category.HOME category. It's literally four lines in the manifest, and you don't have to write any code to support it. Take a look at lines 77-82 in the stock launcher's manifest for an example of how this is done. (Ignore the filters on DEFAULT and MONKEY; they're not necessary.) Once the activity is selected as the default handler for the category, it becomes the first thing launched at boot and what comes up when the Home key is pressed. HTC Sense, aHome, Panda Home, etc. all use this mechanism.
Launching the stock home (or any other application) explicitly is about five lines of code.
Side note: There's a application on the Market called Home Switcher that lets you launch any of the activities filtering on the HOME category or set one as the default.
Unless the handset manufacturer adds a lot of shovelware, the stuff that runs in the background should be inconsequential and won't get in the way.
There was a similar question already somewhere. You can indeed limit the functionality of your device by the amount you want or have to. In order to achieve this you will definitely have to build your own modified ROM.
You will have to touch the ROM because you will have to get rid of several applications running in the background. One you won't need them anyway and two as you don't need them they would only consume resources.
You might want to take a look at http://source.android.com there you will find more information about the sources which will hopefully direct you where you need.
Blrfl's answer is great, but it still has a problem: if the user long presses the HOME button, the recent applications popup will appear an the user will be able to launch another app.