As Gabe said, you can't control the orientation of the app.
What you can do is, if the app is in portrait mode, don't show the keyboard but display a message saying 'the keyboard works only in landscape mode'.
This can be done using the onConfigurationChanged() method.
@Override
public void onConfigurationChanged(Configuration newConfig) {
InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
IBinder token = getWindow().getWindow().getAttributes().token;
if (newConfig.orientation == Configuration.ORIENTATION_LANDSCAPE) {
imm.showSoftInputFromInputMethod(token, InputMethodManager.SHOW_FORCED);
} else if (newConfig.orientation == Configuration.ORIENTATION_PORTRAIT) {
imm.hideSoftInputFromInputMethod(token, InputMethodManager.RESULT_HIDDEN);
Toast.makeText(getApplicationContext(),"Keyboard works only in landscape mode!",Toast.LENGTH_LONG).show();
}
}
Ans also in onStartInputView()
method put a check:
@Override
public void onStartInputView(EditorInfo info, boolean restarting) {
super.onStartInputView(info, restarting);
if(getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT){
//hide the keyboard & display a message (same as onConfigurationChanged())
} else{
//dont do anything...we are good to go!
}
}