2017-04-25 11 views

答えて

0

が見つかりました。私は、私は次のように私はgetDataNetworkTypeを使用することができ、データネットワークが必要な場合は例えばTelephonyManagerメソッドを呼び出すためにアンドロイドリフレクションを使用しています

getNetworkTypeReflection(telephonyManager, "getDataNetworkType", slot, false);

private static String getNetworkTypeReflection(final TelephonyManager telephony, final String predictedMethodName, final int slotID, final boolean isPrivate) { 

     String result = null; 

     try { 

      final Class<?> telephonyClass = Class.forName(telephony.getClass().getName()); 

      final Class<?>[] parameter = new Class[1]; 
      parameter[0] = int.class; 
      final Method getSubtecnology; 
      if (slotID != -1) { 
       if (isPrivate) { 
        getSubtecnology = telephonyClass.getDeclaredMethod(predictedMethodName, parameter); 
       } else { 
        getSubtecnology = telephonyClass.getMethod(predictedMethodName, parameter); 
       } 
      } else { 
       if (isPrivate) { 
        getSubtecnology = telephonyClass.getDeclaredMethod(predictedMethodName); 
       } else { 
        getSubtecnology = telephonyClass.getMethod(predictedMethodName); 
       } 
      } 

      final Object obPhone; 
      final Object[] obParameter = new Object[1]; 
      obParameter[0] = slotID; 
      if (getSubtecnology != null) { 
       if (slotID != -1) { 
        obPhone = getSubtecnology.invoke(telephony, obParameter); 
       } else { 
        obPhone = getSubtecnology.invoke(telephony); 
       } 

       if (obPhone != null) { 
        result = obPhone.toString(); 

       } 
      } 
     } catch (Exception e) { 
      //e.printStackTrace(); 
      return null; 
     } 
     return result; 
    } 

問題は、このオプションは唯一のAndroid 5.1上で動作することである(API22 )しかし、Android 7.0(API24)が必要な他のデバイスのデバイスでのみ使用できます。 誰かが他のオプションを持っている場合は、歓迎します。

0

Android Android 5.1(API22)の前には、このためのAPIはありません。しかし、次にSubscriptionManagerとそのgetActiveSubscriptionInfoList()

+0

あなたの答えをありがとうが、SubscriptionManagerの問題は各シムのネットワークを返さないか、本当に返すのかどうかわからない – efr