How to add metadata dynamically (Not in manifest but inside code)?

后端 未结 3 343
终归单人心
终归单人心 2020-12-17 01:33

I want to set app meta data using code. Is it possible in Android ? Trying to set Facebook app id into code not inside manifest.

meta-data android:name=\"co         


        
相关标签:
3条回答
  • 2020-12-17 01:47

    for add any metadata dynamically you can use this code:

    try {
                ApplicationInfo applicationInfo = getPackageManager().getApplicationInfo(getPackageName(), PackageManager.GET_META_DATA);
                applicationInfo.metaData.putString("Your Key", "Your Value");
            } catch (PackageManager.NameNotFoundException e) {
                e.printStackTrace();
            }
    
    0 讨论(0)
  • 2020-12-17 01:47

    Hello all i know above answer is right for older sdk version, but in

    facebook sdk 4+
    

    there is no Session class

    You can simply do it by using this single line code:

    FacebookSdk.setApplicationId(APP_ID);
    

    Thanks!

    0 讨论(0)
  • 2020-12-17 02:01

    I want to set app meta data using code.Is it possible in android ?

    No, it's not possible. The manifest get's parsed at compile time -> you can't add meta-data at runtime.

    0 讨论(0)
提交回复
热议问题