如何通过代码打开手机的无线网络功能? [英] How to turn on wireless network feature of phone by code?
问题描述
如果我没有使用此功能,我无法获得纬度和经度。
当我启用设置>位置>使用无线网络(开启)时的功能
我可以获得纬度经度...
有没有其他方法可以解决这个问题?
任何打开功能的sammple代码
我可以打开GPS卫星...
I am not getting latitude and longitude without this feature from GPS.
when I turn on feature which is on Settings>location>Use Wireless Network(On)
I can get latitude longitude ...
Is there any other way to solve this?
Any sammple code to turn on feature
I can turn on GPS satellite by this...
Intent intent = new Intent("android.location.GPS_ENABLED_CHANGE");
intent.putExtra("enabled", true);
sendBroadcast(intent);
我的代码是为了得到纬度和经度...
My code is this to get latitude and longitude...
/**
* For Getting Gps latitude longitude
*/
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
// Getting the name of the provider that meets the
// criteria
provider = locationManager.getBestProvider(criteria,
false);
System.out.println(provider);
if (provider != null && !provider.equals("")) {
// Get the location from the given provider
Location location = locationManager
.getLastKnownLocation(provider);
locationManager.requestLocationUpdates(provider,
20000, 1,this);
System.out.println(location);
if (location != null) {
onLocationChanged(location);
System.out.println(latitude + longitude);
} else {
System.out.println("Location not retrived...");
}
@Override
public void onLocationChanged(Location location) {
// Getting reference to TextView tv_longitude
latitude = location.getLatitude();
longitude = location.getLongitude();
}
@Override
public void onProviderDisabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onProviderEnabled(String provider) {
// TODO Auto-generated method stub
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
// TODO Auto-generated method stub
}
推荐答案
你好Vivek,
这里有很好的文章[ ^ ]。基本上你需要以下权限
Hello Vivek,
There is good article on this here[^]. Basically you will need following permissions
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" xmlns:android="#unknown"></uses-permission>
<uses-permission android:name="android.permission.UPDATE_DEVICE_STATS" xmlns:android="#unknown"></uses-permission>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" xmlns:android="#unknown"></uses-permission>
<uses-permission android:name="android.permission.WAKE_LOCK" xmlns:android="#unknown"></uses-permission>
在清单中宣布此功能后,您的应用就可以访问Wi-Fi。然后,您可以使用以下代码打开Wi-Fi
Once this is declared in the manifest your app will be able to access the Wi-Fi. You can then use following code to turn on Wi-Fi
wifiManager = (WifiManager) this.getSystemService(Context.WIFI_SERVICE);
wifiManager.setWifiEnabled(true);
wifiManager.setWifiEnabled(false);
问候,
Regards,
这篇关于如何通过代码打开手机的无线网络功能?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!