How to start activity from a running service - android-automotive

I work in the automotive industry and we are using not Android mobile but we are using Android Automotive . In Android automotive you cannot have a launcher activity. Instead a service will be called by the OS. So in this service I want to start an activity to show a GUI. Is that possible ?? I tried it like that.
Intent dialogIntent = new Intent(this, AddressBookActivity.class);
dialogIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
this.startActivity(dialogIntent);
And in the emulator I use my gui was shown sometimes. But strangely it did not work all the time.

Yes . It does.
Android in general have full control on what will be run on Force Ground ( top activity in main screen).
So not all activity request to start implicitly "will be start"
It can be start in some case if Android system check all condition like:
Memory, Current Activity priority ...vv, Idle time and so on...
So it is not strange if your beheavior like you mentioned.
You can also check logcat to see what exactly happend to your Start request.
Sometime it related to permission ... for service running in Backround (likely in this case).

Related

what is a simple way to create an app that runs in both background and foreground in flutter?

I am trying to create a flutter app that sends notification every time there is new entry in stream builder, it works fine when the app is on or opened but I want it to work and receive notification even when it is not opened , I have used workmanager to make the task work in background but it is not working ...the code for it can be found here code
Flutter apps by nature are supposed to run on a UI thread or foreground. The background tasks you are asking for are features disclosed by each individual platforms.
In case of Android, you can create a a Background Service to accomplish the tasks you need to perform when application is closed. The link to the bacground service is as follows: Creating a Background Service
In case of iOS, see this link for creating a background task. Other platform implementation will be as like above, so please have a look into each platform specific background process.
UPDATE:
Please have a look into the package Flutter Background Service. This package helps to deal with background tasks setup from flutter side even when app is closed.
NOTE:
Q: Why the service not started automatically?
A: Some android device manufacturers have a custom android os for example MIUI from Xiaomi. You have to deal with that policy.
Q: Service killed by system and not respawn?
A: Try to disable battery optimization for your app.

AirConsole phone controller screen not loading

I've set up a project in Unity using AirConsole. I was able to put together a simple game pretty quickly, but I've since run into issues. I was initially developing on a Mac and then switched to my work computer which is a Dell PC. On my Mac I was able to test my game using the simulator in Unity. Since I switched to my PC I have been unable to connect from my phone to the webserver in the debug simulator. The phone gets through the "Enter the Code" screen, the developer console makes a connection noise, but then my phone just sits at the "Loading..." screen.
I've reverted back to the Pong sample project to confirm that my code is not the problem. I've tested the phone using both Chrome and the AirConsole app. I've tried temporarily disabling my firewall in case my firewall was blocking the ports. If I run the simulator in Browser Start Mode = "Virtual Controllers" the controllers on my PC load fine, but I'm still not able to connect with my phone. I'm using AirConsole v1.3.0.b which was still the most recent version when I posted this.
Steps to resolve this issue:
Start the game using the simulator.
Make sure the virtual controllers of the simulator load your controller.
If that is the case try to load the controller.html directly in the phones browser. Assuming your run your game on in the simulator using http://www.airconsole.com/simulator/#http://192.168.0.2:7834/ then take the part behind the # and append controller.html. In this example try to load: http://192.168.0.2:7834/controller.html on your smartphone. Note that this controller wont be working - it's just to try if the page that AirConsole loads internally works. If this does not work, you are either not in the same network or you network has client isolation activated (this needs to be deactivated). To resolve this, check: Using Airconsole on a standard University/Corporate network for dev
If this also works, you probably have javascript errors before the AirConsole constructor is called. Use chrome to remotely debug the phone browser: https://developers.google.com/web/tools/chrome-devtools/debug/remote-debugging/remote-debugging?hl=en
Update: here is a detailed guide for Unity
https://developers.airconsole.com/#!/guides/unity-ngrok

Fire Chrome Alarms from background service when using cca Google Chrome apps

