我需要获取安卓锁屏活动的包名。我用谷歌搜索了一下,除了https://stackoverflow.com/a/16881064/2803557什么也没找到,它似乎不能工作。
有没有办法获取锁屏包名?
发布于 2016-12-11 10:52:43
您可以通过分析Android日志来确定任何来到前台的Activity的包名。例如,如果您打开了Google Maps,单击设备的主页按钮将在日志中显示此信息(我通常根据ActivityManager字符串进行过滤)。
START u0 {act=android.intent.action.MAIN cat=[android.intent.category.HOME]
flg=0x10200000 cmp=com.android.launcher/com.android.launcher2.Launcher} 向您显示主屏幕Activity的包名为com.android.launcher
然而,当我点击我的Nexus4主页按钮来显示任何应用程序的锁屏时,它从来没有显示另一个正在启动的活动。这让我觉得这不是我们所理解的典型的Activity。
如果你查看KeyguardViewMediator.java的源代码,你会发现一个名为private void doKeyguardLocked(Bundle options)的方法。根据我的经验,将源代码更改为从此方法立即返回将禁用锁屏。KeyguardViewMediator.java的源代码显示它在com.android.keyguard包中,我相信这就是您正在寻找的包。
至于动态获取包名,对我来说似乎是不可能的。但是,如果您事先已经知道包的名称,那么就没有必要动态获取它。
我希望这能帮到你。
发布于 2016-12-10 21:34:31
获取所有进程的列表,然后检查屏幕锁定应用程序包名称。
代码如下:
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 https://stackoverflow.com/questions/40952185
复制相似问题