title: How to find active app name?
body: <p>I have this code that when I copy some text in clipboard this program paste text and application name automatically in the text box.I want paste app's name that running/on top </p>
  
  <pre><code>        myClipboard.addPrimaryClipChangedListener(new ClipboardManager.OnPrimaryClipChangedListener() {
          @Override
          public void onPrimaryClipChanged()
          {
              PackageManager pm = getApplicationContext().getPackageManager();
              ApplicationInfo ai;
              try {
                  ai = pm.getApplicationInfo(getPackageName(), 0);
              } catch (final PackageManager.NameNotFoundException e) {
                  ai = null;
              }
              final String applicationName = (String) (ai != null ? pm.getApplicationLabel(ai) : "(unknown)");
              ClipData cp = myClipboard.getPrimaryClip();
              ClipData.Item item = cp.getItemAt(0);
              String text1 = item.getText().toString();
              pastetext.setText(text1+"---"+applicationName);
          }
      });
  </code></pre>