Android Lollipop Lock Notifications

Scenario

I want to create a notification that redirects to a url when an action is clicked. The example below works great if the device is unlocked. I would like the same thing to happen in the lock screen notification (now available on lollipop). Currently, when I select an action from the lock screen, nothing happens.

Alternatively, I would like to hide the action button in the lock screen notification.

Example

I created a BroadcastReceiver that just redirects to google:

public class RedirectReceiver extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        String url = "http://www.google.com";

        Intent i = new Intent(Intent.ACTION_VIEW);
        i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        i.setData(Uri.parse(url));

        context.startActivity(i);
    }
}

      

I created a notification using the following:

Intent i = new Intent(this, RedirectReceiver.class);

Notification.Builder builder = new Notification.Builder(this)
        .setSmallIcon(R.drawable.ic_icon)
        .setContentTitle("Test")
        .setContentIntent(PendingIntent.getBroadcast(this, 1, i, PendingIntent.FLAG_UPDATE_CURRENT))
        .addAction(R.drawable.ic_icon, "Open Page", PendingIntent.getBroadcast(this, 1, i, PendingIntent.FLAG_UPDATE_CURRENT));

NotificationManager m = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
m.notify("test", 0, builder.build());

      

I hope someone can have an idea if possible.

+3


source to share





All Articles