Android/meta-data
提供: 初心者エンジニアの簡易メモ
meta-dataの値をactivityで取得する方法
-AndroidManifest.xml
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.test.myapplication" > <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" /> </application> </manifest>
-MainActivity.java
Context context = (Context)MainActivity.this; 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 } } catch (PackageManager.NameNotFoundException e) { e.printStackTrace(); }