Skip to content

Commit ed60aac

Browse files
committed
updates
1 parent 2baf2f6 commit ed60aac

7 files changed

+88
-40
lines changed

README.md

+1-10
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
#### Android
2323

2424
1. Open up `android/app/src/main/java/[...]/MainActivity.java`
25-
- Add `import com.reactlibrary.RNInfoManifestBridgePackage;` to the imports at the top of the file
25+
- Add `import com.jimlake.RNInfoManifestBridgePackage;` to the imports at the top of the file
2626
- Add `new RNInfoManifestBridgePackage()` to the list returned by the `getPackages()` method
2727
2. Append the following lines to `android/settings.gradle`:
2828
```
@@ -34,14 +34,6 @@
3434
compile project(':react-native-info-manifest-bridge')
3535
```
3636

37-
#### Windows
38-
[Read it! :D](https://github.com/ReactWindows/react-native)
39-
40-
1. In Visual Studio add the `RNInfoManifestBridge.sln` in `node_modules/react-native-info-manifest-bridge/windows/RNInfoManifestBridge.sln` folder to their solution, reference from their app.
41-
2. Open up your `MainPage.cs` app
42-
- Add `using Info.Manifest.Bridge.RNInfoManifestBridge;` to the usings at the top of the file
43-
- Add `new RNInfoManifestBridgePackage()` to the `List<IReactPackage>` returned by the `Packages` method
44-
4537

4638
## Usage
4739
```javascript
@@ -50,4 +42,3 @@ import RNInfoManifestBridge from 'react-native-info-manifest-bridge';
5042
// TODO: What to do with the module?
5143
RNInfoManifestBridge;
5244
```
53-

android/src/main/AndroidManifest.xml

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11

22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3-
package="com.reactlibrary">
3+
package="com.jimlake.infomanifestbridge">
44

55
</manifest>
6-
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
package com.jimlake;
2+
3+
import com.facebook.react.bridge.ReactApplicationContext;
4+
import com.facebook.react.bridge.ReactContextBaseJavaModule;
5+
import com.facebook.react.bridge.ReactMethod;
6+
import com.facebook.react.bridge.Callback;
7+
8+
import javax.annotation.Nullable;
9+
import java.util.Map;
10+
import java.util.HashMap;
11+
12+
import android.content.pm.ApplicationInfo;
13+
import android.content.pm.PackageInfo;
14+
import android.content.pm.PackageManager;
15+
import android.os.Build;
16+
import android.os.Bundle;
17+
import android.util.Log;
18+
19+
public class RNInfoManifestBridgeModule extends ReactContextBaseJavaModule {
20+
public static final String TAG = "RNInfoManifestBridgeModule";
21+
22+
private final ReactApplicationContext reactContext;
23+
24+
public RNInfoManifestBridgeModule(ReactApplicationContext reactContext) {
25+
super(reactContext);
26+
this.reactContext = reactContext;
27+
}
28+
29+
@Override
30+
public String getName() {
31+
return "RNInfoManifestBridge";
32+
}
33+
34+
@Override
35+
public @Nullable Map<String, Object> getConstants() {
36+
final Map<String, Object> constants = new HashMap<>();
37+
38+
try {
39+
final ApplicationInfo ai = reactContext.getPackageManager().getApplicationInfo(reactContext.getPackageName(),PackageManager.GET_META_DATA);
40+
final Bundle bundle = ai.metaData;
41+
for (String key : bundle.keySet()) {
42+
final String value = bundle.get(key).toString();
43+
constants.put(key,value);
44+
}
45+
46+
final int labelId = ai.labelRes;
47+
final String displayName = labelId == 0 ? ai.nonLocalizedLabel.toString() : reactContext.getString(labelId);
48+
constants.put("displayName",displayName);
49+
constants.put("bundleName",displayName);
50+
} catch (final Exception e) {
51+
Log.e(TAG,"Failed to pull things from manifest",e);
52+
}
53+
54+
try {
55+
final PackageInfo pInfo = reactContext.getPackageManager().getPackageInfo(reactContext.getPackageName(),0);
56+
final String versionCode = String.valueOf(pInfo.versionCode);
57+
constants.put("bundleIdentifier",pInfo.packageName);
58+
constants.put("shortVersion",pInfo.versionName);
59+
constants.put("version",versionCode);
60+
constants.put("androidVersionCode",versionCode);
61+
} catch (final Exception e) {
62+
Log.e(TAG,"Failed to pull from package info",e);
63+
}
64+
65+
constants.put("androidDeviceName",getDeviceName());
66+
return constants;
67+
}
68+
69+
private String getDeviceName() {
70+
final String brand = Build.BRAND; //= "motorola"
71+
final String model = Build.MODEL; //= "XT1053"
72+
73+
String deviceType = "";
74+
if (model.startsWith(brand)) {
75+
deviceType = model;
76+
} else {
77+
deviceType = brand + " " + model;
78+
}
79+
return deviceType;
80+
}
81+
}

android/src/main/java/com/reactlibrary/RNInfoManifestBridgePackage.java android/src/main/java/com/jimlake/RNInfoManifestBridgePackage.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
2-
package com.reactlibrary;
1+
package com.jimlake;
32

43
import java.util.Arrays;
54
import java.util.Collections;
@@ -10,6 +9,7 @@
109
import com.facebook.react.bridge.ReactApplicationContext;
1110
import com.facebook.react.uimanager.ViewManager;
1211
import com.facebook.react.bridge.JavaScriptModule;
12+
1313
public class RNInfoManifestBridgePackage implements ReactPackage {
1414
@Override
1515
public List<NativeModule> createNativeModules(ReactApplicationContext reactContext) {
@@ -25,4 +25,4 @@ public List<Class<? extends JavaScriptModule>> createJSModules() {
2525
public List<ViewManager> createViewManagers(ReactApplicationContext reactContext) {
2626
return Collections.emptyList();
2727
}
28-
}
28+
}

android/src/main/java/com/reactlibrary/RNInfoManifestBridgeModule.java

-22
This file was deleted.

ios/RNInfoManifestBridge.m

+1-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

22
#import <React/RCTBridgeModule.h>
3+
#import <UIKit/UIKit.h>
34

45
@interface RNInfoManifestBridge : NSObject <RCTBridgeModule>
56

@@ -14,8 +15,6 @@ + (BOOL)requiresMainQueueSetup {
1415
}
1516

1617
- (NSDictionary *)constantsToExport {
17-
NSLog(@"constantsToExport");
18-
1918
NSBundle *mainBundle = [NSBundle mainBundle];
2019
NSString *displayName = [mainBundle objectForInfoDictionaryKey:@"CFBundleDisplayName"];
2120
if (displayName == nil) {

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
{
33
"name": "react-native-info-manifest-bridge",
4-
"version": "1.0.0",
4+
"version": "1.0.1",
55
"description": "",
66
"main": "index.js",
77
"scripts": {

0 commit comments

Comments
 (0)