@norcy/react-native-toolkit 0.1.141 → 0.1.142
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/android/src/main/java/com/norcy/reactnativetoolkit/CheckPackageInstallationModule.java
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
package com.norcy.iread;
|
2
|
+
|
3
|
+
import com.facebook.react.bridge.NativeModule;
|
4
|
+
import com.facebook.react.bridge.ReactApplicationContext;
|
5
|
+
import com.facebook.react.bridge.ReactContext;
|
6
|
+
import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
7
|
+
import com.facebook.react.bridge.ReactMethod;
|
8
|
+
import com.facebook.react.bridge.Callback;
|
9
|
+
|
10
|
+
import android.content.Intent;
|
11
|
+
import android.content.pm.PackageManager;
|
12
|
+
import android.content.Context;
|
13
|
+
import android.net.Uri;
|
14
|
+
|
15
|
+
public class CheckPackageInstallationModule extends ReactContextBaseJavaModule {
|
16
|
+
Context ctx;
|
17
|
+
public CheckPackageInstallationModule(ReactApplicationContext reactContext) {
|
18
|
+
super(reactContext);
|
19
|
+
this.ctx = reactContext.getApplicationContext();
|
20
|
+
}
|
21
|
+
|
22
|
+
@Override
|
23
|
+
public String getName() {
|
24
|
+
return "CheckPackageInstallation";
|
25
|
+
}
|
26
|
+
|
27
|
+
@ReactMethod
|
28
|
+
public void isPackageInstalled(String packageName, Callback cb) {
|
29
|
+
PackageManager pm = this.ctx.getPackageManager();
|
30
|
+
try {
|
31
|
+
pm.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES);
|
32
|
+
cb.invoke(true);
|
33
|
+
} catch (Exception e) {
|
34
|
+
cb.invoke(false);
|
35
|
+
}
|
36
|
+
}
|
37
|
+
|
38
|
+
@ReactMethod
|
39
|
+
public void goToMarket(String packageName, String marketPackage, String marketActivity) {
|
40
|
+
Uri uri = Uri.parse("market://details?id=" + packageName);
|
41
|
+
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
|
42
|
+
// https://www.cnblogs.com/upwgh/p/11054397.html
|
43
|
+
// intent.setClassName(marketPackage, marketActivity);
|
44
|
+
intent.setPackage(marketPackage);
|
45
|
+
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
46
|
+
ctx.startActivity(intent);
|
47
|
+
}
|
48
|
+
}
|
@@ -14,7 +14,8 @@ class ReactNativeToolkitPackage : ReactPackage {
|
|
14
14
|
return Arrays.asList<NativeModule>(
|
15
15
|
ReactNativeToolkitModule(reactContext),
|
16
16
|
NCYReport(reactContext),
|
17
|
-
NCYAPI(reactContext)
|
17
|
+
NCYAPI(reactContext),
|
18
|
+
CheckPackageInstallationModule(reactContext)
|
18
19
|
)
|
19
20
|
}
|
20
21
|
|