[英]how to send Broadcast to BroadcastReceiver when location of device changes, in Android
In my android application, I want to sendBroadcast
to BroadcastReceiver
when the location of the device changes, even when my application is not running.在我的 android 应用程序中,即使我的应用程序没有运行,我也想在设备位置发生变化时将
sendBroadcast
发送到BroadcastReceiver
。 I am new to android, please tell how can I do that?我是安卓新手,请告诉我该怎么做?
Try this尝试这个
LocationManager manager= (LocationManager)getSystemService(Context.LOCATION_SERVICE);
manager.requestLocationUpdates("gps", 10, 10, new LocationListener() {
@Override
public void onLocationChanged(Location location) {
sendBroadcast(rec);
}
@Override
public void onStatusChanged(String provider, int status, Bundle extras) {
}
@Override
public void onProviderEnabled(String provider) {
}
@Override
public void onProviderDisabled(String provider) {
}
});
In order to broadcast in background you have to make use of AsyncTask or Service为了在后台广播,您必须使用 AsyncTask 或 Service
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.