2

我想从我的应用程序中打开 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;

它是设置偏好片段......那我该如何打开它???

4

4 回答 4

2

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

三星:"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"));
  }
}

请让我知道它是否可以更好地实施。

于 2014-03-01T10:12:24.963 回答
1

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

于 2013-12-16T07:36:41.653 回答
0

用这个

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));
} 

这可能会帮助你

于 2013-08-06T10:30:07.223 回答
0

利用

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);
    }
于 2013-08-06T10:37:12.197 回答