我创建了锁屏应用程序,它可以正常启动应用程序。但我面临着通知问题。假设我将WhatsApp添加到app锁中,当我收到任何WhatsApp消息时,会出现锁定屏幕。我该如何解决呢?我使用下面的代码监控前台活动。是否有其他东西需要监控才能出现锁定屏幕。
private String aphpchecke() {
String currentApp = "NULL";
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
UsageStatsManager usm = null;
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP_MR1) {
usm = (UsageStatsManager) this.getSystemService(USAGE_STATS_SERVICE);
long time = System.currentTimeMillis();
List<UsageStats> appList = usm.queryUsageStats(UsageStatsManager.INTERVAL_DAILY, time - 1000 * 1000, time);
if (appList != null && appList.size() > 0) {
SortedMap<Long, UsageStats> mySortedMap = new TreeMap<Long, UsageStats>();
for (UsageStats usageStats : appList) {
mySortedMap.put(usageStats.getLastTimeUsed(), usageStats);
}
if (mySortedMap != null && !mySortedMap.isEmpty()) {
currentApp = mySortedMap.get(mySortedMap.lastKey()).getPackageName();
}
}
} else {
ActivityManager am = (ActivityManager) this.getSystemService(Context.ACTIVITY_SERVICE);
assert am != null;
List<ActivityManager.RunningAppProcessInfo> tasks = am.getRunningAppProcesses();
currentApp = tasks.get(0).processName;
}
Log.e("adapter", "Current App in foreground is: " + currentApp);
return currentApp;
} else {
ActivityManager mActivityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
assert mActivityManager != null;
List<ActivityManager.RunningTaskInfo> RunningTask = mActivityManager.getRunningTasks(1);
ActivityManager.RunningTaskInfo ar = RunningTask.get(0);
currentApp = ar.topActivity.getClassName();
Log.i(TAG, "Top Activity " + currentApp);
return currentApp;
}
}
一旦WhatsApp通知出现,前台活动就会显示WhatsApp软件包名称,因此逻辑上它必须显示锁定屏幕。
E/adapter: Current App in foreground is: com.google.android.apps.nexuslauncher
E/adapter: Current App in foreground is: com.whatsapp
D/FA: Logging event (FE): screen_view(_vs), Bundle[{firebase_event_origin(_o)=auto, firebase_previous_class(_pc)=LockScreen, firebase_previous_id(_pi)=7245334281643449211, firebase_screen_class(_sc)=LockScreen, firebase_screen_id(_si)=7245334281643449214}]
请指导,
答案 0 :(得分:0)
此代码在通知时不返回前景。
{ "query_string":{
"default_field":"text",
"query":"\"instruments de musique\"",
"enable_position_increments":false
}
}