0

我想从通知栏控制启动应用程序。所以我想拦截此栏中任何图标中的任何操作。下面给出的代码给出了一个通知图标如何启动应用程序的示例。

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

我想检测所有意图并实现需要密码的身份验证服务,然后才能从通知栏运行应用程序。

4

1 回答 1

0

好的,如果我很好地理解了这个问题......为什么不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));
}
于 2013-09-05T10:08:03.103 回答