Android-adb获取当前前台进程

背景:

      安卓R版本在权限检测的时候对某些权限加了前后台的判断,如果是后台就默认不给权限。然后我们遇到了权限的问题,无法确实是否是前后台引起,所以想在运行过程中动态获取前台的进程。

 

方法:

    adb shell

    dumpsys activity activities

 

结果查看:

dumpsys activity activities                                            
ACTIVITY MANAGER ACTIVITIES (dumpsys activity activities)
Display #0 (activities from top to bottom): // 下面就是按照top to bottom排序的activity,所以第一个就是前台进程
  Stack #37: type=standard mode=fullscreen
  isSleeping=false
  mBounds=Rect(0, 0 - 0, 0)
    mResumedActivity: ActivityRecord{3c7a895 u0 com.tencent.tmgp.sgame/.SGameActivity t37}
    mLastPausedActivity: ActivityRecord{3c7a895 u0 com.tencent.tmgp.sgame/.SGameActivity t37}
    * Task{b483f6f #37 visible=true type=standard mode=fullscreen translucent=true A=10248:com.tencent.tmgp.sgame U=0 StackId=37 sz=1}
      mBounds=Rect(0, 0 - 0, 0)
      mMinWidth=-1 mMinHeight=-1
      userId=0 effectiveUid=u0a248 mCallingUid=u0a108 mUserSetupComplete=true mCallingPackage=com.miui.home mCallingFeatureId=null
      affinity=10248:com.tencent.tmgp.sgame
      intent={act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.tencent.tmgp.sgame/.SGameActivity}
      mActivityComponent=com.tencent.tmgp.sgame/.SGameActivity
      autoRemoveRecents=false isPersistable=true activityType=1
      rootWasReset=true mNeverRelinquishIdentity=true mReuseTask=false mLockTaskAuth=LOCK_TASK_AUTH_PINNABLE
      Activities=[ActivityRecord{3c7a895 u0 com.tencent.tmgp.sgame/.SGameActivity t37}] // 前台进程就是王者荣耀
      askedCompatMode=false inRecents=true isAvailable=true
      mRootProcess=ProcessRecord{a78bd44 31635:com.tencent.tmgp.sgame/u0a248}
      taskId=37 stackId=37
      mHasBeenVisible=true
      mResizeMode=RESIZE_MODE_RESIZEABLE mSupportsPictureInPicture=false isResizeable=true
 supportsSplitScreenWindowingMode=true lastActiveTime=5170911      lastActiveTime=5170911 (inactive for 1s)
      * Hist #0: ActivityRecord{3c7a895 u0 com.tencent.tmgp.sgame/.SGameActivity t37}
          packageName=com.tencent.tmgp.sgame processName=com.tencent.tmgp.sgame
          launchedFromUid=10108 launchedFromPackage=com.miui.home launchedFromFeature=null userId=0
          app=ProcessRecord{a78bd44 31635:com.tencent.tmgp.sgame/u0a248}
          Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] flg=0x10200000 cmp=com.tencent.tmgp.sgame/.SGameActivity bnds=[590,730][758,898] (has extras) }
          rootOfTask=true task=Task{b483f6f #37 visible=true type=standard mode=fullscreen translucent=true A=10248:com.tencent.tmgp.sgame U=0 StackId=37 sz=1}
          taskAffinity=10248:com.tencent.tmgp.sgame
          mActivityComponent=com.tencent.tmgp.sgame/.SGameActivity
          baseDir=/data/app/~~ULVzRzBTMDNZx32eyCyVgA==/com.tencent.tmgp.sgame-djLAI0s1v0F-pFm6b8GpeA==/base.apk
          dataDir=/data/user/0/com.tencent.tmgp.sgame
          stateNotNeeded=false componentSpecified=false mActivityType=standard
          compat={440dpi} labelRes=0x7f0900ce icon=0x7f020054 theme=0x7f0b0009
          mLastReportedConfigurations:

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值