Get text from external keyboard connected to tablet - Android Q&A, Help & Troubleshooting

Hi,
I want to get some text from a keyboard connected to a tablet but I don't want to use an EditText.
With the following event I can handle keys like enter, space-bar, return, arrows but not characters like 'a','b', etc...
public boolean dispatchKeyEvent(KeyEvent e) {
Log.d("KEYBOARD",e.toString());
return true;
};
I need to wait for the user to input some text but I want it invisible to the user. I open a msgbox, ask for some text and only after manage the text I show it to the user. Basically I need some event like the one above but for all keys.
Thanks

Related

[Q] Anyone know why random children are being selected when I use ActionMode?

Some of my list view's children will appear selected, when in fact they are not. For example, If I select the first child only and enter ActionMode, several other children will appear as though I've selected them, but aren't actually selected. I've noticed this only happens when I have more than 6 children available.
To be completely clear, if I select the first child I'll enter ActionMode and it will turn blue, but several other children will also turn blue, even though I haven't selected them.
Code:
public void onItemCheckedStateChanged(ActionMode mode, int position,
long id, boolean checked) {
final int checkedCount = lv.getCheckedItemCount();
mSelectedConvCount.setText(Integer.toString(checkedCount));
if (checked) {
lv.getChildAt(position).setBackgroundColor(
Color.BLUE);
} else {
lv.getChildAt(position).setBackgroundColor(
Color.TRANSPARENT);
}
}
}
Questions or Problems Should Not Be Posted in the Development Forum
Please Post in the Correct Forums
Moving to Q&A

[Q] Capture raw soft-keyboard events

Hi all
I have an issue with an app I am writing. It has the working name VNCHID, and is designed to allow an Android phone/tab to be used as a keyboard and mouse for a computer (or other device) over VNC. I currently have it in a semi-working state, but with unpredictable results. I am hoping someone can help with the issues I have come accross.
The first is related to mapping KeyEvents to VNC (X11) KeySyms. I have derived a class from KeyEvent wrich adds a method "getKeySym". This method does the following:
Uses the getUnicodeCharacter method from KeyEvent to try to determine a character from the key (combination). If one exists, it uses a map (found elsewhere) to translate this into a KeySym.
Does the same again, but without modifier keys. This may be unnecessary, but for now I have left it in.
Assuming the above fails, it uses getKeyCode and runs this through my own map to generate a KeySym.
The problem I am facing on my development device, an A10-based tablet running CM9, is that if a key is pressed which doesn't have a unicode character associated with it, like backspace, the code just stops at getUnicodeCharacter. It doesn't crash the app, throw an exception, or anything else, the execution of the routine just stops completely. It will still pick up other keyevents afterwards.
This seems very strange, and I do not know why it would do so.
My second problem is on my day-to-day phone. I tried installing the app on here to see if the problem was with the device/ROM/etc, but on here it doesn't even detect any keyevents. I have done some research which indicates that my approach (implementing OnKeyListener) is not guaranteed to work with soft keyboards, but it seems very strange that it (almost) does on one device but not on another (using the same soft keyboard, hackers keyboard).
I am now almost at the stage of creating my own keyboard (not an IME, just a layout to be shown in the app with a keyboard), but would like to avoid this. Can anyone help? I am tearing my hair out. Does anyone know the correct way to receive keyevents from a soft keyboard? I do not want an edittext, I just want the raw key events.
The code for my getKeySym() method is bellow. It stops at the first getUnicodeCharacter() call when a non-character key is pressed:
Code:
// Test unicode
Log.i("VNCHID.VKE","Translating keyevent to keysym");
int keysym=0, ucc=0;
ucc=this.getUnicodeChar(this.getMetaState());
Log.i("VNCHID.VKE","Got ucc");
if( ucc > 0 ) {
keysym = UnicodeToKeysym.translate(ucc);
}
if( keysym > 0 ) {
Log.i("VNCHID.VKE", "Got keysym "+keysym+" from ucc "+ucc);
return keysym;
}
// Test unicode without modifiers
ucc=this.getUnicodeChar(0);
if( ucc > 0 ) {
keysym = UnicodeToKeysym.translate(ucc);
}
if( keysym > 0 ) {
Log.i("VNCHID.VKE", "Got keysym "+keysym+" from ucc wom "+ucc);
return keysym;
}
Log.i("VNCHID.VKE","Could not find keysym from ucc, trying from keycode");
// Otherwise lookup from KeyCode
if( KCSM.size() < 1 ) generateKeyCodeSymMap();
/*KCSM.
if( KCSM.containsKey(this.getKeyCode()) ) return KCSM.get(this.getKeyCode());
*/
keysym=KCSM.get(this.getKeyCode(), -1);
Log.i("VNCHID.VKE","Result of lookup by keycode "+this.getKeyCode()+" is "+keysym);
return keysym;
Note it was much simpler, but I have expanded it and inserted the Log calls for debugging. As an example, when backspace is pressed I receive log lines from my onKey method, plus the first one in this method (Translating keyevent to keysym) but nothing after that.
Please help!
Hi
Is this the right forum to be asking questions like this? I'm not trying to be pushy, it's just I've come to expect quick, helpful answers on this site, so I just wanted to double check.
If so... Bump
If not, could someone please point me towards the appropriate forum?
Sent from my MB860 using xda premium

[Help] EditText in notification draw

I'm trying to put a edittext box in the notification draw, so far it displays fine but I cannot interact with it e.g. click inside and start typing. I've out my XML code inside status_bar_expanded.xml. Like I said, it displays fine but is unusable.
Thanks for any help

[Q] App to perform the same effect as the touch button task shifting

Good evening, I'm a newbie, I read about intent, activity and other things in Android but can not get the effect I want.
I would make exactly the same action that causes the button to the left. "switch between tasks" of a Galaxy Tab 4. Run the code in my application and pass to any previously opened application.
I've tried several codes like this, and I've also searched some information about the PID of the process, but I know not to handle them too well:
Intent intent1 = new Intent(Intent.ACTION_VIEW); // OR ACTION_MAIN ??
intent1.addFlags(Intent.FLAG_ACTIVITY_BROUGHT_TO_FRONT );
intent1.addCategory(Intent.CATEGORY_LAUNCHER);
PackageManager manager = getPackageManager();
intent1 = manager.getLaunchIntentForPackage("com.other.externalapp");
startActivity(intent1);
PD: This code works, but it opens a new instance of "com.other.externalapp" and not what I want, it close an internal connection of "externalapp". I want exactly the same effect achieved with switching between applications with the Galaxy tab touch button.
Maybe it's a permission problem, or to be able to run the exact same PID already open.
Thank you very much for your help people. :good:

[Q] Admob event is not firing sometimes, or is firing, but not completely

I use Admob's rewarded video ad. It can be called by button from my game's pause menu and game over screen. So it works almost always in pause menu, and it's worse on game over screen. So, here's the event handler code:
Code:
public void HandleRewardBasedVideoRewarded(object sender, Reward args)
{
this.RequestRewardBasedVideo();
Lives.lives++;
rewardButtonP.interactable = false;
rewardButtonG.interactable = false;
GameObject.Find("banner").GetComponent<AdBanner>().bannerView.Hide();
if (!pauseUI.activeSelf)
respawn.RespawnAction();
}
Bug 1: Button is always non-interactable if ad is not loaded, but sometimes it is interactable, and nothing happens on click. It looks like 1st, 3rd and 4'th lines were not called.
Bug 2: Sometimes respawn.RespawnAction() is not called from game over screen (it must be called only from there). And it is 100% that !pauseUI.activeSelf.
These bugs are seemed to be random.

Categories

Resources