分享

android中如何点击通知定位到指定的activity

 软件团队头目 2012-10-24
Java代码  收藏代码
  1. private void initNotification() {  
  2.         mState = STATE_EXITED;  
  3.         mHungup = mContext.getResources().getString(R.string.hungup);  
  4.         mPlaying = mContext.getResources().getString(R.string.signalPrompt);  
  5.         if (null == mNM) {  
  6.             mNM = (NotificationManager) mContext  
  7.                     .getSystemService(Context.NOTIFICATION_SERVICE);  
  8.         }  
  9.   
  10.         if (null == mNotification) {  
  11.             mNotification = new Notification();  
  12.             mNotification.flags = Notification.FLAG_NO_CLEAR;  
  13.         }  
  14.         setRemoteActivity(LAUNCHER);  
  15.         setContentView();  
  16.     }  
  17.   
  18.   
  19.   
  20. /* 
  21.      * set the activity to go when click the item in the notification area. 
  22.      */  
  23.     public void setRemoteActivity(String launcher) {  
  24.         ComponentName comp = new ComponentName(PKGNAME, PKGNAME + launcher);  
  25.         Intent notificationIntent = new Intent();  
  26.         notificationIntent.setComponent(comp);  
  27.         if (launcher.equals(LAUNCHER)) {  
  28.             notificationIntent.addCategory("android.intent.category.LAUNCHER");  
  29.             notificationIntent.setAction("android.intent.action.MAIN");  
  30.             notificationIntent.setFlags(0x10200000);  
  31.         } else {  
  32.             notificationIntent.putExtra(Define.INTENT_CHANNEL_POSITION,  
  33.                     MBBMSService.sCurrentPlayPosition);  
  34.             notificationIntent.setAction(Action.ACTION_VIEW_PROGRAM_ACTION);  
  35.         }  
  36.         mNotification.contentIntent = PendingIntent.getActivity(mContext, 0,  
  37.                 notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);  
  38.     }  
  39.   
  40.     private void setContentView() {  
  41.         mContentView = new RemoteViews(mContext.getPackageName(),  
  42.                 R.layout.status_bar_signal);  
  43.         mContentView.setTextViewText(R.id.text, mPlaying);  
  44.         mContentView.setImageViewResource(R.id.icon, R.drawable.icon_tvplayer);  
  45.         mNotification.contentView = mContentView;  
  46.     }  
 

   方法setRemoteActivity里面使得后台运行的应用显示到主界面上,同时使得最后一次运行的activity显示在activity堆栈的最上面

分享到:
评论

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多