Android/meta-data
提供: 初心者エンジニアの簡易メモ
meta-dataの値をactivityで取得する方法
-AndroidManifest.xml
<application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme" > <meta-data android:name="log_flag" android:value="true" /> <meta-data android:name="custom1" android:value="hogehoge" /> </application>
-MainActivity.java
Context context = MainActivity.this.getApplicationContext(); try { ApplicationInfo appInfo = context.getPackageManager().getApplicationInfo(context.getPackageName(), PackageManager.GET_META_DATA); if (appInfo.metaData != null) { Log.i("test", "log_flag=" + appInfo.metaData.getBoolean("log_flag", false)); // true Log.i("test", "custom1=" + appInfo.metaData.getString("custom1")); // hogehoge } } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); }