I have implemented a call recognition app which displays a View that contains the caller id. More specifically it is a Service with a WindowManager where I add the View. I also use the draw over other apps permission.
The problem is only in Android 8, in case that the user enables the screen lock (Settings-> Security & Location -> Screen Lock).
In this senario if the device screen is off, and someone calls, my call recognition is not displayed. (The only thing I can see is the native call recognition app that is ringing)
My Service code runs correctly but the user cannot see the UI.
Do you have something in mind?
Thank you in advance
After several tries I found that the following parameter should be passed in the WindowManager.LayoutParams constructor.
flags -> WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
For earlier versions of Android although I didn't use this parameter it was ok.
Related
TL;DR How to make a phone call while using Activity.startLockTask()?
I'm trying to setup a restricted environment on an Android device, i.e. what is usually called "Kiosk-Mode".
Official documentation can be found here:
https://developer.android.com/work/cosu.html
The official way of doing this suggest to use Activity.startLockTask.
This works fine until you want to start other apps from within your Activity which is in startLockTask() mode.
Any activity that launches must not start on a new task stack otherwise the system blocks the launch intent, i.e. no Intent.FLAG_ACTIVITY_NEW_TASK.
Some apps can just be launched, other seem to implicitly set this flag, but can be workedaround by using startActivityForResult(...) which seems remove the NEW_TASK flag. For apps that still don't work I could code my own replacement.
The real issue is the call application, which enforces a new task stack. Triggering a call initiated the call, doesn't show the call activity, but also puts a call notification in the status bar (which is not accessible in while using startLockTask().
In contrast to other apps the call app is also one that can't be replaced with a custom app...
DevicePolicyManager.html.setLockTaskPackages() has no effect on this behavior.
I tried to make start call intent under locked mode and this line pop up:
system_process E/ActivityManager: Attempted Lock Task Mode violation mStartActivity=ActivityRecord{56ab302 u0 com.android.server.telecom/.components.UserCallActivity t155}
So I add
setLockTaskPackages(<ComponentName>,new String[]{getPackageName(),"com.google.android.dialer","com.android.server.telecom"});
Managed to get the dialler out. Of course if I push the home button or back button, there's no way to get the dialler back... the recent button is still locked though. Receiving call works perfectly (all buttons are disabled)
Have you tried this?
setLockTaskPackages(new ComponentName(this, DeviceAdminReceiver.class),new String[]{getPackageName(),"com.google.android.dialer"});
I'm developing an android app that blocks incoming phone calls while running.
but after a block sequence android's main keys(Back,Home,..) just changes to a dotted circle !
can any one please tell me what is this
and help me to get main buttons back?
by the way - i'm testing on : Sony C2305(Android 4.2.2)
This is what happens when your android phone is ringing(in default). since you changed default functionality of androids caller mechanism so its what really happen:
1- your phone rings and default caller turns on and hides android system keys in order to display caller screen
2- your application launches too and rejects call using code(and not androids caller application)
3- so as call rejected so androids default application closed with no response(without getting KEYs back!)
Thats it.
so i guess you should work with main caller istead of your own code to solve this problem.
Hope help you
I'm writing an application managing access to other applications. User can decide which app he would like to block on device, If someone start blocked app he see screen informing him about blockade. I have my own launcher and background process which check if currently open activity is blocked one. To check top activity I use package and class name from ActivityManager getRunningTasks(); If this app is blocked I cover it with my own View by adding it to WindowManager. This works for every app, except this which also use WindowManager like facebook chat heads or multitasking brought by LG - QSLIDE. This application isn't on top. Of course I can find her process using getRunningAppProcesses, but I cant kill it. Android.os.Process.killprocess don't work also. I know this is not a good idea but I don't have other one.
Is there a possibility to recognize that some app added something to WindowManager and eventually block it? Or just remove view or kill the app?
Facebook (and many other apps) draw to the Window with SYSTEM_ALERT to manage their little chat heads. As of writing this (6.0.1) there is no API to listen for views being added and/or gather any information about that view.
Is it possible for a 3rd party Android application on an device that is not rooted, to somehow make an outgoing phone-call, without launching the dialer ? What I mean is that my own Activity (displaying some information, image or video) keeps running in foreground, while the phone-call progresses in the background. Clearly, my Activity needs to be aware of call-state changes (i.e. when call is terminated). My own Activity (not the dialer), would have the "Call" / "Hang-up" buttons.
If possible, kindly share some pointers and hints as to how this could be done. If this is possible via the ITelephony (or other such) reflection based API, even if it is undocumented and hack-based method -- I would like to know about it.
So far in my research, I've come to know of only the method where you place the call directly to a number, without having to open up the Dialer first. However during the phone call, the Dialer application's Activity is open. I cannot show any other information on the foreground. Any alternative workaround, s.a. using Dialog overlay etc., might work as worst-case fallback, though I am not sure if there is anyway to show any "active" content (s.a. images that change, or video) in a Dialog.
Finally, can Fragments be a solution ? Can I show the DialerApplication activity in a Fragment ? I don't think so, but wonder if there's any hack possible for it ?
1) Is it possible for a 3rd party Android application on an device that
is not rooted, to somehow make an outgoing phone-call, without
launching the dialer ? What I mean is that my own Activity
(displaying some information, image or video) keeps running in
foreground, while the phone-call progresses in the background?
Ans.
It is not possible to keep our application foreground during phone call because the phone call is a system app and has highest priority.
2) Clearly, my Activity needs to be aware of call-state changes (i.e.
when call is terminated). My own Activity (not the dialer), would
have the "Call" / "Hang-up" buttons.
Ans.
Yes this is possible to get notify on call-state changes.
Look at here
I have a floating view created in service, and I need to dispatch key events when I touch this view.
I have found out that view.dispatchKeyEvent() needs context of foreground activity, and key event dispatching only works when activity is foreground.
When you close/pause the activity and touch the view - nothing happens, even no NPE in LogCat.
Is there any way to use this method outside of main activity?
This may be a bit too little too late but I found a solution. (Assuming the OP still wants to trigger OS back button from a floating view or service.)
It seems like it is possible to tell Android to press the back button, if you're a registered Accessibility Service. (Once your component is registered with Android, user must explicitly enable it in System Settings. So if this is simply a niche feature for your app rather than a critical function, it may be an overkill.)
Once you're done registering .etc. accordingly, your background service may tell the Accessibility Service to perform the back button, which can be done by calling
performGlobalAction( GLOBAL_ACTION_BACK )
from the Accessibility Service.
You do need API Level 16 or above for this to work.
I haven't got around to test this, but according to docs, this should work.
Tried and works on a number of recent devices. (Kitkat, Marshmellow and Nouget)
I found the app Back Button (No root) on play store which seem to employ this technique to draw soft buttons for back, home .etc. (which works on LG Nexus 5X and Samsung Galaxy Tab A 2016)
HTH
If I right understand (you did not post any source you have), you need to have floating view over all over apps receives key events, outside your app.
There is some projects shows this ability. (forum-thread androidFloatingImage-repo)
Try to use this floating views example to create each other, or use exactly the same. I think, using something i wrote above you can use callback on key event correctly. Hope it helps;