3
context.sendOrderedBroadcast(intent, receiverPermission)
或context.sendBroadcast(intent, receiverPermission);
在我的應用程序 但我不知道通過receiverPermission參數的功能,以及如何在清單文件中設置 請任何身體幫我
我想告訴你,我的源代碼
public class LocationReceiver extends BroadcastReceiver {
public static final String BROADCAST_ACTION = "LOCATION_CHANGE";
@Override
public void onReceive(Context context, Intent intent) {
intent.setAction(BROADCAST_ACTION);
Bundle b = intent.getExtras();
Location loc = (Location)b.get(android.location.LocationManager.KEY_LOCATION_CHANGED);
Logger.debug("Loc:"+loc);
if(loc != null){
doBroadCast(context,intent,loc);
}
}
public void doBroadCast(final Context context,final Intent i1,final Location loc){
Handler h = new Handler();
h.post(new Runnable() {
@Override
public void run() {
// TODO Auto-generated method stub
Logger.debug("LocationReceiver->sendLocation update broadcast");
i1.putExtra("Latitude", loc.getLatitude());
i1.putExtra("Longitude", loc.getLongitude());
context.sendBroadcast(i1,null);
}
});
}
}
和活動我寫
@Override
protected void onResume() {
registerReceiver(broadcastReceiver, new IntentFilter(LocationReceiver.BROADCAST_ACTION));
}
private BroadcastReceiver broadcastReceiver = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
UpdateUI(intent);
}
};
private void UpdateUI(Intent i){
Double Latitude = i.getDoubleExtra("Latitude",0);
Double Longitude = i.getDoubleExtra("Longitude",0);
showMap(Latitude, Longitude);
}
現在我的問題是,當它sendbroadcast它infinitly執行了DoBroadcast()函數,請幫我走出來。