35

ユーザーが 3g またはデータ接続を有効/無効にできるように、モバイル ネットワーク設定画面を起動したいと考えています。アクティビティを開始するために使用する必要があるインテントを誰か教えてください。使った

Intent in = new Intent(android.provider.Settings.ACTION_NETWORK_OPERATOR_SETTINGS ) 

Intent in = new Intent(android.provider.Settings.ACTION_DATA_ROAMING_SETTINGS  ). 

しかし、これらは両方とも機能しませんでした。

4

6 に答える 6

42

2.3で修正されたと思われるバグがあったため、それらは機能しません。

https://review.source.android.com/#/c/22229/を参照

(NETWORK_OPERATOR_SETTINGSの場合)を使用してこれをバイパスできます

Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setClassName("com.android.phone", "com.android.phone.NetworkSetting");
startActivity(intent);

DATA_ROAMING_SETTINGSNetworkSettingSettingsに置き換えます

Error opening mobile network settings menuで説明されている別の同様の解決策があります。

アップデート

私は最近これをテストしましたが、この回避策は API レベル 15 までまだ必要であるようです。API レベル 16 以降、質問の意図は正しく機能しているようです。

于 2011-07-22T11:54:59.880 に答える
11
public class SettingsScreen
{

protected static void _showSettingScreen(String intentStr)
{
    try
    {
        Intent intent = new Intent(intentStr);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        Reference.getAppContext().startActivity(intent);
    }
    catch (Exception e) {Reference.showToast(e.toString(), true);}
}

public static void showSettingScreen()
{
    _showSettingScreen("android.settings.SETTINGS");
}

public static void showAPNScreen()
{
    _showSettingScreen("android.settings.APN_SETTINGS");
}

public static void showLocationScreen()
{
    _showSettingScreen("android.settings.LOCATION_SOURCE_SETTINGS");
}

public static void showSecurityScreen()
{
    _showSettingScreen("android.settings.SECURITY_SETTINGS");
}

public static void showWifiScreen()
{
    _showSettingScreen("android.settings.WIFI_SETTINGS");
}

public static void showBluetoothScreen()
{
    _showSettingScreen("android.settings.BLUETOOTH_SETTINGS");
}

public static void showDateScreen()
{
    _showSettingScreen("android.settings.DATE_SETTINGS");
}

public static void showSoundScreen()
{
    _showSettingScreen("android.settings.SOUND_SETTINGS");
}

public static void showDisplayScreen()
{
    _showSettingScreen("android.settings.DISPLAY_SETTINGS");
}

public static void showApplicationScreen()
{
    _showSettingScreen("android.settings.APPLICATION_SETTINGS");
}

public static void showNetworkSettingScreen()
{
    showDataRoamingScreen();
}

public static void showNetworkOperatorScreen()
{
    if(Reference.getSystemOptions().VERSION_SDK_INT > 15)
    {
        _showSettingScreen("android.settings.NETWORK_OPERATOR_SETTINGS");
    }
    else
    {
        Intent intent=new Intent(android.provider.Settings.ACTION_SETTINGS);
        intent.setClassName("com.android.phone", "com.android.phone.NetworkSetting");
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        Reference.getAppContext().startActivity(intent);
    }
}

public static void showDataRoamingScreen()
{
    if(Reference.getSystemOptions().VERSION_SDK_INT > 15)
    {
        _showSettingScreen("android.settings.DATA_ROAMING_SETTINGS");
    }
    else
    {
        Intent intent=new Intent(Settings.ACTION_DATA_ROAMING_SETTINGS);
        ComponentName cName = new ComponentName("com.android.phone","com.android.phone.Settings");
        intent.setComponent(cName);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        Reference.getAppContext().startActivity(intent);
    }
}

public static void showDataMobileScreen()
{
    if(Reference.getSystemOptions().VERSION_SDK_INT > 15)
    {
        Intent intent = new Intent(Settings.ACTION_WIRELESS_SETTINGS);//android.provider.Settings.ACTION_SETTINGS //Intent.ACTION_MAIN
        intent.setClassName("com.android.settings", "com.android.settings.Settings$DataUsageSummaryActivity");
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        Reference.getAppContext().startActivity(intent);
    }
    else
    {
        showDataRoamingScreen();
    }
}

public static void showNotificationScreen()
{
    _showSettingScreen("android.settings.NOTIFICATION_SETTINGS");
}

public static void showBatterySaverScreen()
{
    _showSettingScreen("android.settings.BATTERY_SAVER_SETTINGS");
}

public static void showNfcScreen()
{
    _showSettingScreen("android.settings.NFC_SETTINGS");
}

public static void showInternalStorageScreen()
{
    _showSettingScreen("android.settings.INTERNAL_STORAGE_SETTINGS");
}

public static void showDictionarySettingScreen()
{
    _showSettingScreen("android.settings.USER_DICTIONARY_SETTINGS");
}

public static void showManageApplicationsScreen()
{
    _showSettingScreen("android.settings.MANAGE_APPLICATIONS_SETTINGS");
}

public static void showManageAllApplicationsScreen()
{
    _showSettingScreen("android.settings.MANAGE_ALL_APPLICATIONS_SETTINGS");
}

public static void showMemoryCardScreen()
{
    _showSettingScreen("android.settings.MEMORY_CARD_SETTINGS");
}

public static void showAirPlaneScreen()
{
    if(Reference.getSystemOptions().VERSION_SDK_INT > 16)
    {
        if(Reference.getSystemOptions().BRAND.equalsIgnoreCase("Lenovo"))
        {
            showSettingScreen();
        }
        else
        {
            _showSettingScreen("android.settings.WIRELESS_SETTINGS");
        }
    }
    else
    {
        _showSettingScreen("android.settings.AIRPLANE_MODE_SETTINGS");
    }
}

public static void showWirelessScreen()
{
    _showSettingScreen("android.settings.WIRELESS_SETTINGS");
}

public static void showWifiScreenSafe()
{
    try
    {
        Intent intent = new Intent(Intent.ACTION_MAIN, null);
        intent.addCategory(Intent.CATEGORY_LAUNCHER);
        ComponentName cn = new ComponentName("com.android.settings", "com.android.settings.wifi.WifiSettings");
        intent.setComponent(cn);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        Reference.getAppContext().startActivity(intent);
    }
    catch (Exception e)
        {}
}
}
于 2016-11-28T12:19:53.437 に答える
5

次の 2 つの可能性があります。

全体的なネットワーク設定が表示され、そこからユーザーはモバイル ネットワークにアクセスできます。

startActivity(new Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS)); 

Zharf提案どおり:

モバイルネットワーク設定が表示され、そこからユーザーはネットワークを有効にできます

Intent intent = new Intent(Intent.ACTION_MAIN);
intent.setClassName("com.android.phone","com.android.phone.NetworkSetting");
startActivity(intent);
于 2016-01-21T07:16:33.660 に答える
4

私の場合 (android 9)、このインテントはモバイル データ設定に直接到達します。

val intent = Intent(Settings.ACTION_DATA_ROAMING_SETTINGS)
context.startActivity(intent)
于 2019-12-11T10:04:52.317 に答える