My app shows views above the lockscreen, until now I used the following code:
windowParams = new WindowManager.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.TYPE_SYSTEM_ALERT, 65794, -2);
windowParams.type = Utils.isSamsung(getApplicationContext()) ? WindowManager.LayoutParams.TYPE_TOAST : WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
windowManager.addView(frameLayout, windowParams);
This code doesn't seem to work anymore on Android O, instead, now the lockscreen is shown above the view, and the view only becomes visible after the user swipes away the lockscreen.
Granted, it could just be a bug since Android O is still in beta, but it's also possible that I missed one of Googles notes about "what's new in O".
It's no longer possible to draw over the lockscreen and other important UI elements (status bar, etc), Google removed this feature in Android O.
Source:
https://issuetracker.google.com/issues/36574245
Related
my application helps testers to find inconsistencies in layouts and makes it easier to work with the UI part using the grid layout overlay. but since android 12 (31 sdk) all clicks are suppressed by the system because they are "untrusted touch"
have any ideas?
P.S. in the article on medium it is suggested to use one of the approaches: Bubbles, Picture-in-Picture, Notifications, but this is not suitable for the gridlayout approach
link to untrusted touch android doc
Code example:
private fun showGrid() {
val overlayFlag = if (Build.VERSION.SDK_INT >= 26)
WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY
else WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY
params = WindowManager.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT,
overlayFlag,
WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE or
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
PixelFormat.TRANSLUCENT
)
windowManager = getSystemService(Context.WINDOW_SERVICE) as WindowManager
gridOverlay = GridOverlay(this, prefHelper.gridColor, prefHelper.gridSize)
gridOverlay?.alpha = prefHelper.gridAlpha
windowManager!!.addView(gridOverlay, params)
}
InputManager , maximumObscuringOpacityForTouch didn't solve the problem
other flags in the WindowManager also did not help.
what can be done according to the android documentation is using the Accessibility service, but this is not our approach as I don't want to be banned by Google because of using Accessibility service not for its intended purpose.
I want to disable home and power buttons automatically after opening my application and enable them after hitting exit button in the application.
I have achieved this by making my application as the launcher application and it works until Jellybean (tested upto 4.1.2).
But the same app doesn't work around in KitKat and Lollipop versions.
I figured that to use kiosk technique to disable home button in Lollipop.
Refer to https://sdgsystems.com/blog/implementing-kiosk-mode-android-part-3-android-lollipop,
it requires a device owner application and few steps to make it achieve.
Though my application is to automatically block the home button function, it doesn't work around.
My questions are:
Is there any process to disable home button in lollipop?
How to achieve it programmatically?
If kiosk is the technique, then how to make it suitable for my requirement? (Looking for a guide through)
First sorry for late answer. first thing is programmer really not blocking home button. They are use only trick to hide home button process behind the lock screen.
How can you do this.? simple. Just use your lock screen window as window manager screen that's why after pressing home your mobile screen will not minimize. This is little trick used in most success lock application.
and one more thing is how to overlap phone window top system status bar.
For this You can use code just like this and can modify as you want.
manager = ((WindowManager) getApplicationContext().getSystemService(Context.WINDOW_SERVICE));
localLayoutParams = new WindowManager.LayoutParams();
localLayoutParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
localLayoutParams.gravity = Gravity.TOP;
localLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
//WindowManager.LayoutParams.FLAG_LAYOUT_ATTACHED_IN_DECOR |
WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN |
// this is to enable the notification to recieve touch events
//WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN |
WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH |
// Draws over status bar
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
//localLayoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
localLayoutParams.height = (int) (50 * getResources().getDisplayMetrics().scaledDensity);
localLayoutParams.format = PixelFormat.TRANSPARENT;
view = new customViewGroup(this);
manager.addView(view, localLayoutParams);
and create customeVIewGroup class like this..
public class customViewGroup extends ViewGroup {
public customViewGroup(Context context) {
super(context);
}
#Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
}
#Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
Log.v("customViewGroup", "**********Intercepted");
return true;
}
}
Here is the flow I suggest. Create a device owner app and take device ownership either through NFC bump or through adb. Add your package name to setLockTaskPackage() in the device owner app.
Now, in the app that you want to lock the device to, call startLockTask() method and your device will be locked to this specific application until you call the stopLockTask().
You can find the api information here.
On how to create a device owner app and guide you can refer to website of Florent Dupont.
can I show coming notification always on top of all other notification . in new version lollipop it is default...but what to do for others previous versions .i am using Samsung note 2 device.
In order to put it there you have to add a flag to the LayoutParams
of your WindowManager and after that add the NotificationView.
WindowManager.LayoutParams lp = new WindowManager.LayoutParams(
WindowManager.LayoutParams.TYPE_SYSTEM_ERROR);
mWindowManager.addView(mHeadsUpNotificationView, lp);
I'm creating an app shows HTML5 video, for studying android programming, that uses Floating WebView.
It performs very choppy even on device that has upgraded WebView.
(I'm using lollipop-powered Nexus 5)
While it is attached on Activity(not floating) it performs buttery smooth.
Even if it is floating, it performs smoothly when any WebView is placed on Current Activity.
But if there's no WebViews on current activity like launcher, it performs very slow and jittery.
Here is part of code what I'm using:
WindowManager windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
WebView = new WebView();
WindowManager.LayoutParams paramsRL = new WindowManager.LayoutParams(
800,
450,
WindowManager.LayoutParams.TYPE_PHONE,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,
PixelFormat.TRANSLUCENT);
paramsRL.gravity = Gravity.TOP | Gravity.LEFT;
webView.setWebChromeClient(new WebChromeClient());
webView.getSettings().setJavaScriptEnabled(true);
webView.getSettings().setCacheMode(WebSettings.LOAD_NO_CACHE);
webView.loadUrl("html5_video_page_URL_here");
windowManager.addView(webView,paramsRL);
Is there any workaround to get around this problem?
EDIT
Added a video explains this behavior: http://youtu.be/BPDxzRRO1N8
while attached to an activity, it performs buttery smooth: http://youtu.be/aQcJRPCZWYs
on Kitkat, at least Samsung Galaxy's, it behaves buttery smooth: http://youtu.be/7Dw0tJ67eJw
I've also filed a bug at
https://code.google.com/p/chromium/issues/detail?id=460440
You can add
webView.setLayerType(WebView.LAYER_TYPE_HARDWARE, null);
Hope help you
I've been working on a application with a floating video player and I had the same issue. I didn't find the root cause of the problem but I got rid of this issue.
I have an activity that starts the Floating Video Player (basically a service that uses the TYPE_SYSTEM_ALERT type), when I added a notification player started by the Activity as well (similar to the one used by Spotify), the issue disappeared.
As I said I wasn't able to determine the root cause of the issue, but it seems that as long as the activity or something started by the activity is "active" (I'm using the term active loosely), the issue will no happen and the Webview will behave as expected.
Android added Presentation in API Level 17 (Android 4.2) to support displaying content on an external Display, such as as TV or monitor connected via HDMI, MHL, Miracast, or SlimPort. However, Presentation extends Dialog, and so it is only usable from an Activity.
And, as far as I knew, that was the end of the story.
However, this StackOverflow answer hints at a possible way to use an external Display from a Service, by means of createDisplayContext() and WindowManager created from that Context. Then, the addView() method on that WindowManager should render the View onto the indicated Display. If this can be made to work, it really opens the door for interesting uses of external displays, such as playing a video on a TV while being able to use unrelated apps (e.g., a Web browser) on the device's own touchscreen.
However, that answer glosses over a key detail: how to set up the WindowManager.LayoutParams for the addView() call. In particular, there are a dizzying array of possible TYPE_ values for the type field. I have crashed in two attempts, though with different messages:
TYPE_APPLICATION results in android.view.WindowManager$BadTokenException: Unable to add window -- token null is not for an application
TYPE_APPLICATION_MEDIA results in android.view.WindowManager$BadTokenException: Unable to add window -- token null is not valid; is your activity running?
For example, here is my WindowManager.LayoutParams for the second scenario above:
WindowManager.LayoutParams p=
new WindowManager.LayoutParams(
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.MATCH_PARENT,
0,
0,
WindowManager.LayoutParams.TYPE_APPLICATION_MEDIA,
0, PixelFormat.OPAQUE);
Reading through the docs for type suggest that none of the TYPE_APPLICATION will be correct, as I do not have a token. Moreover, the point behind this exercise is to not have a token, as least as far as I can tell, as the Service is supposed to run independently from any UI.
If you look at the source to Presentation, it defers the WindowManager work to Dialog, which uses com.android.internal.policy.PolicyManager, which quickly dead-ends in an IPolicy. An SDK app does not have access to PolicyManager, anyway.
Has anyone gotten the createDisplayContext() approach to work from a Service? If so, what did you use for the type (or, more generally, for the WindowManager.LayoutParams in general)? Bonus points for a solution that does not involve some icky permission. :-)
Thanks!
TYPE_SYSTEM_ALERT type used conjunctly with the SYSTEM_ALERT_WINDOW permission should work.
It makes sense that launching a dialog from a service
requires "icky" permissions, it basically allows you to draw over other apps :)