2

I wish to get name/packageName of current app using my customKeyboard service.

Is there anyway to do so?

Dirindon
  • 634
  • 1
  • 5
  • 15

3 Answers3

4

You have to rely on getCurrentInputEditorInfo(), a method in InputMethodService, to achieve this:

String packageName = getCurrentInputEditorInfo().packageName;
jfcartier
  • 1,095
  • 12
  • 20
0

Found answer in this topic: How to check current running applications in Android?

If app is running its obviosuly the one calling my keyboard.

Community
  • 1
  • 1
Dirindon
  • 634
  • 1
  • 5
  • 15
-1
private String getApplicationName() {
    final PackageManager pm = mActivity.getApplicationContext()
            .getPackageManager();
    ApplicationInfo ai;
    String appName;
    try {
        ai = pm.getApplicationInfo(mActivity.getPackageName(), 0);
        appName = (String) pm.getApplicationLabel(ai);
    } catch (final NameNotFoundException e) {
        appName = "(unknown)";
    }
    return appName;
}

use this method to get Appname/Package name

Ankit Kumar
  • 3,663
  • 2
  • 26
  • 38
  • This allowes me to get appname/package name (as long as I implemented it correctly) of my own app, I created keyboard service and wish to know which app uses it to write inside of that app. – Dirindon May 05 '15 at 15:30
  • Downvoted. This does not attempt to answer the question asked. – Vicky Chijwani Mar 14 '16 at 17:52