我需要獲取android鎖屏活動的包名。我GOOGLE搜索沒有發現,除了https://stackoverflow.com/a/16881064/2803557這似乎不工作。動態獲取android鎖屏包名
有沒有什麼辦法讓所有進程的鎖屏包名
我需要獲取android鎖屏活動的包名。我GOOGLE搜索沒有發現,除了https://stackoverflow.com/a/16881064/2803557這似乎不工作。動態獲取android鎖屏包名
有沒有什麼辦法讓所有進程的鎖屏包名
獲取列表,然後檢查是否有鎖屏的應用程序包名稱。
下面是代碼:
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
您可以任意確定包名通過分析Android日誌來獲得前景的。例如,如果您打開Google地圖,則單擊設備的「主頁」按鈕將在日誌中顯示此內容(我通常按照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
中,我相信這是您正在尋找的包。
至於動態獲取包名,它對我來說似乎不可能。但是,如果您已經提前知道包名,則不需要動態獲取它。
我希望這會有所幫助。
鎖屏包名是:com.android.systemui 如果你想在鎖屏上顯示某些東西,還有其他更好的方法來做到這一點。 – abhishesh