Samsung Keyboard Suppress - android

With a bluetooth keyboard connected, the Note 2 forces the switch back to the Samsung keyboard. This is a problem, as the Samsung keyboard always pops up when I'm trying to type with my external, taking up screen space and defeating half the purpose. I could write an app that forces the switch back, probably, but I'd still have to hit Enter/OK everytime the keyboard connects. I disabled the Samsung keyboard altogether, but the OK button still shows up. Is there some sort of service that does this or something? Because if I can't block/disable whatever it is, it's going to mess with my workflow, seeing as I bought this K810 to switch between multiple devices.

Here's a code snippet I use in order to prevent the keyboard to popup at application start:
public void hideSoftKeyboard(View v) {
Activity activity = (Activity) v.getContext();
InputMethodManager inputMethodManager = (InputMethodManager) activity.getSystemService(Activity.INPUT_METHOD_SERVICE);
inputMethodManager.hideSoftInputFromWindow(activity.getCurrentFocus().getWindowToken(), 0);
}
I think that if you can detenct the event with:
http://developer.android.com/reference/android/content/res/Configuration.html#keyboard
There are some flags, which indicate what's the inserted keyboard.
Or just try this one, even though i didn't test it:
public boolean onEvaluateInputViewShown() {
return false;
}
Let me know then of the results.
Thanks

Related

How to disable softKeyboard if there is a hardware Keyboard

Actually i'm checking by this method if there is a hardware keyboard on my device
private boolean isHardwareKeyboardAvailable() { return getResources().getConfiguration().keyboard != Configuration.KEYBOARD_NOKEYS; }
But now i would be able to disable the softKeyboard for that activity if the result of that boolean is true. How can i do?
Actually for a target of devices i set in my manifest
android:windowSoftInputMode="stateVisible"
But i have to disable even it.
Any suggestion?
The easiest way to do it is by preventing the keyboard from popping up automatically:
this.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
Put this code when you realized that the phone has physical keyboard.

How close soft keyboard of previous application?

I have an application with custom keyboard on first screen.
It works o'key! But in some cases application opens with custom and native keyboards...
for example: i am writing an sms, receive notification from my app and click on it (soft keyboard from sms-app still open).
In this case will open my application with both keyboards...
take a look on screenshot
So any method like next one are not working, cos in my just opened application none view have focus and view = null:
View view = getActivity().getCurrentFocus();
if (view != null) {
InputMethodManager imm = (InputMethodManager)getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
any ideas how can I close all previously opened keyboards from other apps?

Using subclass of Input Method Service

I extended InputMethodService hoping to use this Service for showing a soft keyboard even though a hard keyboard is connected(based off the following post Show soft keyboard even though a hardware keyboard is connected). Is there a way to bind to this service within the app without having to declare it in the manifest? The end result is to have InputMethodService.onEvaluateInputViewShown return true so that the soft keyboard will show even though a hard keyboard is connected.
I would like to use the extended class MultiInputMethodService with the inputmethodmanager in show/hideSoftKeyboard:
public class MultiInputMethodService extends InputMethodService {
#Override
public boolean onEvaluateInputViewShown () {
Log.i("onEvaluateInputViewShow","onEvaluateInputViewShown");
return true;
}
}
my activity:
private void showSoftKeyboard() {
InputMethodManager imm = (InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,InputMethodManager.HIDE_IMPLICIT_ONLY );
}
private void hideSoftKeyboard() {
InputMethodManager imm = (InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(this.myInput.getEditText().getWindowToken(), 0);
}
The IMS framework really needs to be used as a whole. If you want to be the keyboard, the user will need to select you as the default keyboard via settings. If you were to try to bind with the service directly I'm not sure what the result would be, but my guess would be that it ends badly. By having the user set you as the default keyboard, you will automatically be used as the keyboard in all apps.
Of course, you can't just set that yourself, for security purposes. Otherwise keyboards would be fighting over the setting. The user has to set it manually.
EDIT:
I found the documentation you are referring to(under the "Security Section"):
http://developer.android.com/reference/android/view/inputmethod/InputMethodManager.html
A client application can ask that the system let the user pick a new
IME, but can not programmatically switch to one itself. This avoids
malicious applications from switching the user to their own IME, which
remains running when the user navigates away to another application.
An IME, on the other hand, is allowed to programmatically switch the
system to another IME, since it already has full control of user
input.
The user must explicitly enable a new IME in settings before they can
switch to it, to confirm with the system that they know about it and
want to make it available for use.

Android bug? Popup dialogs and spinners invisible; screen dims

I have an app that has a few Spinners and a couple of Buttons that pop up Dialogs. Other Buttons start new Activities.
On startup, these all work fine. However, when a new Activity is started and then we return, all pop-up elements stop working properly - the screen dims, but no dialog appears. In this state:
if you tap where the dialog's buttons should be (such as an "OK" button), their callbacks are called and everything works fine
rotating the phone will cause a redraw and the dialog will be visible again
This seems to me to be an Android bug. There seem to be very few references to it anywhere, and I'm at a loss as to what triggers it, and how I can work around it. As requested by #ethan, code fragment for one possible path is below, but there's little to it; I don't need to return any results, and the problem is exhibited when the user simply presses the Back button (which just has the default binding).
private OnClickListener button_click = new OnClickListener()
{
public void onClick(View v) {
int lId = v.getId();
...
if ( lId == R.id.cancel_button ) {
finish();
}
...
}
}
This is probably not helpful - I'm hoping someone will recognize the symptom. In the meantime, I'm trying to work up a mock example that exhibits the problem.
It does not occur in 1.5 or 1.6, but does in 2.2.

Android - Activities and navigation?

I navigate from Activity1 to Activity2
On Activity 2 I have a keyboard and this keyboard stays on the screen after selecting the back button and going to Activity 1.
This is how I fixed this issue
// This code is in Activity 2
#Override
public void onBackPressed() {
startActivity(intentForActivity1);
finish();
}
Is this a wrong solution to my problem?
Is it a bad idea to handle the back button manually?
Since you're capturing the back button press, most probably the soft keyboard does not receive the press and thus it does not hide.
Try hiding it yourself:
#Override
public void onBackPressed() {
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(myEditText.getWindowToken(), 0);
startActivity(intentForActivity1);
finish();
}
See Reto Meier's answer for more details on this method to hide the keyboard: Close/hide the Android Soft Keyboard
There's nothing inherently wrong with overriding the back button. Just make sure the behavior isn't confusing to the user.
Also, if you ever just want to hide the soft keyboard (say, you're switching between tabs or something like that), you can use InputMethodManager. Here's a thread where people discussed ways to do this.

Categories

Resources