-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from APSL/iss_1
Android version
- Loading branch information
Showing
5 changed files
with
105 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,7 +40,6 @@ buck-out | |
.gradle | ||
local.properties | ||
*.iml | ||
/android/ | ||
|
||
# Node | ||
node_modules | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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.+' | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
46 changes: 46 additions & 0 deletions
46
android/src/main/java/com/apsl/versionnumber/RNVersionNumberModule.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
android/src/main/java/com/apsl/versionnumber/RNVersionNumberPackage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |