我的应用程序刚刚安装完毕,
广播接收器不起作用。
在我的活动中,我在onCreate中进行了此设置..
mIntentFilter = new IntentFilter();
mIntentFilter.addAction(LocationService.MY_ACTION);
registerReceiver(mReceiver, mIntentFilter);
servIntent = new Intent(this, LocationService.class);
startService(servIntent);
这是同一活动中的我的广播接收器。
private BroadcastReceiver mReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(LocationService.MY_ACTION)) {
lat = Double.parseDouble(intent.getStringExtra("lat"));
lng = Double.parseDouble(intent.getStringExtra("long"));
Log.e("MY", "" + intent.getStringExtra("lat"));
Log.e("MY", "" + intent.getStringExtra("long"));
}
}
};
对于我的服务,
我在LocatioOnChanged
@Override
public void onLocationChanged(Location location) {
Log.e("LAT",""+ location.getLatitude());
Log.e("LONG", ""+location.getLongitude());
Intent intent = new Intent();
intent.setAction(MY_ACTION);
intent.putExtra("lat", String.valueOf(location.getLatitude()));
intent.putExtra("long", String.valueOf(location.getLongitude()));
sendBroadcast(intent);
}
我错过了什么吗?