Skip to content

Commit

Permalink
Merge pull request #2 from APSL/iss_1
Browse files Browse the repository at this point in the history
Android version
  • Loading branch information
alvaromb authored Sep 2, 2016
2 parents 116f32c + a1e47aa commit b537d91
Show file tree
Hide file tree
Showing 5 changed files with 105 additions and 1 deletion.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ buck-out
.gradle
local.properties
*.iml
/android/

# Node
node_modules
Expand Down
25 changes: 25 additions & 0 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

apply plugin: 'com.android.library'

android {
compileSdkVersion 23
buildToolsVersion "23.0.1"

defaultConfig {
minSdkVersion 16
targetSdkVersion 22
versionCode 1
versionName "1.0"
ndk {
abiFilters "armeabi-v7a", "x86"
}
}
lintOptions {
warning 'InvalidPackage'
}
}

dependencies {
compile 'com.facebook.react:react-native:0.20.+'
}

5 changes: 5 additions & 0 deletions android/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.apsl.versionnumber">

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@

package com.apsl.versionnumber;

import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.bridge.ReactContextBaseJavaModule;
import com.facebook.react.bridge.ReactMethod;
import com.facebook.react.bridge.Callback;

import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.pm.PackageManager;

import java.util.HashMap;
import java.util.Map;

public class RNVersionNumberModule extends ReactContextBaseJavaModule {

private final ReactApplicationContext reactContext;

private static final String APP_VERSION = "appVersion";
private static final String APP_BUILD = "buildVersion";

public RNVersionNumberModule(ReactApplicationContext reactContext) {
super(reactContext);
this.reactContext = reactContext;
}

@Override
public String getName() {
return "RNVersionNumber";
}

@Override
public Map<String, Object> getConstants() {
final Map<String, Object> constants = new HashMap<>();
final PackageManager packageManager = this.reactContext.getPackageManager();
final String packageName = this.reactContext.getPackageName();
try {
constants.put(APP_VERSION, packageManager.getPackageInfo(packageName, 0).versionName);
constants.put(APP_BUILD, packageManager.getPackageInfo(packageName, 0).versionCode);
} catch (NameNotFoundException e) {
e.printStackTrace();
}
return constants;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@

package com.apsl.versionnumber;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;

import com.facebook.react.ReactPackage;
import com.facebook.react.bridge.NativeModule;
import com.facebook.react.bridge.ReactApplicationContext;
import com.facebook.react.uimanager.ViewManager;
import com.facebook.react.bridge.JavaScriptModule;

public class RNVersionNumberPackage implements ReactPackage {
@Override
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
return Arrays.<NativeModule>asList(new RNVersionNumberModule(reactContext));
}

@Override
public List<Class<? extends JavaScriptModule>> createJSModules() {
return Collections.emptyList();
}

@Override
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
return Collections.emptyList();
}
}

0 comments on commit b537d91

Please sign in to comment.