I cannot find a way to disable quick settings tile in Android programmatically that is a requirement for our enterprise launcher.
Are there any clues beyond the How to disable the notification bar pull-down in Android? and https://e2e.ti.com/support/embedded/android/f/509/t/283260
Is it possible to do? Thanks!
May you start your app in the full screen mode?
like explained here: https://stackoverflow.com/a/8470893/2801860
<activity
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
....
>
Yes you can do it. I had used the following snippet to disable quick settings.
public static void preventStatusBarExpansion(Context context) {
WindowManager manager = ((WindowManager) context.getApplicationContext()
.getSystemService(Context.WINDOW_SERVICE));
Activity activity = (Activity)context;
WindowManager.LayoutParams localLayoutParams = new WindowManager.LayoutParams();
localLayoutParams.type = WindowManager.LayoutParams.TYPE_SYSTEM_ERROR;
localLayoutParams.gravity = Gravity.TOP;
localLayoutParams.flags = WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE|
// this is to enable the notification to recieve touch events
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL |
// Draws over status bar
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN;
localLayoutParams.width = WindowManager.LayoutParams.MATCH_PARENT;
int resId = activity.getResources().getIdentifier("status_bar_height", "dimen", "android");
int result = 0;
if (resId > 0) {
result = activity.getResources().getDimensionPixelSize(resId);
}
localLayoutParams.height = result;
localLayoutParams.format = PixelFormat.TRANSPARENT;
customViewGroup view = new customViewGroup(context);
manager.addView(view, localLayoutParams);
}
Call this method where ever you need. Before calling this method make sure you has screen overlay permission.
However this permission is deprecated in Oreo.
It seems is impossible to do at all.
That is the answer.
No, not impossible. Use ACTION_CLOSE_SYSTEM_DIALOGS to prevent it be pulled down when the screen is locked.
Related
I am making an application,and have access to system permissions.
I want to make the navigation bar hide permanently,
It should not appear even on user interaction.
Now i'm using this piece of code,
it hides the bar but when user touches the screen it showing again. is there any way to hide it permanently until activity onStop();
protected void hideBottomUIMenu() {
if (Build.VERSION.SDK_INT > 11 && Build.VERSION.SDK_INT < 19) { // lower api
View v = this.getWindow().getDecorView();
v.setSystemUiVisibility(View.GONE);
} else if (Build.VERSION.SDK_INT >= 19) {
Window _window = getWindow();
WindowManager.LayoutParams params = _window.getAttributes();
params.systemUiVisibility = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION|View.SYSTEM_UI_FLAG_IMMERSIVE;
_window.setAttributes(params);
}
}
Any technical advice or comments/suggestions on the best implementation would be hugely appreciated.
I hope this might be helpful for you. Also look at this
I'm trying to create an overlay window using the next code:
int OVERLAY_TYPE;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
OVERLAY_TYPE = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
} else {
OVERLAY_TYPE = WindowManager.LayoutParams.TYPE_PHONE;
}
WindowManager windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
ImageView popupView = new ImageView(this);
popupView.setImageResource(R.drawable.bottom_dialog_background);
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT,
OVERLAY_TYPE,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
PixelFormat.TRANSLUCENT);
params.gravity = Gravity.BOTTOM;
windowManager.addView(popupView, params);
I've added <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" /> to Manifest and allowed all needed permissions for that.
It works fine for Android versions up to Android Q. But Q and R versions don't work at the same way. Overlay window creates, persists through some activities and other apps. It even persists through Android Settings but when I try to open something deeper than just Android Settings, for example Usage Data Access screen or App Data screen, the Overlay Window disappears. If I press Back button it will show the previous Activity and Overlay Window will be shown again.
Does anyone know how to "fix" it and achieve the same behavior for all Android versions?
Any help would be highly appreciated. Thanks in advance.
I am checking the internet connection in my application, when the internet is not accessible I want to display a small popup message to the user that you're offline.
I tried to solve the issue by using AlertDialog and AlertDialog.Builder, and I have also searched through different solution on the internet but no solution resolve my issue. I am trying to do this by the following method.
AlertDialog.Builder builder = new AlertDialog.Builder(context);
LayoutInflater inflater = LayoutInflater.from(context);
View alertdialog = inflater.inflate(R.layout.nointernetdialogue, null);
builder.setView(alertdialog);
AlertDialog dialog = builder.create();
dialog.getWindow().setType(WindowManager.LayoutParams.TYPE_TOAST);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
WindowManager.LayoutParams alertTop = dialog.getWindow().getAttributes();
alertTop.gravity = Gravity.TOP | Gravity.START;
alertTop.x = 100;
alertTop.y = 100;
dialog.show();
The result I want.
Create BaseActivity which shall implement Broadcast Receiver regarding network connectivity checks. Whenever network connectivity goes off, show the SnackBar/Alert.
Let all your other activities extend this Base activity.
Alert dialog looks like a over kill just have a TextView and show and hide it on network change.
Try with this example Click here
here i am using BroadcastReceiver to find the Wifi and Mobile data status
By this you can access the Network state anywhere un the App
You should create a BaseActivity that checks internet connection and shows alert dialog if needed. All activities that you want to show alert dialog should extended from BaseActivity.
You can work with top SnackBar , there is the code
Snackbar snack = Snackbar.make(findViewById(android.R.id.content), "Online", Snackbar.LENGTH_LONG);
View view = snack.getView();
FrameLayout.LayoutParams params =(FrameLayout.LayoutParams)view.getLayoutParams(); params.gravity = Gravity.TOP;
view.setLayoutParams(params);
snack.show();
I am trying to implement an AlertWindow kind of thing where I am using the instance of WindowsManager to add a View on it from a Service. The View is visible and accessible. But the back/home buttons on the on-screen NavigationBar don't seem to respond. I am new to Android.
Here is a snippet of my code:
mLayout = new LinearLayout(this);
mLayout.setLayoutParams(new WindowManager.LayoutParams(WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.MATCH_PARENT));
View view = LayoutInflater.from(this).inflate(R.layout.Mainactivity,
mLayout, true);
mTvErrorMsg = (TextView)view.findViewById(R.id.tv_error_msg);
mChkBoxAppState = (CheckBox)view.findViewById(R.id.chkbox_app_state);
mCancelBtn = (Button)view.findViewById(R.id.btn_action);
mEdtPin.addTextChangedListener(this);
try {
mWindowManager.addView(mLayout, wmlp);
} catch (RuntimeException e) {
SymLog.e(TAG, "Failed to add lock page.", e);
}
Adding the below LayoutParameters solved my issue:
wmlp.flags = WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH;
wmlp.flags &= ~(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON | WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE);
wmlp.type = WindowManager.LayoutParams.TYPE_SYSTEM_ALERT | WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY;
wmlp.format = -1;
wmlp.token = null;
wmlp.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE | WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE;
Are you sure you are defining the layoutparams right?
new WindowManager.LayoutParams(WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.MATCH_PARENT)
This implies the the LinearLayout that you have will take up the parents full width/height. Perhaps change the view to WRAP_CONTENT so it will only take up as much as needed.
Likely this will require more work as it depends WHAT exactly you are trying show.
I want to add a line above the action bar like in the "pocket"-app. How can i do this?
Here is a picture for example:
Thanks
tomtom
Taking advantage of an Activity's WindowManager, we can draw any view we want on top. Here's some (half-pseudo) code that should help:
// Create an instance of some View that does the actual drawing of the line
View customView = new CustomView(<some context>);
// Figure out the window we have to work with
Rect rect = new Rect();
getWindow().getDecorView().getWindowVisibleDisplayFrame(rect);
// Make sure the view is measured before doing this
int requestedHeight = customView.getLayoutParams().height;
// setup the params of the new view we'll attach
WindowManager.LayoutParams wlp = new WindowManager.LayoutParams(
rect.width(), requestedHeight,
WindowManager.LayoutParams.TYPE_APPLICATION_PANEL,
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE |
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN,
PixelFormat.TRANSLUCENT);
// set the parameters so we fit on the top left of the window
wlp.x = 0;
wlp.y = rect.top;
wlp.gravity = Gravity.TOP;
// finally add it to the screen
getWindowManager().addView(header, wlp);
The only thing to be careful is that you can't run that code from onCreate() or any lifecycle method of the Activity because the Window won't have been created yet (You'll get a BadTokenException). One way might be post a Runnable on the Window's DecorView so that your code to add the CustomView runs after the Window is created:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//...
getWindow().getDecorView().post(<Runnable that execs code above>);
}
As for the actual CustomView that will display that multi-coloured bar, I feel like that's a good exercise :-)
All you'd need to do is have the onDraw() method use canvas.drawRect() with specific x and widths.
Hope that helps.
What Pocket does
As for how Pocket actually does it. If you use HierarchyViewer on the Pocket app, you'll be able to determine that Pocket uses a custom class for their ActionBar. Since they already rebuild all the features of the ActionBar for their needs, in their case, adding the line is like adding a regular View to some ViewGroup.