How do you add user defined properties/values in to the Android manifest file?

前端 未结 2 1680
挽巷
挽巷 2020-12-13 09:56

I want to add a custom attribute / property into the manifest file, and be able to read it at run time. I want to do this so I can customize the app\'s behavior via these ma

2条回答
  •  死守一世寂寞
    2020-12-13 10:07

    You can add meta-data to your AndroidManifest.xml file and then read that in your application.

    Write the data like so:

    
    

    And read the data like so:

    ApplicationInfo ai = context.getPackageManager().getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA);
    Object value = (Object)ai.metaData.get("foo");
    

    See http://developer.android.com/guide/topics/manifest/meta-data-element.html

提交回复
热议问题