【问题标题】:Displaying Desired Settings Screen on Android在 Android 上显示所需的设置屏幕
【发布时间】:2012-02-07 19:21:43
【问题描述】:

在我的应用程序中,某些任务需要某种网络连接(wifi 或蜂窝网络都可以)。在我的活动中,我有一个检查onResume()来检查网络状态,如果没有连接,我想显示网络设置屏幕:

private void showConnectionSettings() {
    Intent intent = new Intent(Settings.ACTION_WIRELESS_SETTINGS);
    ComponentName cn = new ComponentName( "com.android.phone", "com.android.phone.Settings" );

    intent.setComponent( cn );
    intent.setFlags( Intent.FLAG_ACTIVITY_NEW_TASK );

    this.getBaseContext().startActivity( intent );
}

然而,这给我带来了移动网络屏幕,当我想显示Wireless and Network Settings 屏幕时,用户可以选择他们的连接类型。

【问题讨论】:

标签: android android-intent android-activity


【解决方案1】:

老实说,如果他们没有覆盖范围,他们唯一的选择就是使用 wifi。

试试这个

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

【讨论】:

  • 这只是显示一个对话框“搜索”。这更多的是显示正确的设置屏幕。
【解决方案2】:
startActivity(new Intent(Settings.ACTION_WIRELESS_SETTINGS));

【讨论】:

    【解决方案3】:

    我知道这已经晚了,但可能会对某人有所帮助。实现这一目标的最佳方法是:

    • 用于显示一般连接设置,

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

    • 用于显示移动网络连接设置

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

    • 用于显示 Wifi 设置

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

    【讨论】:

      【解决方案4】:

      此代码可以很好地显示无线和网络设置。

      Intent intent = new Intent(Intent.ACTION_MAIN);
      intent.setComponent(new ComponentName("com.android.settings","com.android.settings.WirelessSettings"));
      intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
      startActivity(intent);
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2022-08-03
        • 1970-01-01
        • 2016-06-29
        • 2023-04-01
        • 1970-01-01
        • 1970-01-01
        • 2020-12-23
        • 2015-01-26
        相关资源
        最近更新 更多