Does Activity Recognition Transition API work on Wear OS? - android

I thought the Activity Recognition Transition API didn't work on Wear OS.
Does Wear OS support the Activity Recognition Transition API?
I checked whether the Activity Recognition Transition API works on Wear OS devices by referring to this site:
https://developer.android.com/guide/topics/location/transitions
"task.addOnSuccessListener" handles success, but unfortunately ActivityTransitionResult never fires the event.

Related

How to check if an Android app started by a service in a separate Android app has finished loading?

I am using the code below to start an installed camera app (not developed by me) from a background service in an app I'm working on.
Intent launchIntent = getPackageManager().getLaunchIntentForPackage("com.sec.android.app.camera");
startActivity( launchIntent );
I need to determine if the camera app is done loading and ready to use so I can prompt the camera to take a picture. After the picture is taken, my app will be brought back to the foreground and show a screensaver until the camera is started again or brought back to the foreground to take another picture. Is there a way to verify that the camera app is loaded and ready each time before attempting to send it commands?
For clarity, I'm not asking about how to check this on a camera app specifically. I'm trying to learn how I can start just about any app (not developed by me) and listen for it to be completely loaded and ready.
I am using the code below to start an installed camera app (not developed by me) from a background service
Launching activities from the background is not supported on modern versions of Android.
Also note that many devices will not have that particular package.
I need to determine if the camera app is done loading and ready to use so I can prompt the camera to take a picture
There is no canonical definition of "done loading and ready to use". And, in general, there is no means for you to monitor the operations of another app, for privacy and security reasons.
Also, outside of accessibility services, in general, you have no means of telling a running app to do anything unless it has a specific API for that purpose. Even with accessibility services, I suspect that it will be difficult to come up with an approach that works no matter what the camera app is.
If, from the foreground, you want a camera app to take a picture, use ACTION_IMAGE_CAPTURE. Or, integrate camera functionality directly in your own app, such as via CameraX or other libraries.

Android webRTC call in a Foreground Service

I am creating an Android app (Java code) that has an audio call feature.
I managed to make it work using the webRTC framework.
I wanted to make my audio call behave like WhatsApp and Messenger, where those apps keep the audio call running even if the user stops the app from apps history, or starts using another app.
So, I decided to migrate the webRTC code from an Activity to a Foreground Service.
My Audio Call Activity handles the UI, displaying friend photo, name, call timer ...
So I had to make communication between my Activity and my Foreground Service through binding and sending android.os.Message object.
Everything works fine when using SAMSUNG devices, if I kill the app, I could return to the Call activity by clicking the foreground service's notification, and the audio call keeps working until I hang up.
My problem appeared when i used a Xiaomi device (redmi note7), if i kill the app, the audio call stops, cause my Foreground Service is restarted.
Even after enabling "Autostart" from settings.
I searched in here for a solution but all the answers i found didn't satisfy my need, cause i can't just accept my Service being restarted.
If i want to resume the audio call, i have to re-call the friend again !
So, the question is :
How to prevent Xiaomi, Huawei, Oppo ... devices from restarting Foreground Service ?
Which is the case with WhatsAPP, Messenger, Instagram and others.
It's a tricky question since it really depends on the vendor. There is a site which document and rank the vendor according to "how bad" they're handling services and processes. From the site:
...With Android 6 (Marshmallow), Google has introduced Doze mode to the base Android, in an attempt to unify battery saving across the various Android phones. Unfortunately, vendors (e.g. Xiaomi, Huawei, OnePlus or even Samsung..) did not seem to catch that ball and they all have their own battery savers, usually very poorly written, saving battery only superficially with side effects.
The solutions differs from vendor to vendor and from ROM version to another.
For example for Huawei you can overcome the issue in Huawei P20, Huawei P20 Lite, Huawei Mate 10 by Phone settings > Battery > App launch and then set your app to “Manage manually” and make sure everything is turned on. Also for reliable background processes you may need to uninstall PowerGenie (which is a power mgmt. application by Huawei). On the other hand for EMUI 9+ devices you'll have to uninstall PowerGenie via adb

