how to control notification icons?

213 Views Asked by At

I would like to control Launching Application from notification bar. So i would like to intercept any action in any icon in this bar. the code given below give an example of how a notification icon start the application that much with it.

 private void handleCommand(Intent intent){
        // In this sample, we'll use the same text for the ticker and the expanded notification
        CharSequence text = getText(R.string.service_running);

        // Set the icon, scrolling text and timestamp
        Notification notification = new Notification(R.drawable.statusbar_icon, text,
                System.currentTimeMillis());

        // The PendingIntent to launch our activity if the user selects this notification
        PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
                new Intent(this, AppLockerActivity.class), 0);

        // Set the info for the views that show in the notification panel.
        notification.setLatestEventInfo(this, text,
                       text, contentIntent);

        startForegroundCompat(R.string.service_running, notification);

        startMonitorThread((ActivityManager)this.getSystemService(Context.ACTIVITY_SERVICE));
    }

I would like to detect all the intent and implement a service of authentication that need a password befor running applications from the notification bar.

1

There are 1 best solutions below

4
On

Ok so, if i understood well the question...why don't make Intent to send to some kind of Login section?

Like this:

 private void handleCommand(Intent intent){
    // In this sample, we'll use the same text for the ticker and the expanded notification
    CharSequence text = getText(R.string.service_running);

    // Set the icon, scrolling text and timestamp
    Notification notification = new Notification(R.drawable.statusbar_icon, text,
            System.currentTimeMillis());


    //create an intent and add some Extra or whatever else you need
    Intent intent = new Intent(this, YOUR_LOGIN_CLASS.class);
    intent.addExtra("WHATEVER TO RETRIEVE TO SEE IF COME FROM NOTIFICATION",whatever);

    // The PendingIntent to launch our activity if the user selects this notification
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
            intent, 0);

    // Set the info for the views that show in the notification panel.
    notification.setLatestEventInfo(this, text,
                   text, contentIntent);

    startForegroundCompat(R.string.service_running, notification);

    startMonitorThread((ActivityManager)this.getSystemService(Context.ACTIVITY_SERVICE));
}