diff --git a/README.md b/README.md
index d58171b..7edab2d 100644
--- a/README.md
+++ b/README.md
@@ -4,7 +4,7 @@


-最近更新 2020.12.26
+最近更新 2020.12.29
### How to use
@@ -22,13 +22,13 @@ allprojects {
```
dependencies {
//kotlin 版本
- implementation 'com.github.yechaoa.YUtils:yutilskt:3.1.4'
+ implementation 'com.github.yechaoa.YUtils:yutilskt:3.1.5'
//java 版本
- implementation 'com.github.yechaoa.YUtils:yutils:3.1.4'
+ implementation 'com.github.yechaoa.YUtils:yutils:3.1.5'
//kotlin && java 版本
- implementation 'com.github.yechaoa:YUtils:3.1.4'
+ implementation 'com.github.yechaoa:YUtils:3.1.5'
}
```
@@ -39,7 +39,8 @@ dependencies {
```
//初始化
YUtils.init(this);
-//设置打印开关(可选,默认false)
+
+//打印开关(可选,默认false不打印)
LogUtil.setIsLog(true);
```
@@ -75,6 +76,7 @@ LogUtil.setIsLog(true);
* void closeSoftKeyboard()
关闭软键盘
+* Boolean hasSim()
是否有sim卡 即设备是否可以拨打电话等
> ## 2.ToastUtil(任意线程,不重复显示,可取消).
@@ -224,6 +226,10 @@ like this
## 更新记录
+#### 3.1.5(2020-12-29)
+- 初始化校验
+- YUtils新增sim卡判断
+
#### 3.1.4(2020-12-26)
- SpUtil优化
diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml
index 57e7527..dac865d 100644
--- a/app/src/main/AndroidManifest.xml
+++ b/app/src/main/AndroidManifest.xml
@@ -5,7 +5,7 @@
-
+ android:text="Hello World!" />
+ android:text="存StringSet" />
+ android:text="读StringSet" />
+ android:text="showLoading" />
+ android:text="hideLoading" />
+ android:text="打印log" />
-
\ No newline at end of file
+
+
+
+
+
\ No newline at end of file
diff --git a/app/src/main/res/mipmap-xxhdpi/ic_logo.png b/app/src/main/res/mipmap-xxhdpi/ic_logo.png
new file mode 100644
index 0000000..a5ae03f
Binary files /dev/null and b/app/src/main/res/mipmap-xxhdpi/ic_logo.png differ
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index b77ea73..6c21464 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -1,5 +1,5 @@
- app
+ YUtils
"Material is the metaphor.\n\n"
diff --git a/yutils/src/main/java/com/yechaoa/yutils/YUtils.java b/yutils/src/main/java/com/yechaoa/yutils/YUtils.java
index cbdefbc..5905065 100644
--- a/yutils/src/main/java/com/yechaoa/yutils/YUtils.java
+++ b/yutils/src/main/java/com/yechaoa/yutils/YUtils.java
@@ -8,6 +8,7 @@
import android.content.Context;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
+import android.telephony.TelephonyManager;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.style.ForegroundColorSpan;
@@ -36,7 +37,7 @@ public class YUtils {
private static Toast toast;
private static ProgressDialog progressDialog;
- private static Application mApp;
+ private static Application mApp = null;
/**
* 使用init()即可
@@ -62,7 +63,11 @@ public static Application getApplication() {
}
public static Application getApp() {
- return mApp;
+ if (null == mApp) {
+ throw new NullPointerException("YUtils未在Application中初始化");
+ } else {
+ return mApp;
+ }
}
/**
@@ -267,4 +272,18 @@ public static void closeSoftKeyboard() {
inputManger.hideSoftInputFromWindow(ActivityUtil.getCurrentActivity().getWindow().getDecorView().getWindowToken(), 0);
}
+ /**
+ * 是否有sim卡 即设备是否可以拨打电话等
+ */
+ public static Boolean hasSim() {
+ TelephonyManager telephonyManager = (TelephonyManager) getApp().getSystemService(Context.TELEPHONY_SERVICE);
+ boolean result = true;
+ switch (telephonyManager.getSimState()) {
+ case TelephonyManager.SIM_STATE_ABSENT:
+ case TelephonyManager.SIM_STATE_UNKNOWN:
+ result = false;
+ break;
+ }
+ return result;
+ }
}
diff --git a/yutilskt/src/main/java/com/yechaoa/yutilskt/YUtils.kt b/yutilskt/src/main/java/com/yechaoa/yutilskt/YUtils.kt
index 3c4617d..a9f03e3 100644
--- a/yutilskt/src/main/java/com/yechaoa/yutilskt/YUtils.kt
+++ b/yutilskt/src/main/java/com/yechaoa/yutilskt/YUtils.kt
@@ -6,6 +6,7 @@ import android.content.ClipData
import android.content.ClipboardManager
import android.content.Context
import android.content.pm.PackageManager
+import android.telephony.TelephonyManager
import android.text.Spannable
import android.text.SpannableString
import android.text.style.ForegroundColorSpan
@@ -50,7 +51,11 @@ object YUtils {
}
fun getApp(): Application {
- return mApp
+ if (this::mApp.isInitialized) {
+ return mApp
+ } else {
+ throw UninitializedPropertyAccessException("YUtils未在Application中初始化")
+ }
}
/**
@@ -234,5 +239,16 @@ object YUtils {
inputManger.hideSoftInputFromWindow(ActivityUtil.currentActivity!!.window.decorView.windowToken, 0)
}
-
+ /**
+ * 是否有sim卡 即设备是否可以拨打电话等
+ */
+ fun hasSim(): Boolean {
+ val telephonyManager = getApp().getSystemService(Context.TELEPHONY_SERVICE) as TelephonyManager
+ var result = true
+ when (telephonyManager.simState) {
+ TelephonyManager.SIM_STATE_ABSENT -> result = false
+ TelephonyManager.SIM_STATE_UNKNOWN -> result = false
+ }
+ return result
+ }
}