如何从其他应用打开WifiDisplay设置?

时间:2013-08-06 10:25:45

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

我想从我的应用程序中打开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 ....非常感谢

问题是它的设置.WIFI_DISPLAY_SETTINGS但不是ACTION_WIFI_SETTINGS,所以eclipse无法编译

addional:

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 个答案:

答案 0 :(得分:2)

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

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

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

请告诉我是否可以更好地实施。

答案 1 :(得分:1)

startActivity(new Intent(“android.settings.WIFI_DISPLAY_SETTINGS”));

答案 2 :(得分: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));
} 

这可能对您有所帮助

答案 3 :(得分: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);
    }