disable home button in lollipop programmatically - android

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.

Related

Show views above lockscreen using window manager in Android O?

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

Start blocking dialogs in service

Block all dialogs of Android, it means no dialog will appear, either of app or Android systems, until my service is running. Is there a way to do it programmatically?
I don't think it's possible to just block all popups.
For me it makes sense that android doesn't allow that normally.
But you can try (if you really want:) )to make your app an Accessibility Service which will react on popup displayed and immediately close it. To close the popup you can find some Cancel button on it and perform click or performGlobalAction(GLOBAL_ACTION_BACK); (if its cancelable).
Check out some code here to find a popup: Android unable read window content on few devices using accessibility service (I don't know if that will work)
You can also review this to get some more inspiration on how to find a view and make clicks on any app with the Accessibility Service: Programmatically enabling/disabling accessibility settings on Android device
EDITED: Some more details
You will need to follow this standard tutorial to add the service to your app: https://developer.android.com/training/accessibility/service.html
First thing to note is that you should decide to use xml configuration and include android:canRetrieveWindowContent="true"like in the tutorial:
<accessibility-service
android:accessibilityEventTypes="typeViewClicked|typeViewFocused"
android:packageNames="com.example.android.myFirstApp, com.example.android.mySecondApp"
android:accessibilityFeedbackType="feedbackSpoken"
android:notificationTimeout="100"
android:settingsActivity="com.example.android.apis.accessibility.TestBackActivity"
android:canRetrieveWindowContent="true"
/>
and I think you will not need the line android:packageName
Then you need to experiment what should happen in the callback method - here is just my rough suggestion:
#Override
public void onAccessibilityEvent(AccessibilityEvent event) {
AccessibilityNodeInfo source = event.getSource();
if(event.getEventType()==AccessibilityEvent.TYPE_WINDOW_STATE_CHANGED)
if(isAlert(source)) //explore the view (maybe recursively) to find if there is an alert
performGlobalAction(GLOBAL_ACTION_BACK);
}
and the recursive method can be like
private boolean isAlert(AccessibilityNodeInfo view){
int count = view.getChildCount();
boolean result = false;
for(int i=0; i<count; i++){
AccessibilityNodeInfo child = view.getChild(i);
if(child.getClassName().contains("Alert")){
return true;
}
if (explore(child));
result = true;
child.recycle();
return result;
}

How to disable android' touchscreen device?

The App currently runs in IMMERSIVE_STICKY mode, but when user swipes from the side - OS shows menu and home/back buttons. So user can turn my app off or run some other stuff which is unacceptable. Therefore, I need to disable touchscreen device completely on android to prevent any taps and swipes.
If i cant disable it via official API, can i disable touchpad using console? Android will be rooted.
I found that my touchpad device is /sys/devices/virtual/input/input1 but still cant find where can I disable it. /power/control takes only 'on' or 'auto'.
I found other solution with xinput but on android there is no one.
I think you can override the function onTouchEvent.
private boolean touch_disabled=true;
#Override
public boolean onTouchEvent(MotionEvent e) {
if (touch_disabled){
return true;
}else {
//do something here if your touch screen is activated
}
}
public disable_touch(boolean b) {
touch_disabled=b; //function to activate or desactivate touch screen
}

Is there a way to programmatically control the back-light for the android back button?

I'm currently making an android app and testing it on a Samsung GT-S5830.
The problem I'm having is that the back button back-light is always off when the app is running (so it's not visible), which seems to confuse the users who I have asked to test the app.
The question is whether there is a way to programmatically ensure that the back-light for the back button is always on?
I'm dubious about it, as the problem seems to be phone model dependent.
Thanks.
there is already a stackoverflow answer but I will post again:
private void setDimButtons(boolean dimButtons) {
Window window = getWindow();
LayoutParams layoutParams = window.getAttributes();
float val = dimButtons ? 0 : -1;
try {
Field buttonBrightness = layoutParams.getClass().getField(
"buttonBrightness");
buttonBrightness.set(layoutParams, val);
} catch (Exception e) {
e.printStackTrace();
}
window.setAttributes(layoutParams);
}
Or try to find something in here (the new design is horrible ...) http://developer.android.com/reference/android/os/PowerManager.html

How to Force Android Soft Keyboard Open from Native Code?

I have a game that uses a callback to Java from C++ to force open the soft keyboard when the user touches the screen. The Java code is simply this:
this._inputMethodManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
This has worked fine for a while but recently we've been receiving complaints from some Motorola Droid users that the soft keyboard fails to open for them. Since we've only recently started to get these complaints and it's a number of users I'm thinking it was some kind of update to those devices.
Is there a better way I can force the keyboard to open? All the links I find online talk about using textbox controls and such but my app is primarily C++ and doesn't use the standard controls at all.
I don't know if this is related to your problem, but I was running into some issues using only InputMethodManager.toggleSoftInput() when devices would sometimes get "out of sync" and hide when I wanted to show and vice versa.
I've had some success by taking advantage of the fact that while IMM.showSoftInput() won't show a keyboard, IMM.hideSoftInputFromWindow() will reliably close one, so when I want to show a keyboard I now call IMM.hideSoftInputFromWindow() followed by IMM.toggleSoftInput(), and use IMM.hideSoftInputFromWindow() by itself to hide one.
[A day later...]
Writing the above yesterday made me rethink how I was dealing with the soft keyboard (I mean, showSoftinput() does work, just not the way we expected it to) and so here is a better way to do it:
First, you need to set up your view so that Android knows it can have a soft keyboard - described in the docs for InputMethodManager. In my case I have a single view derived from GLSurfaceView and so I added:
setFocusable(true);
setFocusableInTouchMode(true);
to the constructor and then the following 2 overrides:
#Override
public InputConnection onCreateInputConnection(EditorInfo outAttrs)
{
outAttrs.actionLabel = "";
outAttrs.hintText = "";
outAttrs.initialCapsMode = 0;
outAttrs.initialSelEnd = outAttrs.initialSelStart = -1;
outAttrs.label = "";
outAttrs.imeOptions = EditorInfo.IME_ACTION_DONE | EditorInfo.IME_FLAG_NO_EXTRACT_UI;
outAttrs.inputType = InputType.TYPE_NULL;
return new BaseInputConnection(this, false);
}
#Override
public boolean onCheckIsTextEditor ()
{
return true;
}
Now I can show the keyboard with:
InputMethodManager mgr = (InputMethodManager)mActivity.getSystemService(Context.INPUT_METHOD_SERVICE);
mgr.showSoftInput(mView, 0);
and the keypresses get reported via the view's onKeyUp() and onKeyDown() methods.
Hiding it is still done using hideSoftInputFromWindow()

Categories

Resources