安卓动态代码判断是否开启代理,是否有SIM卡
时间: 2024-05-14 09:19:25 浏览: 17
判断是否开启代理:
```
public static boolean isProxyEnabled(Context context) {
String proxyAddress = android.provider.Settings.System.getString(
context.getContentResolver(),
android.provider.Settings.System.HTTP_PROXY);
return (proxyAddress != null && !proxyAddress.equals(""));
}
```
判断是否有SIM卡:
```
public static boolean isSimCardAvailable(Context context) {
TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
return (tm.getSimState() == TelephonyManager.SIM_STATE_READY);
}
```
需要注意的是,这两个方法需要添加相应的权限,即`<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />`和`<uses-permission android:name="android.permission.READ_PHONE_STATE" />`。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![-](https://csdnimg.cn/download_wenku/file_type_lunwen.png)
![-](https://csdnimg.cn/download_wenku/file_type_lunwen.png)
![-](https://csdnimg.cn/download_wenku/file_type_lunwen.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)