diff --git a/README.md b/README.md index 493f8fe..e173766 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Common utils used among OPF libraries. Intended for the internal use. Download [the latest JAR][opfutils-latest-jar] or grab via Gradle: ```groovy -compile 'org.onepf:opfutils:0.1.25' +compile 'org.onepf:opfutils:0.1.26' ``` or Maven: @@ -13,7 +13,7 @@ or Maven: org.onepf opfutils - 0.1.25 + 0.1.26 ``` diff --git a/opfutils/build.gradle b/opfutils/build.gradle index 6759c6e..8458617 100644 --- a/opfutils/build.gradle +++ b/opfutils/build.gradle @@ -35,9 +35,9 @@ android { defaultConfig { minSdkVersion 15 - targetSdkVersion 22 + targetSdkVersion 23 versionCode 1 - versionName "0.1.25" + versionName "0.1.26" } buildTypes { @@ -60,5 +60,5 @@ dependencies { testCompile 'org.robolectric:robolectric:3.0-rc2' testCompile group: 'org.hamcrest', name: 'hamcrest-library', version: '1.3' - compile 'com.android.support:support-annotations:21.0.3' + compile 'com.android.support:support-annotations:23.0.1' } diff --git a/opfutils/src/main/java/org/onepf/opfutils/OPFChecks.java b/opfutils/src/main/java/org/onepf/opfutils/OPFChecks.java index 7a45e9b..a096b10 100644 --- a/opfutils/src/main/java/org/onepf/opfutils/OPFChecks.java +++ b/opfutils/src/main/java/org/onepf/opfutils/OPFChecks.java @@ -23,6 +23,7 @@ import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.content.pm.ResolveInfo; +import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.text.TextUtils; @@ -124,7 +125,7 @@ public static void checkPermission(@NonNull final Context context, /** * Checks if supplied permission is requested in AndroidManifest.xml file. - *

+ *

* Throws {@link SecurityException} if it's not. * * @param context The instance of {@link android.content.Context}. @@ -139,6 +140,31 @@ public static void checkPermission(@NonNull final Context context, } } + /** + * Checks if metadata is added in AndroidManifest.xml file. + * + * @param context The instance of {@link android.content.Context}. + * @param metadataKey The checked metadata key. + * @return True if metadata is added, false otherwise. + */ + public static boolean hasMetadata(@NonNull final Context context, @NonNull final String metadataKey) { + if (TextUtils.isEmpty(metadataKey)) { + throw new IllegalArgumentException("Meta data key can't be null or empty."); + } + + try { + final PackageInfo info = context.getPackageManager() + .getPackageInfo(context.getPackageName(), PackageManager.GET_META_DATA); + final Bundle metaData = info.applicationInfo.metaData; + if (metaData != null && metaData.get(metadataKey) != null) { + return true; + } + } catch (PackageManager.NameNotFoundException e) { + //ignore + } + return false; + } + /** * The same as {@link #checkReceiver(android.content.Context, String, android.content.Intent, String)} * with the {@code null} values for the {@code receiverName} and {@code permission} parameters.