10

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.

Niko
  • 1,367
  • 1
  • 13
  • 37
Kinjal
  • 173
  • 1
  • 1
  • 9
  • This link shows how to add app Id for facebook: [ADD DYNAMICALLY Facebook APP ID](https://stackoverflow.com/questions/15072937/facebook-sdk-for-android-set-application-id-programmatically/17016077#17016077) – Kinjal Sep 04 '13 at 20:09
  • its working nicely... Just add metadata into the manifest file as a place holder – Kinjal Sep 04 '13 at 20:10

3 Answers3

8

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.

Ahmad
  • 69,608
  • 17
  • 111
  • 137
  • is it possible to add value of appid at run time ? – Kinjal Aug 29 '13 at 01:17
  • No I'm afraid this is not possible either. – Ahmad Aug 29 '13 at 09:45
  • Is it possible to either add/remove or enable/disable a `meta-data` tag in the Manifest? For instance, a web browser app implementing `WebView` that offers users the ability to [opt-in/out of Google metrics collection](https://developer.android.com/guide/webapps/managing-webview#metrics). – AdamHurwitz Dec 06 '20 at 18:50
2

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

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!

Hardy
  • 2,576
  • 1
  • 23
  • 45