0

I'm trying to catch a click action on a button of a custom notification. I want to avoid creating a class extending BroadcastReciever. To do this I am coding as follows inside my service class:

this.registerReceiver(new BroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            Log.v ("Myreceiver", "on click catch")
        }
    }, new IntentFilter("MyRemoteViewsBroadcast"));

PendingIntent pi = PendingIntent.getBroadcast(this, 0, new Intent("MyRemoteViewsBroadcast"), 0);
remoteviews.setOnClickPendingIntent(R.I'd. Button, pi);

But it doesn't work. Am I loosing something?

Edit: With "It doesn't work" I mean OnReceive() method is never called when I click on button. (Sorry for the incomplete question)

1 Answers1

0

I have just realize where is the problem!!!

The code works perfectly!!! I had wrote in my own code:

PendingIntent playPendingIntent = PendingIntent.**getService**( getApplicationContext(), NOTIFICATION_ID, new Intent("MyRemoteViewsBroadcast"), 0);

instead of:

PendingIntent playPendingIntent = PendingIntent.**getBroadcast**( getApplicationContext(), NOTIFICATION_ID, new Intent("MyRemoteViewsBroadcast"), 0);

Silly mistake. I need a rest! Sorry for the inconvenience.