【问题标题】:how to open WifiDisplay Setting from another app?如何从另一个应用程序打开 WifiDisplay 设置?
【发布时间】:2013-08-06 10:25:44
【问题描述】:

我想从我的应用打开Android4.2设置WifiDisplaySettingsActivity。

我试过了

        Intent i;
        PackageManager manager = getActivity().getPackageManager();
        try {
            i = manager.getLaunchIntentForPackage("com.android.settings.wfd");
            if (i == null)
                throw new PackageManager.NameNotFoundException();
            i.addCategory(Intent.ACTION_MAIN);
            startActivity(i);
        } catch (PackageManager.NameNotFoundException e) {

        }

    final Intent intent = new Intent(Intent.ACTION_MAIN, null);
    intent.addCategory(Intent.CATEGORY_LAUNCHER);
    final ComponentName cn = new ComponentName("com.android.settings.wfd","com.android.settings.wfd.WifiDisplaySettings");
    intent.setComponent(cn);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    startActivity(intent);

但没有一个可以工作。 我去AndroidManifest.xml看代码

        <activity android:name="Settings$WifiDisplaySettingsActivity"
            android:label="@string/wifi_display_settings_title"
            android:taskAffinity=""
            android:excludeFromRecents="true">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <action android:name="android.settings.WIFI_DISPLAY_SETTINGS" />
            <category android:name="android.intent.category.DEFAULT" />
        </intent-filter>
        <meta-data android:name="com.android.settings.FRAGMENT_CLASS"
            android:value="com.android.settings.wfd.WifiDisplaySettings" />
    </activity>

问题是我知道它是一个片段类,我知道它的包名是 com.android.settings.wfd,但我仍然不知道如何打开它,尤其是我不知道如何处理活动名称像这样

设置$WifiDisplaySettingsActivity

谁能给我 建议???plz....非常感谢您

问题是settings.WIFI_DISPLAY_SETTINGS而不是ACTION_WIFI_SETTINGS,所以eclipse无法编译

补充:

public final class WifiDisplaySettings extends SettingsPreferenceFragment implements PersistentGroupInfoListener {
private static final String TAG = "WifiDisplaySettings";

private static final int MENU_ID_SCAN = Menu.FIRST;
private static final int MENU_ID_CREATE_GROUP = Menu.FIRST + 1;
private static final int MENU_ID_REMOVE_GROUP = Menu.FIRST + 2;

这是设置偏好片段...那我怎么打开它???

【问题讨论】:

    标签: android android-intent android-fragments android-fragmentactivity


    【解决方案1】:

    可以通过 Intent "android.settings.WIFI_DISPLAY_SETTINGS". 调用无线显示设置活动 一些 OEM 使用其他意图

    三星:"com.samsung.wfd.LAUNCH_WFD_PICKER_DLG"

    宏达电:"com.htc.wifidisplay.CONFIGURE_MODE_NORMAL"

    所以,不保证工作。

    我处理了同样的问题,最后得到了以下代码。

    try {
      Log.d("TAG", "open WiFi display settings in HTC");
      godController.getActivity().startActivity(new 
                 Intent("com.htc.wifidisplay.CONFIGURE_MODE_NORMAL"));
    } catch (Exception e) {
      try {
        Log.d("TAG", "open WiFi display settings in Samsung");
        godController.getActivity().startActivity(new 
                  Intent("com.samsung.wfd.LAUNCH_WFD_PICKER_DLG"));
      } catch (Exception e2) {
        Log.d("TAG", "open WiFi display settings in stock Android");
        godController.getActivity().startActivity(new 
                   Intent("android.settings.WIFI_DISPLAY_SETTINGS"));
      }
    }
    

    如果可以更好地实施,请告诉我。

    【讨论】:

    【解决方案2】:

    startActivity(new Intent("android.settings.WIFI_DISPLAY_SETTINGS"));

    【讨论】:

      【解决方案3】:

      使用这个

      ConnectivityManager manager = (ConnectivityManager) 
              getSystemService(MainActivity.CONNECTIVITY_SERVICE);
      /*
       * 3G confirm
       */
      Boolean is3g = manager.getNetworkInfo(
              ConnectivityManager.TYPE_MOBILE).isConnectedOrConnecting();
      /*
       * wifi confirm
       */
      Boolean isWifi = manager.getNetworkInfo(
              ConnectivityManager.TYPE_WIFI).isConnectedOrConnecting();
      if (is3g) {
          textView.setText("3G");
      } else if (isWifi) {
          textView.setText("wifi");
      } else {
          textView.setText("nothing");
          // Activity transfer to wifi settings
          startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS));
      } 
      

      这可能对你有帮助

      【讨论】:

      • ???,我的意思是我只想启动安卓设置应用,但不连接wifi。
      • 我不明白你的意思。
      【解决方案4】:

      使用

      startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS));
      

      或者

      public void openWifiSettings(){
      
              final Intent intent = new Intent(Intent.ACTION_MAIN, null);
              intent.addCategory(Intent.CATEGORY_LAUNCHER);
              final ComponentName cn = new ComponentName("com.android.settings", "com.android.settings.wifi.WifiSettings");
              intent.setComponent(cn);
              intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
              startActivity( intent);
          }
      

      【讨论】:

      • 我试过了,但不行。它进入了 Wi-Fi 设置页面,但没有进入 Wi-Display 页面
      • 谢谢各位...但问题是它的设置。WIFI_DISPLAY_SETTINGS 但不是 ACTION_WIFI_SETTINGS,所以 eclipse 无法编译
      猜你喜欢
      • 2011-08-05
      • 2016-12-29
      • 2020-12-15
      • 2018-04-27
      • 2018-04-28
      • 1970-01-01
      • 1970-01-01
      • 2014-01-17
      相关资源
      最近更新 更多