I'm working on a calling feature app and app need to open certain activity after getting push notification. In order to open an activity I need some authentication which implemented in a service. I'm getting the push and after authentication successfully it start the activity but system destroy the service because Android screen still unlock(Everything works well when app is not locked). I needs the following things:
Need to keep service alive
or
Unlock the phone programmatically.
Looking for some help.
Related
Based on https://developer.android.com/guide/components/foreground-services#bg-access-restriction-exemptions we can only start using camera in foreground service without launching app (making it visible) if:
The service is started by a system component.
The service is started by interacting with app widgets.
The service is started by interacting with a notification.
The service is started as a PendingIntent that is sent from a different, visible app.
The service is started by an app that is a device policy controller that is running in device owner mode.
The service is started by an app which provides the VoiceInteractionService.
The service is started by an app that has the START_ACTIVITIES_FROM_BACKGROUND privileged permission.
In my case I need to open camera in background without user interaction and when screen of device is off, in such case as I understand it's possible only with:
The service is started by a system component.
The service is started by an app that is a device policy controller that is running in device owner mode.
The service is started by an app that has the START_ACTIVITIES_FROM_BACKGROUND privileged permission.
System component - though this one I guess also isn't not for developers, because it means a system app - system component?
And also what about START_ACTIVITIES_FROM_BACKGROUND, can a regular application have this permission, how to grant it? Can't find any info about this one on Android site
If it's also only for system apps then the only choice is device policy controller to open camera from foreground service which is started in background on Android 11+?
p.s. if anyone is interested why such functionality may be needed. It's needed for dashboard camera apps. Users have a smartphone in their cars and when they for example turn on the phone (if it wasn't powered) they want video recording to be started automatically without their interaction.
So it would start recording automatically in all cases like a real dashcam device
But Android 11 brings these limitations...
This is no longer seems possible in Android 11 and up (for very good reasons!). What is possible is as soon as the device connects to a carkit or car radio (via Bluetooth, you can register a BroadcastReceiver that listens to intents with action ACTION_ACL_CONNECTED), you post a local notification. The user can launch the foreground service then by interacting with the notification.
I want my app to silently start in the backgorund, without showing any activity on the screen.
It has a service which needs to perform 2 upload tasks.
I'm learning about service, but all boot-up launch of apps talks about showing the activity.
I need no activity to be shown.
Is that permitted after Oreo?
You didn't say what should trigger your app from background. I presume some kind of an Intent. As far as I know there is no way to start service in the background since android O without showing anything to the user. You should start your service using startForegroundService(), then show notification, perform your 2 uploads and turn off the app (hidding notification too). If those uploads aren't huge, it will be pretty quick, and in most cases user won't even see the notification.
I have used GCM to get push notifications, now if I Force stop the app from the settings on the Android device, will it be able to get push notifications?
I have read many posts that say in this case an app cannot receive notifications.
Is there any possibility to get notifications?
Once you force-stop your app from Settings, your code will not run until something manually runs one of your components (ie the user manually launches an activity).
Therefore after force-stopping your app from Settings, you will not receive GCM messages.
If you want to get notifications you have to manually restart your app.
This is by design since Android 3.1.
Apps that are in the stopped state do not receive broadcast Intents.
Stopped state is:
when the app is initially installed (before the user runs something in
the app) or
after a Force Stop.
You can find more about this here: http://developer.android.com/about/versions/android-3.1.html#launchcontrols
I'm developing an android app which implements push notifications using parse.
I have a requirement that the app must 'still receive notifications if the app is not running', but what is 'not running' on android? from what I gather there are 3 ways in which an app can 'not run'.
using the back button when the app is running
going to applications->force quit
holding down the back button and clearing the app from the list of recent apps
using the home button.
I have a broadcast receiver registered through manifest that fires only if the app has been closed using methods 1. and 4.
Is that how it should work on android? or should my broadcast receiver trigger no matter how the app is closed?
It's the normal behavior, take a look at the doc here :
http://developer.android.com/about/versions/android-3.1.html
Section Launch controls on stopped applications
Or here :
http://www.javacodegeeks.com/2012/05/android-broadcast-receiver-change-in.html
The requirement is for an enterprise application. The application will be started on device boot. It will be running in the background and the user should not be able to disable or Stop the application. In Android a user can go to Settings->Application->Manage Application and stop my application. Is there any way to prevent this from happening?
No there is not. You can prevent Android from stopping the application by utilizing a Service and marking it as a foreground service, though this will require your application to display an icon in the status bar.
You can not make your application live forever, but it depends on what you really want to do. It's possible to receive a lot of events of the mobile and execute code even if your Activity/Service is not running. You can use BroadcastReceivers to look for interesting events and then start a service. I do it for an Enterprise Application that sends an event to a main server when the user has received/made a call.