, , queryUsageStats() , , . getLastTimeUsed.
rxJava:
List<UsageStats> queryUsageStats = usageStatsManager.queryUsageStats(UsageStatsManager.INTERVAL_DAILY, currentTime - milliSecs, currentTime);
rx.Observable.from(queryUsageStats)
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.toSortedList((usageStats1, usageStats2) -> compareTo(usageStats2.getLastTimeUsed(), usageStats1.getLastTimeUsed()))
.subscribe(usageStats -> {
Toast.makeText(ctx, usageStats.get(0).getPackageName(), Toast.LENGTH_SHORT).show();
});
:
Collections.sort(queryUsageStats, (usageStats1, usageStats2)
-> compareTo(usageStats2.getLastTimeUsed(), usageStats1.getLastTimeUsed()));
Toast.makeText(ctx, queryUsageStats.get(0).getPackageName(), Toast.LENGTH_SHORT).show();
private int compareTo(long a, long b) {
return a == b ? 0 : (a > b ? 1 : -1);
}
:
// Declare USAGE_STATS permisssion in manifest
<uses-permission
android:name="android.permission.PACKAGE_USAGE_STATS"
tools:ignore="ProtectedPermissions" />
//TODO: Check if user has already enabled Device Administrator, don't start this intent.
Intent intent = new Intent(Settings.ACTION_USAGE_ACCESS_SETTINGS);
startActivity(intent);
: , , 100%, Google Play.
, - , ( , , ...) - , .
, :
: .
, , ,
, , -, .
, , f_cked: 3.
Ultra Ultra STAMINA mode ( , Samsung Sony, ),
(,
call...), ALL app-lock ,
shared-user SMS-.
-, :), , , .
, lock-app, .:)