0

我想使用此信息来确定我设备上最常用的应用程序。

我还想知道是否有办法确定我在设备上使用每个应用程序所花费的时间。

似乎只能在“越狱”设备上访问此信息。我希望情况并非如此。

非常感谢!

4

1 回答 1

0

我认为您不能对所有应用程序都这样做。

相反,如果您想知道您的应用程序已启动多少次,请尝试以下操作:

在您的应用程序(或启动的第一个活动)的初始屏幕上,尝试增加一个数字,并将其保存在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 
于 2012-11-28T16:22:19.223 回答