獲取清單文件中meta-data值

獲取Mainifest.xml文件中meta-data值: java

<meta-data
            android:name="com.facebook.sdk.ApplicationId"
            android:value="@string/app_id" />
public static final String APPLICATION_ID_PROPERTY = "com.facebook.sdk.ApplicationId";

 

public static String getMetadataApplicationId(Context context) {
        try {
            ApplicationInfo ai = context.getPackageManager().getApplicationInfo(
                    context.getPackageName(), PackageManager.GET_META_DATA);
            if (ai.metaData != null) {
                return ai.metaData.getString(Session.APPLICATION_ID_PROPERTY);
            }
        } catch (PackageManager.NameNotFoundException e) {
            // if we can't find it in the manifest, just return null
        }

        return null;
    }
相關文章
相關標籤/搜索