2

I've an activity which has a meta data tag associated with it.


        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>

            <meta-data
                android:name="type"
                android:value="a" />
        </activity>

At any point of time from my activity I need to know whether my activity is associated with the meta data tag of type 'a' or not. How to achieve this. I tried something like

        Intent intent = mCurrentActivity.getIntent();
        Bundle bundle = (intent != null) ? intent.getExtras() : null;
        String value = (bundle != null) ? bundle.getString("type") : null;

but this is always returning me null not a. Am I missing something here?

Tom Taylor
  • 3,344
  • 2
  • 38
  • 63

1 Answers1

4

Use this for getting metadata:

ActivityInfo activityInfo = getPackageManager()
    .getActivityInfo(getComponentName(), PackageManager.GET_META_DATA);
Bundle bundle = activityInfo.metaData;
String value = bundle.getString("type");
Saurabh Thorat
  • 18,131
  • 5
  • 53
  • 70