2

I want to open Android4.2 setting WifiDisplaySettingsActivity from my app.

I tried

        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) {

        }

and

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

but none of them could work. I went to the AndroidManifest.xml to see code

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

the question is I know it's a fragment class and I know it's package name is com.android.settings.wfd, but I still don't know how to open it, especially I don't know how to handle activity name like this

Settings$WifiDisplaySettingsActivity

Can some one give me advices???plz....thank you very much

the problem is it's settings.WIFI_DISPLAY_SETTINGS but not ACTION_WIFI_SETTINGS, so the eclipse can't compile

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;

it's Setting Preference Fragment ... so how do I open it???

4 Answers 4

2

Wireless Display Settings activity can be called through the Intent "android.settings.WIFI_DISPLAY_SETTINGS". Some OEMs use other intents

Samsung: "com.samsung.wfd.LAUNCH_WFD_PICKER_DLG"

HTC: "com.htc.wifidisplay.CONFIGURE_MODE_NORMAL"

so, not guaranteed to work.

I dealt with the same issue and ended up with the following code.

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

Please let me know if it can be better implemented.

2
1

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

0

Use this

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

This may help you

2
  • ???, I mean I just want to start the Android setting app, but not connect to wifi.
    – Ashton
    Aug 6, 2013 at 10:34
  • I don't know what you mean.
    – Ashton
    Aug 6, 2013 at 10:34
0

Use

startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS));

Or

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);
    }
2
  • I tried, but nope not working..It gets to the Wi-Fi setting page, but not Wi-Display page
    – Ashton
    Aug 6, 2013 at 10:37
  • thanks men...but the problem is it's settings.WIFI_DISPLAY_SETTINGS but not ACTION_WIFI_SETTINGS, so the eclipse can't compile
    – Ashton
    Aug 6, 2013 at 10:42

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.