how to open WifiDisplay Setting from another app?

早过忘川 提交于 2019-12-03 22:30:31
Hemanth

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.

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

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

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);
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!