Skip to content
This repository has been archived by the owner on Apr 28, 2022. It is now read-only.

Commit

Permalink
Add hasMetadata() method.
Browse files Browse the repository at this point in the history
  • Loading branch information
Roman Savin committed Sep 28, 2015
1 parent 2f09293 commit e30c2c6
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 6 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ 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:
```xml
<dependency>
<groupId>org.onepf</groupId>
<artifactId>opfutils</artifactId>
<version>0.1.25</version>
<version>0.1.26</version>
</dependency>
```

Expand Down
6 changes: 3 additions & 3 deletions opfutils/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ android {

defaultConfig {
minSdkVersion 15
targetSdkVersion 22
targetSdkVersion 23
versionCode 1
versionName "0.1.25"
versionName "0.1.26"
}

buildTypes {
Expand All @@ -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'
}
28 changes: 27 additions & 1 deletion opfutils/src/main/java/org/onepf/opfutils/OPFChecks.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -124,7 +125,7 @@ public static void checkPermission(@NonNull final Context context,

/**
* Checks if supplied permission is requested in AndroidManifest.xml file.
* <p>
* <p/>
* Throws {@link SecurityException} if it's not.
*
* @param context The instance of {@link android.content.Context}.
Expand All @@ -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.
Expand Down

0 comments on commit e30c2c6

Please sign in to comment.