【问题标题】:Dynamically getting android lock screen package name动态获取android锁屏包名
【发布时间】:2016-12-03 20:29:17
【问题描述】:

我需要获取 android 锁屏活动的包名。除了https://stackoverflow.com/a/16881064/2803557 之外,我没有找到任何东西,这似乎不起作用。

有没有办法获取锁屏包名

【问题讨论】:

  • 锁屏包名是:com.android.systemui 如果你想在锁屏上显示一些东西,还有其他更好的方法来做到这一点。

标签: android lockscreen package-name


【解决方案1】:

您可以通过分析 Android 日志来确定出现在前台的任何 Activity 的包名称。例如,如果你打开了谷歌地图,点击设备的主页按钮会在日志中显示(我通常按ActivityManager 字符串过滤)。

START u0 {act=android.intent.action.MAIN cat=[android.intent.category.HOME] 
flg=0x10200000 cmp=com.android.launcher/com.android.launcher2.Launcher} 

显示主屏幕的包名Activitycom.android.launcher

但是,当我单击 Nexus 4 主页按钮以显示任何应用程序的锁屏时,它永远不会显示正在启动的另一个 Activity。这让我觉得这不是我们所理解的典型Activity

如果您查看Android 源代码KeyguardViewMediator.java 的源代码,您会发现一个名为private void doKeyguardLocked(Bundle options) 的方法。我从经验中知道,将源更改为立即从此方法返回将禁用锁屏。 KeyguardViewMediator.java的来源显示它在包com.android.keyguard中,我相信这就是你要找的包。

至于动态获取包名,对我来说似乎是不可能的。但是,如果您已经提前知道包名,则无需动态获取。

我希望这会有所帮助。

【讨论】:

    【解决方案2】:

    获取所有进程的列表,然后检查屏幕锁定应用程序包名称。

    下面是代码:

    ActivityManager activityManager = (ActivityManager) getSystemService(ACTIVITY_SERVICE);
    List<ActivityManager.RunningServiceInfo> services = activityManager.getRunningServices(Integer.MAX_VALUE);
    
    long currentMillis = Calendar.getInstance().getTimeInMillis();
    Calendar cal = Calendar.getInstance();
    
    for (ActivityManager.RunningServiceInfo info : services) {
      cal.setTimeInMillis(currentMillis-info.activeSince);
      Log.i("TAG", String.format("Process %s has been running since: %d ms",info.process,  info.activeSince));
    }
    

    Logcat:

    TAG: Process com.android.systemui has been running since: 86526 ms 
    

    那是锁屏^

    TAG: Process com.qualcomm.telephony has been running since: 68521 ms
    TAG: Process com.motorola.ccc has been running since: 57456 ms
    TAG: Process com.google.android.music:main has been running since: 26245 ms
    TAG: Process com.android.phone has been running since: 29421 ms
    TAG: Process com.motorola.ccc has been running since: 52141 ms
    TAG: Process system has been running since: 28602 ms
    TAG: Process com.motorola.actions has been running since: 74371 ms
    TAG: Process com.motorola.ccc has been running since: 59166 ms
    TAG: Process com.motorola.process.slpc has been running since: 25483 ms
    TAG: Process com.android.systemui has been running since: 30142 ms
    TAG: Process com.android.bluetooth has been running since: 22187 ms
    TAG: Process system has been running since: 28603 ms
    TAG: Process com.google.android.gms.persistent has been running since: 31621 ms
    TAG: Process com.android.systemui has been running since: 27361 ms
    TAG: Process com.google.android.gms.persistent has been running since: 99678 ms
    TAG: Process com.motorola.contacts.preloadcontacts has been running since: 45603 ms
    TAG: Process com.google.android.gms.persistent has been running since: 73457 ms
    TAG: Process com.google.android.gms.persistent has been running since: 72908 ms
    TAG: Process com.google.android.gms.persistent has been running since: 37251 
    

    【讨论】:

    • 那是我不知道包名的问题
    • @AkashKumar 您可以从您已经提到的问题中获取包名称。
    • @AkashKumar 检查this
    猜你喜欢
    • 2012-10-09
    • 2012-05-24
    • 2010-10-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-28
    相关资源
    最近更新 更多