[英]How to pass intent to settings app for wifi
i`ma very new in android development .我是安卓开发的新手。 currently I am facing a problem enabling wifi from my app .
目前我在从我的应用程序启用 wifi 时遇到问题。 If my app is not connected to the internet I want to pass a intent to the settings app to enable the wifi and return to my app .
如果我的应用程序未连接到互联网,我想将意图传递给设置应用程序以启用 wifi 并返回到我的应用程序。 how can I do that ?
我怎样才能做到这一点 ? can anyone plz show me the trick .
谁能告诉我诀窍。
Use this:用这个:
startActivity(new Intent(Settings.ACTION_WIRELESS_SETTINGS));
For the complete list of Settings: https://developer.android.com/reference/android/provider/Settings.html有关设置的完整列表: https : //developer.android.com/reference/android/provider/Settings.html
this is quite easy .这很容易。 here is the solution if you have any button to enable internet in your app , you must need to call startActivityForResutlt method in this way .
这是解决方案,如果您的应用程序中有任何启用互联网的按钮,您必须以这种方式调用 startActivityForResutlt 方法。
internetButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
startActivityForResult(new Intent(
Settings.ACTION_WIFI_SETTINGS), 0);
}
});
}
and the onActivityResult() method would be like this和 onActivityResult() 方法将是这样的
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 0) {
WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
if (!wifiManager.isWifiEnabled()) {
Toast.makeText(DuaCategoryActivity.this,
"something went wrong ", Toast.LENGTH_SHORT).show();
} else {
//write your code for any kind of network calling to fetch data
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.