WEB开发网
开发学院手机开发Android 开发 Android 模拟器中用 DDMS 监听位置变化 阅读

Android 模拟器中用 DDMS 监听位置变化

 2010-03-16 16:06:00 来源:WEB开发网   
核心提示:import android.location.Location;import android.location.LocationListener;import android.location.LocationManager;import android.location.Criteria;mLocationMana

import android.location.Location;

import android.location.LocationListener;

import android.location.LocationManager;

import android.location.Criteria;

mLocationManager = (LocationManager)getSystemService(Context.LOCATION_SERVICE);

mLocationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 2000, 10, mLocationListener);

// GPS位置更新事件

public final LocationListener

mLocationListener = new LocationListener()

{

@Override

public void onLocationChanged(Location location)

{

// TODO Auto-generated method stub

System.out.println("Location Changed");

processLocationUpdated( location );

}

@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

}

};

注意添加访问权限:

《uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" /》

《uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" /》

《uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" /》

Tags:Android 模拟器 中用

编辑录入:coldstar [复制链接] [打 印]
赞助商链接