Broadcast receiver not working when security permission is set

Hi,

I have following code to send data from service to activity
in service:
protected override void SendToWire(object data)
{
var intent = new Intent("intenta");
intent.PutExtra("extra", (string)data);
CoreService.SendOrderedBroadcast(intent, "permission_string");
//CoreService.SendOrderedBroadcast(intent, null);
}

and in activity
[IntentFilter(new string[]{"intenta"})]
// [BroadcastReceiver(Permission = "permission_string")]
private class NotificationReceiver : BroadcastReceiver
{
public override void OnReceive(Context context, Android.Content.Intent intent)
{
var command = intent.GetStringExtra("extra");
if (string.IsNullOrEmpty(command)) return;
dosomework(command);
InvokeAbortBroadcast();
}
}

the problem is in the service if I use CoreService.SendOrderedBroadcast(intent, null); then everything works fine, but if I use what it is now, then at the receiver side it will never be called regardless if I enable the [BroadcastReceiver(Permission = "permission_string")] or not.

any idea?

Thanks

Michael

Posts

  • MichaelLi.4104MichaelLi.4104 CAMember

    Reformatting for easier read,

    At service side
    <br /> protected override void SendToWire(object data)<br /> { <br /> var intent = new Intent("intenta"); <br /> intent.PutExtra("extra", (string)data);<br /> CoreService.SendOrderedBroadcast(intent, "permission_string");<br /> //CoreService.SendOrderedBroadcast(intent, null); <br /> }

    at activity side:
    <br /> [IntentFilter(new string[]{"intenta"})] <br /> // [BroadcastReceiver(Permission = "permission_string")] <br /> private class NotificationReceiver : BroadcastReceiver <br /> { <br /> public override void OnReceive(Context context, Android.Content.Intent intent)<br /> { <br /> var command = intent.GetStringExtra("extra"); <br /> if (string.IsNullOrEmpty(command)) return; <br /> dosomework(command); <br /> InvokeAbortBroadcast(); <br /> } <br /> }

Sign In or Register to comment.