@simplysm/capacitor-plugin-auto-update 14.0.11 → 14.0.13

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.
@@ -7,6 +7,14 @@ android {
7
7
  defaultConfig {
8
8
  minSdk project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 23
9
9
  }
10
+ compileOptions {
11
+ sourceCompatibility JavaVersion.VERSION_21
12
+ targetCompatibility JavaVersion.VERSION_21
13
+ }
14
+ }
15
+
16
+ kotlin {
17
+ jvmToolchain(21)
10
18
  }
11
19
 
12
20
  dependencies {
@@ -0,0 +1,114 @@
1
+ package kr.co.simplysm.capacitor.apkinstaller
2
+
3
+ import android.content.Intent
4
+ import android.content.pm.PackageManager
5
+ import android.net.Uri
6
+ import android.os.Build
7
+ import android.provider.Settings
8
+ import android.util.Log
9
+
10
+ import com.getcapacitor.JSObject
11
+ import com.getcapacitor.Plugin
12
+ import com.getcapacitor.PluginCall
13
+ import com.getcapacitor.PluginMethod
14
+ import com.getcapacitor.annotation.CapacitorPlugin
15
+
16
+ @CapacitorPlugin(name = "ApkInstaller")
17
+ class ApkInstallerPlugin : Plugin() {
18
+
19
+ companion object {
20
+ private const val TAG = "ApkInstallerPlugin"
21
+ }
22
+
23
+ @PluginMethod
24
+ fun install(call: PluginCall) {
25
+ val uriStr = call.getString("uri")
26
+ if (uriStr == null) {
27
+ call.reject("uri is required")
28
+ return
29
+ }
30
+
31
+ try {
32
+ val apkUri = Uri.parse(uriStr)
33
+
34
+ val intent = Intent(Intent.ACTION_VIEW)
35
+ intent.setDataAndType(apkUri, "application/vnd.android.package-archive")
36
+ intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_GRANT_READ_URI_PERMISSION
37
+
38
+ context.startActivity(intent)
39
+ call.resolve()
40
+ } catch (e: Exception) {
41
+ Log.e(TAG, "install failed", e)
42
+ call.reject("Install failed: " + e.message)
43
+ }
44
+ }
45
+
46
+ @PluginMethod
47
+ fun checkPermissions(call: PluginCall) {
48
+ // Check granted
49
+ val granted = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
50
+ context.packageManager.canRequestPackageInstalls()
51
+ } else {
52
+ true
53
+ }
54
+
55
+ // Check manifest
56
+ var manifest = false
57
+ try {
58
+ val targetPermission = "android.permission.REQUEST_INSTALL_PACKAGES"
59
+ val requestedPermissions = context.packageManager
60
+ .getPackageInfo(context.packageName, PackageManager.GET_PERMISSIONS)
61
+ .requestedPermissions
62
+ if (requestedPermissions != null) {
63
+ for (perm in requestedPermissions) {
64
+ if (targetPermission == perm) {
65
+ manifest = true
66
+ break
67
+ }
68
+ }
69
+ }
70
+ } catch (e: Exception) {
71
+ Log.e(TAG, "checkPermissions manifest check failed", e)
72
+ }
73
+
74
+ val ret = JSObject()
75
+ ret.put("granted", granted)
76
+ ret.put("manifest", manifest)
77
+ call.resolve(ret)
78
+ }
79
+
80
+ @PluginMethod
81
+ fun requestPermissions(call: PluginCall) {
82
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
83
+ val intent = Intent(Settings.ACTION_MANAGE_UNKNOWN_APP_SOURCES)
84
+ intent.data = Uri.parse("package:" + context.packageName)
85
+ intent.flags = Intent.FLAG_ACTIVITY_NEW_TASK
86
+ context.startActivity(intent)
87
+ }
88
+ call.resolve()
89
+ }
90
+
91
+ @PluginMethod
92
+ fun getVersionInfo(call: PluginCall) {
93
+ try {
94
+ val pm = context.packageManager
95
+ val info = pm.getPackageInfo(context.packageName, 0)
96
+
97
+ val versionName = info.versionName
98
+ val versionCode = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
99
+ info.longVersionCode
100
+ } else {
101
+ @Suppress("DEPRECATION")
102
+ info.versionCode.toLong()
103
+ }
104
+
105
+ val ret = JSObject()
106
+ ret.put("versionName", versionName)
107
+ ret.put("versionCode", versionCode.toString())
108
+ call.resolve(ret)
109
+ } catch (e: Exception) {
110
+ Log.e(TAG, "getVersionInfo failed", e)
111
+ call.reject("getVersionInfo failed: " + e.message)
112
+ }
113
+ }
114
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@simplysm/capacitor-plugin-auto-update",
3
- "version": "14.0.11",
3
+ "version": "14.0.13",
4
4
  "description": "심플리즘 패키지 - Capacitor 자동 업데이트 플러그인",
5
5
  "author": "심플리즘",
6
6
  "license": "Apache-2.0",
@@ -19,11 +19,11 @@
19
19
  ],
20
20
  "dependencies": {
21
21
  "semver": "^7.7.4",
22
- "@simplysm/capacitor-plugin-file-system": "14.0.11",
23
- "@simplysm/core-browser": "14.0.11",
24
- "@simplysm/service-client": "14.0.11",
25
- "@simplysm/core-common": "14.0.11",
26
- "@simplysm/service-common": "14.0.11"
22
+ "@simplysm/capacitor-plugin-file-system": "14.0.13",
23
+ "@simplysm/core-browser": "14.0.13",
24
+ "@simplysm/service-client": "14.0.13",
25
+ "@simplysm/core-common": "14.0.13",
26
+ "@simplysm/service-common": "14.0.13"
27
27
  },
28
28
  "devDependencies": {
29
29
  "@capacitor/core": "^7.6.1",