动态获取android锁屏包名

问题描述:

我需要获取android锁屏活动的包名。我GOOGLE搜索没有发现,除了https://*.com/a/16881064/2803557这似乎不工作。动态获取android锁屏包名

有没有什么办法让所有进程的锁屏包名

+0

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

获取列表,然后检查是否有锁屏的应用程序包名称。

下面是代码:

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 
+0

这就是我不知道软件包名称的问题 –

+1

@AkashKumar你可以从已经提到的问题中获得软件包名称。 – Gattsu

+1

@AkashKumar检查[this](http://*.com/questions/40952185/dynamically-getting-android-lock-screen-package-name/41076162#comment69397047_40952185) – Gattsu

您可以任意确定包名通过分析Android日志来获得前景的。例如,如果您打开Goog​​le地图,则单击设备的“主页”按钮将在日志中显示此内容(我通常按照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

然而,当我点击我的Nexus 4家按钮,显示从任何应用程序的锁屏,它从来没有显示正在推出的另一款活动。这让我觉得这不是我们所理解的典型Activity

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

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

我希望这会有所帮助。