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

    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);
    }

    at activity side:

    [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();
    }
    }

Sign In or Register to comment.