android - 如何从另一个应用程序打开WifiDisplay设置?

标签 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>

问题是我知道它是一个 fragment 类,并且我知道它的包名称是 com.android.settings.wfd,但我仍然不知道如何打开它,特别是我不知道如何处理 Activity 名称像这样

Settings$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;

它正在设置首选项 fragment ...那么我该如何打开它???

最佳答案

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

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

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

关于android - 如何从另一个应用程序打开WifiDisplay设置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18077556/

相关文章:

android - 多个 Android 项目具有通用库项目?

java - 解决错误::撤销权限android.permission.CALL_PHONE

java - 无法在 Android Studio 上将可绘制的 vector 图像附加到电子邮件

具有 fragment 的 Activity 与具有 fragment 的另一个 Activity 之间的 Android 共享元素转换

android - 如何在列表中添加新项目时更新 RecyclerView 适配器数据

android - 如何在 TextView 中显示非常大的文本(几兆)?

Android webView 不显示所有内容

android - 基于单一 Activity fragment 的应用程序和后退按钮

android - 是否可以以编程方式设置 drawableLeft 可见性

android - 共享时 "FLAG_ACTIVITY_CLEAR_WHEN_TASK_RESET"的作用是什么?