Experimenting with Mobile Chrome apps API: ( https://github.com/MobileChromeApps/mobile-chrome-apps )
What I'm trying to achieve is the registering of my chrome alarms without having to crudely start the apps' main activity as this causes a bad user experience.
The challenge:
I have specified a chome.alarm which gets successfully registered when I open the app ('cca run android ' for example). These alarms are specified in a background.js file, which is declared as a background script in the manifest.json file.
I wanted these to be registered automatically on boot, therefore I implemented a background service and thought I could simply call the app to register the alarms specified in the background.js file. However, the only way I can find thus far to achieve this, is via a call to launch the apps main activity via an Intent from within the background service as explained in more detail below.
On boot, my background service simply invokes:
//Launch main activity..
Intent LaunchIntent = getPackageManager().getLaunchIntentForPackage("com.company.appname");
startActivity(LaunchIntent);
The above launches the app into its main activity and the aforementioned chrome.alarms are registered as desired. Happy days! A massive downside to this, of course, is that no user wants the full blown main activity window to open on boot.
Please advise if there is a less clunky way to have the chrome.alarm specified in background.js registered at boot by a background thread. I do not wish to open the mainActivity of the app, yet this is currently the only way thus far I can see to get them to be registered. It is preferable not to register these alarms from within the Android SDK as I intend to stay as close to using web APIs and want to use background.js as the hook to do this keeping things in-line with chrome web apps as-well-as the android platform.
What I have done:
A cca (chrome mobile web app) app which registers a background service natively (I extend BackgroundService) as a plugin and register this to run at boot time. This is the only 'native android code' in order to load the app at boot-time.
Upon booting android, this background service then simply issues a startActivity(LaunchIntent) in order to open the app. In doing so, my chrome.alarm specified in my background.js file get registered successfully. If I don't do this, my chrome alarm specified in background.js do not get registered until I manually open the apps main activity. Therefore I use the backgroundService to open the apps main activity.
This is not at all ideal, I would simply like to somehow have my chrome.alarms registered without crudely having to launch the apps main activity window.
Is there a call which I can place in my BackgroundService to have only the chrome.alarms contained in my background.js file read and registered to fire?
Thank you for your time.
First, thanks for using Chrome Apps for Mobile! (Note: I work on the project)
Sorry that our current bootstrap is "crude" and "clunky", and we agree that it is. You can track this issue for progress on our effort to replace our current Background-scripts-embedded-in-main-Activity-webview strategy with a real background service and multiple window support. Basically you've summarized exactly our plan and existing limitations.
This work is actually scheduled for the near term, and will certainly be done before the end of the year.
As well as chrome.alarms, this feature is quite important for chrome.gcm and chrome.tcpServer (among other reasons).

Keep infomed for Device location will Application in Backgroud

I'am developing an application that keep a WebService informed for device location each 5minute (for exemple) :
So when the application leave the foreground execution and enter background I have to lunch a timer who
1 - Update the device location
2 - Send the location to a web service
How can I perform this action ? Or do you know any code exemple that I can follow to achieve this design ?
Thank you for your help !
Doesn't look like anyone gave you a solid answer, so allow me.
There is no iOS approved way of running a 5 minute (or any minute) timer in the background (unless your app is VOIP or music). What you CAN do is register your app as requiring location services in the background (edit the info.plist and add a key Required Background Modes and then add a value App registers for location updates. What this means is your locationManager:didUpdateToLocation:fromLocation: method and corresponding region monitoring/SLC methods will fire on location change, but Timers will not work at all.
The reason why is that timers require a run loop (a thread executing code) to be running and must piggy-back on that thread, but when the app is in the background even when executing code from the LocationManager, the run loop that executes the code almost always finishes before your timer would go off.
Hope this helps!
you cannot do this (on iOS).
(unless your app requests permissions that are meant for Navigation apps)
Hello #Aladdin Gallas,
I have developed a simple application that supports background location updates for iOS and Android in Xamarin.
The app pushes a new location every 2 seconds (you can change it to 5 minutes if you want to).
There is a feature I haven't been able to add; it is to keep the service up when the user closes the app (for iPhone). Other than that, as long as the app is open, even if the phone is locked, the service keeps running.
You can take a look at the application as a reference if it helps.
GitHub Repo

Is it possible to run an application automatically on boot up as background service in J2me?

I wanted to develop Location Based Service in J2me which has to start automatically on Boot up & run as background service ,which will send periodic location to the server? How can i implement it on J2me ?
Any Suggestions,tips or examples will be really helpful.
Thanks
Yes, Srizan,
It is possible using the Application Settings. You need to set the Auto Start setting to true in Application Settings.
Yes I am also trying same, I went to some extent.
Yes is possible to do ,with help of Push reg which is with MIDP 2.0 Mobile app can be called after every 10 sec or so (I didn't Coded this yet)
and. to hide app use this line Display.getDisplay (this).setCurrent (null);
it will run be shown with your tab or run app again.
I am still getting some problems like, Internet will Go Off when Mobile screen goes Off.