拉下Status bar之后,可以点击上面对应的icon,从而调出相应的Activity。
请问这个过程是怎么实现的?或者说,具体是哪个类的按键事件做出的反应

解决方案 »

  1.   

    我写了一小的apk,要想实现启动指定的application中某个Activity,只需要知道当前的上下文和Activity即可。     Intent notificationIntent = new Intent(this,this.getClass()); //点击该通知后要跳转的Activity
         PendingIntent contentIntent = PendingIntent.getActivity(this,0,notificationIntent,0);
         notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent); 
         nf.notify(0, notification);      
    那么,点击statusbar对应的图标时,具体的按键响应过程是怎么样的呢?
      

  2.   

    楼主看下 frameworks/base/services/java/com/android/server/status/
    StatusBarView.java
    StatusBarService.java
      

  3.   

    StatusBarView.java这个类有两个重要的方法,
    onTouchEvent和onInterceptTouchEvent
    这两个方法主要是用来响应statusbar的下拉事件,使之能显示扩展的状态栏。
    StatusBarService.java有个内部类,Launcher,该类中有个方法onClick:      public void onClick(View v) {
                 try {
                     // The intent we are sending is for the application, which
                     // won't have permission to immediately start an activity after
                     // the user switches to home.  We know it is safe to do at this
                     // point, so make sure new activity switches are now allowed.
                     ActivityManagerNative.getDefault().resumeAppSwitches();
                 } catch (RemoteException e) {
                 }
     
                 if (mIntent != null) {
                     int[] pos = new int[2];
                     v.getLocationOnScreen(pos);
                     Intent overlay = new Intent();
                     overlay.setSourceBounds(
                             new Rect(pos[0], pos[1], pos[0]+v.getWidth(), pos[1]+v.getHeight()));
                     try {
                         mIntent.send(StatusBarService.this, 0, overlay);
                     } catch (PendingIntent.CanceledException e) {
                         // the stack trace isn't very helpful here.  Just log the exception             message.
                         Slog.w(TAG, "Sending contentIntent failed: " + e);
                     }
                 }
     
                 try {
                      mBarService.onNotificationClick(mPkg, mTag, mId);
                 } catch (RemoteException ex) {
                     // system process is dead if we're here.
                 }
     
                 // close the shade if it was open
                 animateCollapse();
             }
         }感觉mBarService.onNotificationClick(mPkg, mTag, mId);这个方法应该就是处理按键消息的。只不过没用到上层传过来的contentIntent参数。搞不懂了
      

  4.   

    新手上路,学习来了。
    我想问我下拉了通知栏点击后成功连到了另一个class但是此时上面的那个通知栏还是显示着自己的提示。请问我想做到拉下来后点击连接到另个class后上面的提示也消失怎么做?
      

  5.   

    新手上路,学习来了。
    我想问我下拉了通知栏点击后成功连到了另一个class但是此时上面的那个通知栏还是显示着自己的提示。请问我想做到拉下来后点击连接到另个class后上面的提示也消失怎么做?将发出来的notification的flags设置为FLAG_AUTO_CANCEL就可以啦
      

  6.   

    mBarService.onNotificationClick(mPkg, mTag, mId)这方法是通知notificationManagerService清除notification