как управлять значками уведомлений?

Я хотел бы контролировать запуск приложения из панели уведомлений. Поэтому я хотел бы перехватить любое действие на любом значке на этой панели. код, приведенный ниже, дает пример того, как значок уведомления запускает приложение с ним.

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

Я хотел бы обнаружить все намерения и реализовать службу аутентификации, для которой требуется пароль перед запуском приложений из панели уведомлений.


person user2641131    schedule 05.09.2013    source источник


Ответы (1)


Итак, если я хорошо понял вопрос... почему бы не сделать Intent для отправки в какой-то раздел Login?

Как это:

 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));
}
person Stefano Munarini    schedule 05.09.2013
comment
это не то, что я ищу, я попытаюсь объяснить на примере. Код, который я вставил, представляет собой уведомление, созданное в моем приложении для запуска моего приложения в строке состояния, поэтому я могу распечатать диалоговое окно перед запуском моего приложения. Я хотел бы сделать что-то со всеми значками в строке состояния - person user2641131; 05.09.2013
comment
например Настройка доступна из строки состояния. Я хотел бы ограничить доступ к этому приложению. - person user2641131; 05.09.2013
comment
Хорошо, извините, я не получил ваш вопрос раньше. Итак, вы хотите, чтобы СИСТЕМНОЕ ПРИЛОЖЕНИЕ не было доступно из строки состояния? - person Stefano Munarini; 05.09.2013
comment
Я бы хотел, чтобы любое приложение, запускаемое из строки состояния, управлялось паролем. - person user2641131; 05.09.2013