在Jelly Bean(Android 4.2)中获取双SIM卡网络信息的问题

时间:2016-12-13 10:23:00

标签: android xamarin.android android-4.2-jelly-bean

我是Android开发的新手。我正在尝试创建一个需要显示网络信息的应用程序。它的目的是为我的Android 6.0设备获取<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.pro</groupId> <artifactId>Test1</artifactId> <packaging>war</packaging> <version>0.0.1-SNAPSHOT</version> <name>Test1 Maven Webapp</name> <url>http://maven.apache.org</url> <properties> <spring.version>4.0.1.RELEASE</spring.version> </properties> <dependencies> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <version>${spring.version}</version> </dependency> <dependency> <groupId>javax.servlet</groupId> <artifactId>javax.servlet-api</artifactId> <version>3.1.0</version> <scope>provided</scope> </dependency> <!-- https://mvnrepository.com/artifact/commons-logging/commons-logging --> <dependency> <groupId>commons-logging</groupId> <artifactId>commons-logging</artifactId> <version>1.1.1</version> </dependency> <!-- https://mvnrepository.com/artifact/xdoclet/xdoclet --> <dependency> <groupId>xdoclet</groupId> <artifactId>xdoclet</artifactId> <version>1.2.3</version> </dependency> <!-- https://mvnrepository.com/artifact/xjavadoc/xjavadoc --> <dependency> <groupId>xjavadoc</groupId> <artifactId>xjavadoc</artifactId> <version>1.1</version> </dependency> <!-- https://mvnrepository.com/artifact/org.aspectj/aspectjtools --> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjtools</artifactId> <version>1.8.9</version> </dependency> <!-- https://mvnrepository.com/artifact/org.aspectj/aspectjrt --> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjrt</artifactId> <version>1.8.9</version> </dependency> <!-- https://mvnrepository.com/artifact/org.aspectj/aspectjweaver --> <dependency> <groupId>org.aspectj</groupId> <artifactId>aspectjweaver</artifactId> <version>1.8.9</version> </dependency> <!-- https://mvnrepository.com/artifact/aopalliance/aopalliance --> <dependency> <groupId>aopalliance</groupId> <artifactId>aopalliance</artifactId> <version>1.0</version> </dependency> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-aop</artifactId> <version>4.0.1.RELEASE</version> </dependency> <!-- https://mvnrepository.com/artifact/org.springframework/spring-jdbc --> <dependency> <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> <version>4.0.1.RELEASE</version> </dependency> </dependencies> <build> <finalName>Test1</finalName> </build> </project> 信息,但我无法使用Jelly Bean(Android 4.2)获得双SIM卡网络信息。

dual sim network

解决这个问题的方法是什么?

1 个答案:

答案 0 :(得分:0)

不知道如何使其与Android 6.0设备一起使用,我使用Android 6.0,4.4和4.2模拟器来测试您的代码,所有内容都因错误而崩溃:

  

Java.Lang.NoSuchMethodException:SimOperatorName [int]

代码行中的

Java.Lang.Reflect.Method getSimID = telephonyClass.GetMethod("SimOperatorName", parameter);

只是查看了您的代码,我假设您想要获取SIM卡提供商的MCC + MNC(移动国家/地区代码+移动网络代码),然后您可以像这样编写代码:

TelephonyManager telemamanger = (TelephonyManager)GetSystemService(Context.TelephonyService);
var simoperator = telemamanger.SimOperator;

还有许多其他属性可能对您的案例有用,例如:

var simoperatorName = telemamanger.SimOperatorName;
var simserialNumber = telemamanger.SimSerialNumber;
var netoperator = telemamanger.NetworkOperator;
var netoperatorName = telemamanger.NetworkOperatorName;
var nettype = telemamanger.NetworkType;

您可以在TelephonyManager Class中找到它们以及其他一些属性,方法和字段。