How to know that app has been paused in Android Q?

Is there any callback that the app has been paused in Android Q?
I'd like to do some actions with the app in such a case, but I can't find any descriptions of it.
"Pause app" is a new feature of Android Q:
https://9to5google.com/2019/05/21/digital-wellbeing-pixel-launch-pause-app/
It's not onPause() lifecycle method.
For other users downvoting his question - this is about a feature in Google's Digital Wellbeing program which has been pushed to Pixel phones - not about the activity lifecycle
For OP - I don't think you will get a satisfactory answer to this yet. I have looked through the Android Q Beta documentation and they are not offering links to anything specific. However for developers in the future, I think the term to search for is "distraction state" as mentioned in their docs:
Per-app distraction state -- Android Q can now selectively set apps to a "distraction state" where their notifications are suppressed and they will not appear as suggested apps.
For now the only thing I can suggest is to not target android Q in gradle. So today the correct answer is this information / api has not been made public yet
As currently there's no official documentation for this issue, I'm posting this as an answer with hope there will be the official solution.
You can register a BroadcastReceiver with intent filter Intent.ACTION_PACKAGES_SUSPENDED. It will be triggered once you put the app to this mode.
But I'm not sure it won't have side effects or will work stable on all devices. I tried it on Pixel 2.
Currently at the time of this post. There is no documentation regarding Android Q Pause App feature in relation to Android Activity Lifecycle and how to apps can track this action. But based on my understanding of how Pause App feature works from the post i read here is that, all notifications from the app are disabled and also selection of the app from the launcher is also disabled.
App paused using Pause App feature can still be running but can
neither be resumed/launched nor send new notifications.
Here is my take on what i think the paused app can do to verify that it is paused when targeting android Q. Though not efficient enough.
App starts a notification during launch using startForeground so it won't be dismissed by the user. Showing something like MyApp is running.
App uses a running foreground service which regularly checks the state of the notification every nth minutes.
If the service is still running and the foreground notification is closed or cannot be found by the service then logically we can say that the app is in a paused state.

How to hide the popup of Androids Voice Recognition, without using RecognitionListener

After the latest 2 updates of the Google App, voice recognition experience in my app has worsened dramatically, because the microphone takes more than 5 seconds to stop recording after the user has stopped speaking.
This bug has been reported to Google, and they only fixed it partially in the last update (If I uninstall Google App updates and rollback my phone to the older Google app shipped with the phone everything works fine).
I am using the RecognitionListener approach.
This problem does not occur when I launch a RecognizerIntent voice recognition popup like this:
startActivityForResult(speechIntent, SPEECHRECON_CODE);
How can I hide that Voice Recognition dialog popup??

Speech Recognition Service in Android

I have an Android application that uses speech recognition in an Activity. The GUI doesn't do anything except for contain the speech recognition objects. I would like to port this over to a service so I can talk to the application while it's running in the background.
However, as far as I know, the speech recognition service has to use onActivityResult, which is unavailable for Services. Is there a way to either contain an Activity in a Service such that its GUI is not displayed, or perform speech recognition in a service instead of an activity?
See Google's voice search speech recognition service - it might have some useful links to information. I don't think you can do non-Gui voice recognition because the recognizer is only exposed as the recognizer intent.
I don't think that Google wants people to call this service directly, and it likely violates some terms of service somewhere if you do, but check out http://mikepultz.com/2011/03/accessing-google-speech-api-chrome-11/ to see the service behind Chrome speech recognition which I suspect is similar to Android.
what if you have your service wake up an activity when it detects any incoming audio signal,
that acts like a widget only taking up a small part of the screen or even just a single pixel, then call voice recognition from the invisible activity?
Just an idea, I don't remember if a widget can be an activity or if you can make an activity that doesn't take up the screen.

Categories

Resources