2015-12-03 5 views
10

私はモバイルデータを設定しようとしました。しかし、ちょうどSIM 1のために働いた。電話機のインターネット設定ダイアログを起動するにはどうすればよいですか?

public static void setMobileData(Context context, boolean isEnabled) throws NoSuchFieldException, ClassNotFoundException, IllegalAccessException, NoSuchMethodException, InvocationTargetException { 

    ConnectivityManager conman = (ConnectivityManager) context.getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE); 
    @SuppressWarnings("rawtypes") 
    final Class conmanClass = Class.forName(conman.getClass().getName()); 
    final Field iConnectivityManagerField = conmanClass.getDeclaredField("mService"); 
    iConnectivityManagerField.setAccessible(true); 
    final Object iConnectivityManager = iConnectivityManagerField.get(conman); 
    final Class iConnectivityManagerClass = Class.forName(iConnectivityManager.getClass().getName()); 

    Class[] cArg = new Class[2]; 
    cArg[0] = String.class; 
    cArg[1] = Boolean.TYPE; 
    Method setMobileDataEnabledMethod; 

    setMobileDataEnabledMethod = iConnectivityManagerClass.getDeclaredMethod("setMobileDataEnabled", cArg); 

    Object[] pArg = new Object[2]; 
    pArg[0] = context.getPackageName(); 
    pArg[1] = isEnabled; 
    setMobileDataEnabledMethod.setAccessible(true); 
    setMobileDataEnabledMethod.invoke(iConnectivityManager, pArg); 
} 

public static void setMobileData2(Context context, boolean isEnabled) throws NoSuchMethodException, ClassNotFoundException, IllegalAccessException, NoSuchFieldException, InvocationTargetException { 
    final ConnectivityManager conman = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); 
    final Class conmanClass = Class.forName(conman.getClass().getName()); 
    final Field iConnectivityManagerField = conmanClass.getDeclaredField("mService"); 
    iConnectivityManagerField.setAccessible(true); 
    final Object iConnectivityManager = iConnectivityManagerField.get(conman); 
    final Class iConnectivityManagerClass = Class.forName(iConnectivityManager.getClass().getName()); 
    final Method setMobileDataEnabledMethod = iConnectivityManagerClass.getDeclaredMethod("setMobileDataEnabled", Boolean.TYPE); 
    setMobileDataEnabledMethod.setAccessible(true); 

    setMobileDataEnabledMethod.invoke(iConnectivityManager, isEnabled); 
} 

public static boolean setMobileData3(Context context, boolean isEnable) { 
    boolean mobileDataAllowed = Settings.Secure.putInt(context.getContentResolver(), "mobile_data", isEnable?1:0); 
    return mobileDataAllowed; 
} 

しかし、今、私はちょうどそのデフォルトモバイルの選択]ダイアログを起動したいです。あなたが持っている場合は、そのダイアログを起動するための任意のアイデアが私に教えてください..事前に感謝します。

+1

「データ用にSIMを選択」ダイアログを起動するようお願いしていますか? – ozbek

+1

はい正確に@ozbek – shobhan

+1

btw、アンドロイドのバージョンとこれを実現するデバイスはどちらですか? API16の – 7383

答えて

3

マルチSIMサポートは、アンドロイドロリポップ5.1以降でのみ追加されています。それ以前には、異なる携帯電話メーカーは、マルチSIMとそれぞれの設定をサポートする独自のカスタム実装を持っています。したがって、一般的な解決策を目標としている場合、達成することはできません。 5.1でも、この特定の設定を起動する直接の意図はありませんが、ハッキングを使用すると、メーカーはGoogleソリューションのみを使用する必要があります。それ以外の場合は動作しません。

+0

誰でも私の答えをdownvote誰かが同じ理由について言及してください。 – 7383

3

このような設定を行う必要があります。

startActivityForResult(new Intent(android.provider.Settings.ACTION_DATA_ROAMING_SETTINGS), 0); 

「注意」 ありWIFIの設定もあり、それは非常にあなたが欲しい.Exploreより。この

android.provider.Settings.ACTION_WIFI_SETTINGS 
+2

@Arslanの回答に感謝します。その意図は、「ネットワーク設定」を起動するために使用されます。私が望むのは、SIMU、SIM2、またはOFFの間でモバイルデータを選択するためのpopUpを直接起動することです。 – shobhan

+0

このソリューションでは、デュアルシム設定ダイアログは決して来ません。 –

+0

ネットワーク設定はデータ選択のための二重simダイアログとは異なります – 7383

1

ように私は自分のアプリケーションthriughインターネットの設定を開こうとしましたが、それは唯一のデフォルトシムすなわちシム1.Youそれはインターネットを開き、デフォルトの機能であるが意図を使用して設定画面に上のユーザーをリダイレクトする必要が

意図インテント=新しいインテント(Settings.ACTION_WIFI_SETTINGS); startActivity(インテント);

+0

データ選択のためのWifi設定とデュアルsimダイアログとは異なります – 7383

関連する問題