I'm creating a floating messaging function like the Messenger app.
I fixed keyboard not showing on a service by using FLAG_NOT_TOUCH_MODAL on my Layout params, but when the service starts, other apps like google,
search apps on phone, the keyboard is not working.
Here's the first picture - showing that the keyboard is showing: https://i.imgur.com/aTHUJm1.png.
Second picture - my service starts: https://imgur.com/C6PIGwk
Third picture - keyboard not showing anymore: https://imgur.com/hxJbEsX
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.TYPE_PHONE,
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL,
PixelFormat.TRANSLUCENT);
the above code is my code for showing the keyboard on my service. Using the FLAG_NOT_TOUCH_MODAL shows the keyboard on my service, I tried replacing FLAG_NOT_TOUCH_MODAL with FLAG_LOCAL_FOCUS_MODE but still the problem persists.
This is a very old question, but the first result for the issue
The issue is the overlay is still taking focus away from any editable views. Combine FLAG_NOT_TOUCH_MODAL with FLAG_NOT_FOCUSABLE to fix this
WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL ||
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
Related
I have challenged myself to code an in house app similar to Google's assistant voice tapping app. Everything is finished except the auto tap feature. When I launch the app it spins up a foreground service that draws a 8x8 grid that is always on top. Even when the main activity is minimized. The service uses an imageview that is set drawable. I then wrote an algorithm that draws a grid within it numbered 1 through 64. The user says which number to tap and the service does just that but nothing happens. I Log.wtf the tap coordinates x,y and it works perfectly when my main activity is open. when minimized it doesnt log the event OR its taping the wrong view.
Any suggestions?
Here is the code inside my custom window class that pops the window and sets the tap transperency so that taps pass through to the target app behind it. tPars is different for testing purposes. Both are window parameters.
`
mPars=new WindowManager.LayoutParams(
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY,
WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE,
PixelFormat.TRANSLUCENT);
lInflater=(LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
gridView = lInflater.inflate(R.layout.window_overlay,null);
iv = gridView.findViewById(R.id.iv);
ivHolder= gridView.findViewById(R.id.ivHolder);
((ImageView)iv).setImageDrawable(new Draw());
mPars.gravity=Gravity.CENTER;
mWManager=(WindowManager) context.getSystemService(WINDOW_SERVICE);
`
Ive even tried using System.exec("Touch X,Y"). Still same issue. Broadcast receivers wont work as the goal is to stay within the service WHILE using other apps. Its an auto tap assistant app like googles.
I would like to utilize this ---> MOTION EVENT
To reiterate, Once Main Activity spins up the service I no longer want or need it as the user will be using other apps. My app allows them to Tap/Scroll with their voice via the foreground service overlay.
Thanks in advance.
I tried MotionEvent, System.exec, and a few 3rd party APIs. It will only tap withing Main Activities view.
EDIT
Here is my tap and recognition code.
else if(sentence.get(0).equalsIgnoreCase("tap")){
mWManager.addView(gridView, mPars);
grid.draw(new Canvas());
tap(548F,946F);
}
and execution
private void tap(Float x, Float y) {
gridView.dispatchTouchEvent(MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis()+100, (int)MotionEvent.ACTION_DOWN, x, y, 0));
gridView.dispatchTouchEvent(MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis()+100, (int)MotionEvent.ACTION_UP, x, y, 0));
}
I'm adding a view to windows manager using these layout parameters:
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.MATCH_PARENT,
WindowManager.LayoutParams.TYPE_ACCESSIBILITY_OVERLAY,
WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE |
WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE |
WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM |
WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
PixelFormat.TRANSLUCENT
);
The expected result is an overlay window that covers the entire screen except the system ui (navigation bar and status bar) and doesn't cover the soft keyboard.
The above parameters do that but the problem is that the navigation bar buttons are not visible while the soft keyboard is open.
Current result:
Expected result:
I've tried a couple of flags like:
WindowManager.LayoutParams.FLAG_LAYOUT_ATTACHED_IN_DECOR
and a combination of:
WindowManager.LayoutParams.FLAG_LAYOUT_INSET_DECOR
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
But none of them worked.
I've also gone through the documentation for system ui but most option there that involve WindowManager.LayoutParams flags are for hiding the decoration and the rest of them require a reference to the window which I don't think I can get from an accessibility service.
The problem seems to be the:
WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM
flag, if I remove it, the navigation buttons are visible but the overlay will cover the keyboard, it will do that even if I use something like this:
params.softInputMode = WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE | WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE;
My question:
Is there any way to have an overlay that doesn't cover the keyboard and doesn't hide the navigation bar buttons ?
Did you try switching from PixelFormat.TRANSLUCENT to PixelFormat.TRANSPARENT? Also:
.apply {
gravity = Gravity.BOTTOM //CENTER or whatever
x = 0
y = 0
screenOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
}
I want to start creating long running applications. For instance, you choose some settings and then they are used while you browsing or playing a game. For example shortcut apps. You click somewhere in the corner, and something pop ups, with list of applications you want to go to.
My problem: I don't know how to create buttons, which would be on phone screen, like triggers, when you touch, something happens. I heard it's called overlays, but I couldn't manage to find tutorials about it.
Application example: Pie Control on Google Play. https://play.google.com/store/apps/details?id=jun.ace.piecontrol
Thanks for helping me out.
use system alert window .
example
View mView = new View(this);
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.TYPE_SYSTEM_OVERLAY,
WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH,
PixelFormat.TRANSLUCENT);
params.gravity = Gravity.RIGHT | Gravity.TOP;
WindowManager wm = (WindowManager) getSystemService(WINDOW_SERVICE);
wm.addView(mView, params);
i am building an android lib with AdMob to use on kony platform. The lib works great for a android phone or for tablets which are in portrait mode by default, but the Ad doesn't display on the galaxy Tab 10.1 (which is a in landscape by default).
i get this error :
Not enough space to show ad. Needs 1280x90 dp, but only has 800x1207 dp.
it seems that Admob get the size in landscape mode instead of the portrait size. (to be clear, portrait being 800x1207 and landscape 1280x800 when a write about it) and i am not sure where does the issue com from
my application is portrait mode only and i use this code to create my banner :
public View onCreateView(Context context) {
adView = new PublisherAdView(context);
adView.setAdUnitId(MY_AD_UNIT_ID);
adView.setAdSizes(AdSize.SMART_BANNER);
/*LayoutParams lparams = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
adView.setLayoutParams(lparams);*/
PublisherAdRequest.Builder publisherAdRequestBuilder = new PublisherAdRequest.Builder();
// Optionally populate the ad request builder.
publisherAdRequestBuilder.addTestDevice("XXXXXXX");
adView.loadAd(publisherAdRequestBuilder.build());
return adView;
}
onCreateView is call by the kony platform to display the Ad and I don't really know what's happen on this side. This code works fine for any android phone and tablet which are in portrait mode by default.
i can also display an Ad on the galaxy 10.1 if I change SMART_BANNER by Leaderboard but it's not centered on the Kony app and not as convenient as the smart banner.
I don't know android a lot and might have forgot to check something basic.
is there anything i could try to get the correct size before to investigate if it comes from Kony?
Thanks
Please check your layout for any padding. It just works if you remove any default padding.
Cheers!
I want to make an activity that can be opened above ANY app.
Normally, even when the activity is set as dialog, when you switch to my app, you see my app, and in the background you see the launcher:
BUT, I want the app will go above any app like this: (made in photoshop):
I did see this question Creating a system overlay window (always on top), but in ICS there is no functionallity to the layout.
Furthermore, I want to give a dialog box from my app without minimizing the other app...
there are plenty of apps that show a floating view on top of everything like : airbrowser , LilyPad , Stick it , AirTerm , Smart Taskbar , aircalc ...
anyway , in order to achieve this feature , you must have a special permission called "android.permission.SYSTEM_ALERT_WINDOW" , and use something like that:
final WindowManager.LayoutParams param=new WindowManager.LayoutParams();
param.flags=WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE;
final View view=findViewById(R.id.my_floating_view);
final ViewGroup parent=(ViewGroup)view.getParent();
if(parent!=null)
parent.removeView(view);
param.format=PixelFormat.RGBA_8888;
param.type=WindowManager.LayoutParams.TYPE_SYSTEM_ALERT;
param.gravity=Gravity.TOP|Gravity.LEFT;
param.width=parent!=null?LayoutParams.WRAP_CONTENT:view.getLayoutParams().width;
param.height=parent!=null?LayoutParams.WRAP_CONTENT:view.getLayoutParams().height;
final WindowManager wmgr=(WindowManager)getApplicationContext().getSystemService(Context.WINDOW_SERVICE);
wmgr.addView(view,param);
// TODO handle overlapping title bar and/or action bar
// TODO you must add logic to remove the view
// TODO you must use a special permission to use this method :android.permission.SYSTEM_ALERT_WINDOW
// TODO if you wish to let the view stay when leaving the app, make sure you have a foreground service running.
I'm one of the developers of the Tooleap SDK, and we also dealt with this issue.
Basically, you don't need to use the SYSTEM_ALERT_WINDOW to display an activity on top of another one. You can just display a regular "shrinked" Activity with a transparent background.
To make a "shrinked Activity, change the activity window layout params of height and width:
WindowManager.LayoutParams params = getWindow().getAttributes();
params.x = ...;
params.y = ...;
params.width = ...;
params.height = ...;
this.getWindow().setAttributes(params);
To make a transparent background add to your activity definition in the manifest file:
android:theme="#android:style/Theme.Translucent"
That way, you can create the illusion of a floating activity:
Note that only the foreground activity will be resumed, while the background one is paused. But for most apps this shouldn't be an issue.
Now all that remains is when to launch the floating activity.
Here is an example of a "floating" calculator app using a regular activity. Note that the activity below the calculator belongs to another app.