title: Extract / distinguish ActivityAlias name from TargetActivity
body: <p>I have multiple <code>ActivityAliases</code> which all start one single <code>TargetActivity</code>.
  Inside of my <code>TargetActivity</code> I try to <strong>distinguish the alias</strong> that started
  the <code>TargetActivity</code>.</p>
  
  <p>The aliases are defined in <code>Manifest</code> as launchables (intent-filter), which will be displayed as 
  shortcuts on the homescreen. The user will click on the shortcut and android
  will start the activity, which I defined in the "<code>android:targetActivity=..</code>" tag.</p>
  
  <p>For that I currently extract the <code>componentName</code> from the <code>Intent</code>, which is 
  given to my TargetActivity and using the <code>className()</code>.</p>
  
  <p>Like:</p>
  
  <pre><code>String aliasName = targetActivity.getComponentName().getClassName();
  </code></pre>
  
  <p>This works fine for a lot of devices. But currently I see some failures on 
  the <em>OnePlus</em>. At that device, <strong>my technique only returns the className of 
  my TargetActivity</strong> and therefore I can't deliver the action, based on the 
  alias that the user started.</p>
  
  <p>Are there any other, <strong>reliable</strong> methods to get <code>ActivityAlias</code> that was used to
  start the <code>TargetActivity</code>? It does not need to be the name itself, as long 
  as I can distinguish them. <em>I do not want to create dedicated TargetActivities for every Alias!</em></p>
  
  <p>Thanks!</p>
  
  <p>Ps.: I saw another way, which uses the PackageManager to retrieve the 
  activityInfo and using the Activity.name. But I doubt that this will 
  return something different than my first approach.</p>
  
  <pre><code>ActivityInfo aInfo = activity.getPackageManager().getActivityInfo(activity.getComponentName(), PackageManager.GET_META_DATA);
  
  String aliasName = aInfo.name;
  </code></pre>
  
  <p><strong>I also tried meta-data:</strong></p>
  
  <p><strong>Edit:</strong></p>
  
  <p><em>Unfortunately this method does not work for all devices. 
  If the parsed <code>alias-className</code> from the activity.component returns the
  <code>target-activity</code>, then the meta-data approach fails, too.</em></p>
  
  <p>I continued searching for an answer and found a good workaround to 
  distinguish between my aliases inside of the TargetActivty.</p>
  
  <p>You can provide meta-data within your ActivityAlias tag like so:</p>
  
  <pre><code>&lt;activity-alias 
      android:name=".aliasName" 
      android:enabled="false" 
      android:exported="true" 
      android:icon="@drawable/someIconRes" 
      android:label="@string/someLabelRes" android:targetActivity=".yourTargetActivity"&gt; 
      &lt;meta-data android:name="alias" android:value="valueToDistinguish"/&gt;
      &lt;intent-filter&gt;  
          &lt;action android:name="android.intent.action.MAIN"/&gt; 
          &lt;category android:name="android.intent.category.LAUNCHER"/&gt; 
      &lt;/intent-filter&gt; 
  &lt;/activity-alias&gt;
  </code></pre>
  
  <p>The important part here is:</p>
  
  <pre><code>&lt;meta-data android:name="alias" android:value="valueToDistinguish"/&gt;
  </code></pre>
  
  <p>Which is within the <code>&lt;activity-alias&gt;</code> here <code>&lt;/activity-alias&gt;</code> tag.</p>
  
  <p>To extract the meta-data you can get an ActivityInfo from the PackageManager 
  with the TargetActivity:</p>
  
  <pre><code>ActivityInfo appInfo = activity.getPackageManager().getActivityInfo(activity.getComponentName(), PackageManager.GET_META_DATA);
  </code></pre>
  
  <p>And extract the meta-data via:</p>
  
  <pre><code>    private static String getAliasNameByMetaData(ActivityInfo app) {
      String aliasName = "";
      if (app.metaData != null &amp;&amp; app.metaData.containsKey(ALIAS_META_DATA_KEY)) {
          aliasName = app.metaData.getString(ALIAS_META_DATA_KEY, "");
      } else {
          LOG.i("AliasName by META-DATA didn't work!");
      }
      LOG.v("AliasName by META-DATA: " + aliasName);
      return aliasName;
  }
  </code></pre>
  
  <p><strong>Edit:</strong></p>
  
  <p>Inspecting the <code>Activity</code> class using the debugger, it includes a <code>mActivityInfo</code> field that is different from the <code>ActivityInfo</code> returned by <code>getPackageManager().getActivityInfo()</code> so you can extract it using reflection and check it's name.</p>
  
  <p>Note: It seems that the <code>ActivityInfo</code> returned by <code>getPackageManager().getActivityInfo()</code> is a shallow copy of the <code>mActivityInfo</code> from the <code>Activity</code>. So, maybe this method does not resolve the issue:</p>
  
  <pre><code>Field field = Activity.class.getDeclaredField("mActivityInfo");
  field.setAccessible(true);
  ActivityInfo value = (ActivityInfo) field.get(this);
  Log.e("APPINFO2", "NAME: " + value.name);
  </code></pre>