[英]Is there a way to log the number of times ANY installed app on my device has been launched?
我想使用此信息来确定设备上最常用的应用程序。
我还想了解是否有办法确定我在设备上使用每个应用程序花费了多少时间。
似乎只能在“越狱”设备上访问此信息。 我希望事实并非如此。
非常感谢!
我认为您不能为所有应用程序做到这一点。
相反,如果您想知道您的应用已启动多少次,请尝试以下操作:
在应用程序的屏幕上(或启动的第一个活动),尝试增加一个数字,并将其保存在SharedPreferences
:
SharedPreferences prefs = getSharedPreferences("prefs",Context.MODE_PRIVATE);
int counter = prefs.getInt("counter", -1);
if(counter == -1 ) {
//first launch of the app, init the counter
counter = 1;
}
else {
// increment the counter
counter++;
}
// update the value of the counter
SharedPreferences.Editor editor = prefs.edit();
editor.putInt("counter",counter);
editor.commit();
//then you can do what you want with your counter , send it to your back end via web service...etc
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.