Flo
Flo

Reputation: 1499

Android - Determine Calling Application of an InputMethod (Custom Keyboard)

I am implementing a custom keyboard following this guide: http://developer.android.com/guide/topics/text/creating-input-method.html

Is there a way that from within my KeyboardService which application (=package id) I am 'connected' to (which application receives the input events that I send)?

Upvotes: 1

Views: 319

Answers (1)

Flo
Flo

Reputation: 1499

Strange, 6 views in a day, thought this topic was more interesting. Well, anyway, I found a solution, here is the code if anyone ever needs it.

From the InputMethodService its possible to receive a InputBinding:

private String getCallerPackageId() {
    InputBinding binding = getCurrentInputBinding();
    return getApplicationContext().getPackageManager().getNameForUid(binding.getUid());
}

Upvotes: 5

Related Questions