android上通过WI-FI获取位置的问题
我有麻烦了。我在HTC上找不到位置 这是我的舱单android上通过WI-FI获取位置的问题,android,geolocation,android-4.0-ice-cream-sandwich,Android,Geolocation,Android 4.0 Ice Cream Sandwich,我有麻烦了。我在HTC上找不到位置 这是我的舱单 <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.locationfinder" android:versionCode="1" android:versionName="1.0" > <uses-sdk android:minSdkVersion="8" android:targe
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.locationfinder"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_LOCATION"/>
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
}
如果我选择
LocationManager.GPS\u PROVIDER
而不是LocationManager.NETWORK\u PROVIDER
并且GPS处于禁用状态,则当前会使用“GPS禁用”来制作toast。但是,如果我使用LocationManager.NETWORK\u PROVIDER
无论WiFi状态如何,都不会发生任何事情。你检查过这个吗:我认为NETWORK\u PROVIDER会同时尝试WiFi和你的手机提供商,所以即使WiFi关闭,它也不会抱怨……为什么你要删除我在你的问题中修复的格式?我的英语不好这是我在这个网站上的第一个问题,我通常用谷歌来回答我的问题,这就是为什么我的行为可能很愚蠢我看到了所有的链接,但我不明白为什么它不起作用。在SGS3上,其工作电流为
public class MainActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
/* Use the LocationManager class to obtain GPS locations */
LocationManager mlocManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);
LocationListener mlocListener = new MyLocationListener();
mlocManager.requestLocationUpdates( LocationManager.NETWORK_PROVIDER, 0, 0, mlocListener);
}
/* Class My Location Listener */
public class MyLocationListener implements LocationListener
{
@Override
public void onLocationChanged(Location loc)
{
loc.getLatitude();
loc.getLongitude();
String Text = "My current location is: " +
"Latitude = " + loc.getLatitude() +
"Longitude = " + loc.getLongitude();
Toast.makeText( getApplicationContext(), Text, Toast.LENGTH_SHORT).show();
}
@Override
public void onProviderDisabled(String provider)
{
Toast.makeText( getApplicationContext(), "WIFI Disabled", Toast.LENGTH_SHORT ).show();
}
@Override
public void onProviderEnabled(String provider)
{
Toast.makeText( getApplicationContext(), "WIFI Enabled", Toast.LENGTH_SHORT).show();
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras)
{
Toast.makeText( getApplicationContext(), "snth", Toast.LENGTH_SHORT).show();
}
}/* End of Class MyLocationListener */