How to write a background service in Android? - android

The "service" here is different form one of the application components "service" in Android. I mean that people can not see the app icon in launcher, and, the can not see the app in the program manager in Android.
The most important is that I don't want the user notice the existence of the app.
Is that possible? Is it a "service" in Linux?

Without ROM modifications, you can't make a linux service. I will tell you what you CAN do.
First, your requirements
Not see the app icon in launcher: This can be done by simply not having an activity that supports the ACTION.MAIN and CATEGORY.LAUNCHER intents.
Not see the app in program manager: Unfortunately for you (but fortunately for all users) you can't get around this with a normal application.
Have a service run "all the time": The best you can do here is start a foreground service upon boot of the device. This will cause a notification to be in the users notification bar, but its really the best you can do on stock phones.

Related

Android Oreo: Is there any way to auto - start the application on mobile reboot?

I am developing an application for a business entity. That application should run in the background in every employees' mobile phone. Employees are mostly salesman. The application basically detects location changes and suggest the salesman where they might visit. A kind of reminder application. It also lets other salesmen see where are their teammates.
Right now I am using a foreground activity and it works fine till the system forcefully doesn't kill the service or the phone doesn't reboot due to manual activity or battery discharge.
Ones the application is closed, as of now, the managers in the firm needs to call salespeople to turn on the application once, as on application start it automatically turn on its foreground service. But this is really an extra burden on the management team which can be automated.
I am ok to have any settings based or code based solution. One solution is to root the phones of salespeople and install some extra utility app or write the code based on root APIs, but this will be too much for this simple task.
THe permission RECEIVE_BOOT_COMPLETED was not added properly in the manifest. After adding the permission it worked calmly. In on receive method of the broadcast receiver, I am starting the foreground service.
At the moment, the best way is to use WorkManager https://developer.android.com/topic/libraries/architecture/workmanager/ Yes, it still alpha, but works very good.
From other side, you could work on automating the task "managers in the firm needs to call salespeople to turn on the application once". I mean, an app/backend could automatically call the salesman (with some pre-recorded message) or send SMS to them.

(Android) Keep service running, even when app is stopped by force

I have created an app. Works great, but I want some same functionality as gmail uses:
When I receive a new email, I get a notification. I inspected my phone and saw no services or applications running that look like the gmail-app.
I have investigated the AlarmManager and services, but as soon as I stop the app both don't work anymore.
Could someone give me a hint how to accomplish this?
Thanks in advance
I inspected my phone and saw no services or applications running that look like the gmail-app.
Partly, that is because Gmail gets such notifications via broadcast Intents from the OS, via the subsystem we see as C2DM (which is why you do not see a process). Partly, that is because Gmail is part of the firmware and may get some extra benefits as a result, in terms of resisting the normal behaviors that befall an app that is force-stopped.
Could someone give me a hint how to accomplish this?
You can't. Particularly on Android 3.1+, if your app is force-stopped, it will not run again until the user manually runs one of your activities (e.g., from the launcher).

How to know if a particular application is currently running?

I am trying to build an application that can detect if the Messaging application is currently running so I can foreground one of my activity to prompt the user for a password.
What I have done:
1)Created a service that starts running after startup.
Now, what is confusing me:
1)Is the messaging application a process, a thread, a task, or something else?
2)What is its package name that i should write to check if running?
How you can check if an app is running you can read here: https://stackoverflow.com/a/4213851/1183280
Now you have to know the package name. As there are many different messaging applications for android (stock Android, HTC Sense, Handcent SMS, etc.) you will have to check more than just one. I think the one for the stock app is "com.android.mms".

Android phone as a dedicated device

We want to use Android mobile for dedicated application. Can somebody suggest how can we make it happen.
Here are the requirement:
The phone when started, should launch our application., so the user cannot launch any other application. The application will be a 1D barcode reader.
The application should be live as long as the phone is up and running, user cannot close the application at all.
Thanks for your help.
Regards,
Manish
Android after boot is complete sends a bradcast intent:
android.intent.action.BOOT_COMPLETED
if you listen for this intent, you can launch a service that in turn launch your activity.
In the Activity you have to take care of the user's interactions that explicitly close the activity, like home button, back button and camera button press.
Setting your activity to be full-screen also should prevent the user to use the notification bar to interact with notification like those from market-app that can close your activity.
Finally, your activity can be killed by the system by various and uncatchable reasons: in those cases, the service that first launched your Activity comes in handy, as it can periodically monitor the general state of the application and relaunch components as needed.
Check out the new Android Enterprise solutions for your use case.
https://developers.google.com/android/work/overview
Its well documented. You can either use
Android Management API to provision the devices and apply policies to the device which will be applied to the device using Android's Device Policy Controller (DPC) or,
Use Google Play EMM API and develop your custom DPC
It depends upon your use-case really, but the first solution set should serve your purpose
I'm afraid there's no single answer to this, but you need to work on multiple fronts.
One of these fronts is preventing user from running other applications: for this there are applications sold on Android Market that can put other apps of your choosing behind passcode.
You need to combine this with automatic launch, but I don't yet know how to do that.

Background application without ui

I am new to android development. I want to make one background application, so that it keeps running in background, and it's without any UI, and even its icon do not appear on desktop.
In short it's a stealth application.
Is it possible?
This is certainly possible. To create an app that does not have an icon in the launch pad, just remove the Activity with the android.intent.category.LAUNCHER category from the AndroidManifest.xml.
To implement your background application it strongly depends on what you want to do. You can create a Service for long running tasks, BroadcastReceivers to react to specific events or Activities with intent filters.
Be aware, however, that your application will be visible in both the file system and in the settings under 'Manage Applications'.
Yeah it's possible look up Service
Read more about the service in tutorials
ServicesDemo - Using Android Services
How Android Services Work
Android Service creation and consumption

Categories

Resources