iOS 4.2+ allows certain webapps to run in the background, without any special requirements.
How is it possible to run a webapp in the background on Android (to continue playing music, for example)?
For an example, see https://coolaj86.com/demos/sandbox/html5-audio-tag.html
Begin playing the music sample on your iPod/iPad/iPhone, then click to "background" the app.
Double click and swipe from left to right in the lower menu to access the player controls.
That is done by using background Services.
As Robby said, to do this you need to use a Service.
Obviously you can't have a "background web page" just like you can't have one of those with any browser. The solution is to use WebView's setJavascriptInterface() to create an interface between your background service and HTML5/JS front-end in the WebView. With a javascript interface, you can create your own bindings to call into Java code from inside of your javascript.
The service can be used to preserve the background functionality, but when the app comes back into the foreground the WebView needs to bind to it via javascript interface again, get the data it needs, and populate its UI.
This is not really an answer, but wouldn't it be great though, if we could request a webpage to continue running in the background. Of course the page should need an explicit (and at all time revokable) consent from the user, but that doesn't seem like a completely impossible thing to handle for the (native) browsers? :( We already prompts the users for permission to use other APIs like the location API - why not also a run-as-a-service API?
It would be such a huge step forward for all webapps to be equal to native apps in my opinion! <3
Related
I have a nativescritp app, which receive phone calls.
When the app is not running on foreground, it still receives the calls, which is fine.
What I need to do is to "load" / "run" / "show" the application on the screen, so the user can answer the phone call or decline it.
It may not be quite straight forward as building an app and there are no ready made plugins available to achieve this.
For iOS you will have to implement CallKit and for Android you will have follow the set of procedures explained here.
FYI, with iOS your normal code won't run any longer if app is minimised. With Android you will have to implement the android.telecom.ConnectionService as explained in the link above, refer onShowIncomingCallUi() for showcasing UI for the call.
If you are not proficient with marshalling native code (iOS & Android) then I would suggest you to start there.
I created a background service on android and I have two buttons which appear on the top of the screen all the time. I want to use these two buttons like scroll down and scroll up. But these two buttons should work on any kind of applications like Instagram, Facebook, Twitter and so. So, it means it should work in all applications that use scrolling.
I search a week on internet but I could not find any solutions.
This is not possible, sorry. Something like this would require your Service to have access to the Views of the applications and this would be a huge security breach, because you could read values from them and so on.
You could achieve this with a custom button code broadcast (so basically your buttons would act as physical buttons on the device) but this would most probably require you to have system-level permissions and some level of cooperation with the OEMs.
Android Activity class has a method called dispatchKeyEvent(), which could let you simulate the key input (with some limitations) but this is not present in the Service class.
Sadly this is not something you can do in Android. Typically you should not be able to touch views with a background service, the point of a background service is that you do some work in it (for example upload files to your web server or get some data). You CAN send a signal from a service once you're finished doing work to tell an app that something needs to happen, however the app needs to be specifically coded to respond to this broadcasted event.
If you wanted to do this with an app that you have developed, that can be achieved by using the onReceive method of say a BroadcastReceiver, however you cannot specifically define the behaviour of other apps as this would represent a security breach in Android.
I am developing an app that is used by just a couple of people at my work. It's an easier way for them to handle support cases that they get while off-hours. I've created an HTML5 site and made it so that it can be launched fullscreen from their Android phones by using the "Add to Home screen" option within Chrome. That works great. Now, I want to make it so that when they get an email notifying them of an incoming support case, they can click the link for the case and open the app instead of it opening in a regular web browser. Otherwise, the usefulness of fullscreen is lost.
Unfortunately, I just don't know how to do it. Every search I make regarding this brings up information on Intents, but all my searching on intents assumes that I'm developing an Android-native application, not an HTML5 app. Is it possible for apps that are created via the "Add to Home screen" option to listen for intents? If so, where do I begin?
Thanks.
No that is definitely not possible, you will need an Android application which uses an Activity class otherwise you won't be able to listen to react on intents or listen to broadcast receivers...
But you can create a simple application holding a WebView which loads your HTML content. Then you will have the ability to use Intents and Broadcast-Receivers and pass on received information to your HTML content.
Is it possible after a user has opened the android browser to catch when the press home / onpause() in order to push the browser to a service or just to start the browser from a service in order to keep it open when the user presses home or locks the phone?
For instance, If the user is listening to a internet stream through the browser and they press home or lock the screen the audio will be cut off. However I would like to keep the browser open so the audio continues to play. I'm under the impression that a service would be the only way to accomplish this.
In fact this is (and should be) impossible within Android. All clicks and things of that nature should go through your app. There are some bad situations where you can do this, and it's widely considered to be an Android bug. Basically, the idea is that you shouldn't be able to control anything outside of your app. Instead, you can only accept clicks within an app, and getting this behavior would require extending the standard Android browser with your own implementation and having users use that instead.
To see why you can't do this, consider the kinds of security implications that it would have, you could control and reroute functionality from other apps to hijack their standard user experience. There are some situations (you can google "clickjacking" to see some) that have been possible in earlier versions of Android, but in any non malicious app, you really shouldn't be doing this.
I was able to create a webview within my app and started a service when the home button (onpause) was pressed that enabled the broswer to continue the playback of flash while the app was in the background or the screen was locked. So while I wasn't able to use the capture the browser outside my app I was able to make an effective webview to emulate that experience.
I followed the instructions here to create the webview and then made a service. The piece of code (android:hardwareAccelerated="true") that allowed the flash to play properly was:
<application android:hardwareAccelerated="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
in the manifest. It works great! (The api must be 3.0 or greater however)
Is it possible to customize the call screen in Android? Example would be, two users have the same application, user calls, but the other user cannot pick up, so they respond with some type of predetermined image baked into the application.
Is this possible?
Does this break any rules?
The built-in Phone application is open source, so you can clone it and modify it to your own needs. This will let you make/receive calls using your custom UI (I believe you can receive. It looks like there's ACTION_ANSWER that you can listen to and handle). Of course, the user will be prompted on what application to use for theses actions and you'll have to convince your users that they should use your app instead of the built-in one.