Android Q background restrictions - android

I need to show an activity on push received, but I am getting Background activity start from package-name blocked. system Toast.
This is an authentication activity where user needs to perform some task. I do not manage phone or NFC interaction thus I don't need to actually start 'special' service but showing notification is not enough - I need that activity.
SYSTEM_ALERT_WINDOW permission doesn't help.
So, should I re-implement all my flows to work only with notifications? Is there any possibility to start activity when application was closed (No activity in back stack)?

Android Q places restrictions on when apps can start activities. This behavior change helps minimize interruptions for the user and keeps the user more in control of what's shown on their screen.You can see the full document here
As of Android Q Beta 4, this change has the following properties:
Affects your app if you launch activities without user interaction
Mitigate by using notification-triggered activities
Disable restrictions by turning on the Allow background activity starts developer option

Related

Is there a way to force app relaunch after it was killed by the Android OS?

Simple put: I want the app to relaunch (yes, from the launch activity, like if the user just tapped the icon button) every time Android kills my task because of lacking resources reasons.
The reason is that instead of managing everything that could possible go wrong after the app came back "from the dead", like NPEs, I want to start all over from the beginning.
I've searched for a "good practice" solution, but nothing came across.
Any ideas?
EDIT: I don't want to force the app back to foreground. However, if the user do it, I mean he brings it back to fore by his own free will, if Android killed my app because of resources purposes, I want the app to relaunch.
Sorry for not being clear previously.
Bringing your app to the foreground when it hasn't been explicitly opened by the user is considered a bad practice and discouraged. In fact, it won't be allowed in Android Q, except in a few cases:
Android Q places restrictions on when apps can start activities. This
behavior change helps minimize interruptions for the user and keeps
the user more in control of what's shown on their screen. In
particular, apps running on Android Q can start activities only when
one or more of the following conditions are met:
The app has a visible window, such as an activity in the foreground.
A different app that's in the foreground sends a PendingIntent belonging to the app. Examples include a Custom Tabs provider sending
a menu item pending intent.
The system sends a PendingIntent that belongs to the app, such as tapping on a notification. Only pending intents where the app is
expected to launch a UI are exempt.
The system sends a broadcast, such as SECRET_CODE_ACTION, to the app. Only specific broadcasts where the app is expected the launch a
UI are exempt.
Therefore, I would definitely recommend you to discard the idea.

Launch android app after start and block other apps

I'm facing the following problem. I want to make an android device to run only my application. All other apps and phone feautes should not be available to a user.
The reason why I want to achieve this is simple: I want to destribute devices with preinstalled application to my client but I don't want to let them use all phone featues.
This could work this way: just after android boots my application is launched automatically and than somehow all other staff is blocked.
Do you have any suggestions how to achieve that? Is it possible? Do I need to root a device?
I hope you get my problem. Any advice you can give will be greatly appreciated.
This is a bit crude way. But see if it is of any help.
If you create your application as a launcher it will start on boot(using system broadcast BOOT_COMPLETED).
Then you need to override all the three android buttons Home, back and recent apps.
To override back button you just have to override the onBackPressed() method.
For home button you will start a service which will run in background. This service will check if your app is in foreground or not. if not then it will bring it in foreground. so when the user presses home the service will sense the foreground app isnt yours and launch it.
But for this switching back of your app android takes approx 3 to 5sec. In that period of time you can display a warning text which will block the user from stopping the service from settings.Also if you remove the activity animations then it will appear seamless.
For recent apps button the above trick will do. If the user tries to close the app using this button your background service will sense it and launch your app.
so its the background service that does all the trick. if you some how stop the service or uninstall the app you are through :p

Launch application without an interface to receive boot_completed

I have developed a Service for Android that starts when BOOT_COMPLETED is received.It works fine on versions prior to 3.1.
I newer versions tough I understand the application must be launched in order to receive this broadcast . How can I launch my application if I don't have an User Interface ?
You add a user interface, in the form of an activity that the user can launch. Besides, this is where you need to:
Allow the user to stop and start your service, since the user may not want your service to be running 24x7 and you do not want the user to have to resort to Force Close
Display your documentation
Display your license agreement

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.

Start application when Content provider is changed

I want my application to start when someone modifies a content provider. A setting to be specific. The settings framework calls "notify" when a value is set.
If my app was started I would use registerContentObserver() I guess, but is is not started.
Can define some intent-filter in my manifest that wakes up my application. A back up plan would be to have a service running all the time that has registered a listener, but that seems like a wast or resources.
Thanks, Ola
This isn't directly supported by the Android device because starting an app every time a ContentProvider's data changes is a path to really killing your battery. To do the query, you'd need to do it in a service, which as you said is understandably undesirable.
Secondly, starting an intent is a user action. Android really doesn't support allowing an application to start all on its own without user request... Doing so would be impolite! What if your user was doing something important and then your app pops up on top? Remember the user is in control, not you. Instead of starting an application, consider placing a Status Bar Notification so the user can deal with it when it's convenient for them.

Categories

Resources