Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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="com.facebook.sdk.ApplicationId"android:value="@string/applicationId" 

Please help me.

like image 877
Kinjal Avatar asked Aug 28 '13 22:08

Kinjal


2 Answers

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.

like image 98
Ahmad Avatar answered Oct 07 '22 18:10

Ahmad


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();
        }
like image 45
Naser Karimi Avatar answered Oct 07 '22 18:10

Naser Karimi