File tree Expand file tree Collapse file tree 3 files changed +71
-2
lines changed
app/src/main/java/ch/lock/mobile/android/deviceinfo Expand file tree Collapse file tree 3 files changed +71
-2
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,9 @@ object UtilsModule {
13
13
get()
14
14
)
15
15
}
16
+ single {
17
+ FormatUtils ()
18
+ }
16
19
single {
17
20
PermissionUtils ()
18
21
}
@@ -23,6 +26,7 @@ object UtilsModule {
23
26
} bind ResourceProvider ::class
24
27
single {
25
28
SimUtils (
29
+ get(),
26
30
get()
27
31
)
28
32
}
Original file line number Diff line number Diff line change
1
+ package ch.lock.mobile.android.deviceinfo.utils
2
+
3
+ import java.util.regex.Pattern
4
+
5
+ open class FormatUtils {
6
+
7
+ companion object {
8
+ const val TAG : String = " FormatUtils"
9
+ }
10
+
11
+ /* *
12
+ * 국제 번호를 지역 번호 형태로 format
13
+ */
14
+ open fun toLocalPhoneNumber (
15
+ internationalNumber : String? ,
16
+ includeHyphen : Boolean = false
17
+ ): String {
18
+ if (internationalNumber.isNullOrEmpty()) return " "
19
+
20
+ var toLocalPhoneNumber: String = Pattern .compile(" (^[+]82)|(^82)" )
21
+ .matcher(internationalNumber)
22
+ .replaceAll(" 0" )
23
+
24
+ try {
25
+ if (includeHyphen) {
26
+ toLocalPhoneNumber = when (toLocalPhoneNumber.length) {
27
+ 8 -> {
28
+ toLocalPhoneNumber.replaceFirst(" ^([0-9]{4})([0-9]{4})$" .toRegex(), " $1-$2" )
29
+ }
30
+ 12 -> {
31
+ toLocalPhoneNumber.replaceFirst(
32
+ " (^[0-9]{4})([0-9]{4})([0-9]{4})$" .toRegex(),
33
+ " $1-$2-$3"
34
+ )
35
+ }
36
+ else -> {
37
+ toLocalPhoneNumber.replaceFirst(
38
+ " (^02|[0-9]{3})([0-9]{3,4})([0-9]{4})$" .toRegex(),
39
+ " $1-$2-$3"
40
+ )
41
+ }
42
+ }
43
+ }
44
+ return toLocalPhoneNumber
45
+ } catch (e: Exception ) {
46
+ return toLocalPhoneNumber
47
+ }
48
+ }
49
+
50
+ }
Original file line number Diff line number Diff line change @@ -9,7 +9,8 @@ import androidx.annotation.RequiresApi
9
9
10
10
@SuppressLint(" MissingPermission" , " HardwareIds" )
11
11
open class SimUtils (
12
- private val applicationContext : Context
12
+ private val applicationContext : Context ,
13
+ private val formatUtils : FormatUtils
13
14
) {
14
15
15
16
companion object {
@@ -31,7 +32,7 @@ open class SimUtils(
31
32
get() = try {
32
33
when {
33
34
Build .VERSION .SDK_INT >= Build .VERSION_CODES .LOLLIPOP_MR1 ->
34
- subscriptionManager.activeSubscriptionInfoList?.firstOrNull()?.iccId ? : " 유심이 장착되어 있지 않습니다. "
35
+ subscriptionManager.activeSubscriptionInfoList?.firstOrNull()?.iccId ? : " "
35
36
else -> telephonyManager.simSerialNumber ? : " "
36
37
}
37
38
} catch (e: Exception ) {
@@ -49,9 +50,23 @@ open class SimUtils(
49
50
}
50
51
51
52
/* *
53
+ * 지역 번호
54
+ *
52
55
* @return 디바이스 전화번호
53
56
*/
54
57
open val phoneNumber: String
58
+ get() = try {
59
+ formatUtils.toLocalPhoneNumber(globalPhoneNumber)
60
+ } catch (e: Exception ) {
61
+ " "
62
+ }
63
+
64
+ /* *
65
+ * 국제 번호
66
+ *
67
+ * @return 디바이스 전화번호
68
+ */
69
+ open val globalPhoneNumber: String
55
70
get() = try {
56
71
telephonyManager.line1Number ? : " "
57
72
} catch (e: Exception ) {
You can’t perform that action at this time.
0 commit comments