I've got an Android device with 2 independent touchscreen displays. On my second screen, I want to display a WebView that is able to load a full-screen webpage in a WebView and interact with it. I am successful with this. However, the problem I'm having is that the keyboard only seems to open on the default display.
I've tried reading https://source.android.com/docs/core/display/multi_display/ime-support and https://source.android.com/docs/core/display/multi_display/input-routing but I don't really understand what to do. The classes mentioned there don't seem to exist (Android Studio returns an error and I'm wondering if they're not meant for me?) My device is running API 30, so should be Android 11 and have these classes.
I've been able to launch the second screen by using:
DisplayManager dm = (DisplayManager) getSystemService(Context.DISPLAY_SERVICE);
Display[] displays = dm.getDisplays();
SecondaryScreen ss = new SecondaryScreen(injectedContext, displays[1], new OnTaskCompleteListener() {
@Override
public void onTaskComplete(Object result, int customTag) {
//nothing for now
}
});
ss.show();
and my second screen class looks like:
public class SecondaryScreen extends Presentation {
private WebViewActivity webView;
public SecondaryScreen(Context context, Display display, OnTaskCompleteListener taskCompleteListener) {
super(context, display);
}
String url = "https://www.google.com/"; //default url
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webview_base);
WebViewActivity webViewActivity = new WebViewActivity();
}
public void setUrl(String incomingUrl) {
url = incomingUrl;
}
}
Specifically, the doc : https://source.android.com/docs/core/display/multi_display/ime-support seems like it refers to my situation, especially:
If there's an active connection on display A, and an input field requests input focus on display B, then the following flow occurs:
#1 A new input connection comes from the input field on display B.
#2 InputMethodManagerService checks if the connection should be approved.
#3 A display is selected for the IME. If display B supports showing the IME and is allowed to show it, then B is used. Otherwise, the primary device display is selected.
#4 If the selected display is not from display A, then the connection is re-established. InputMethodService is destroyed and then created again.
But, this is not happening. How can I tell Android that Display B is capable of showing a keyboard? I tried following this answer: https://stackoverflow.com/a/59244618/1042362 but I couldn't really get it to work. For what it's worth now, I now have the AOSP Keyboard in my project, but I'm not sure how to tell Android or the WebView to actually use it. (Also, please suggest some tags if the ones I chose are not good/there are others)