3.2. 再 AndroidManifest.xml 使用 meta-data element 定義
...
<application ...>
...
...
<meta-data android:name="api_url" android:value="https://api.netkiller.cn/v1/"/>
<meta-data android:name="api_key" android:value="123456"/>
</application>
public static String getMetaData(Context context, String name) {
try {
ApplicationInfo ai = context.getPackageManager().getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA);
Bundle bundle = ai.metaData;
return bundle.getString(name);
} catch (PackageManager.NameNotFoundException e) {
Log.e(TAG, "Unable to load meta-data: " + e.getMessage());
}
return null;
}
String apiUrl = getMetaData(this, "api_url");
String apiKey = getMetaData(this, "api_key");