作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试可靠地记录设备运行的时间。我已尽力使用 BOOT_COMPLETED
BroadcastReceiver
。由于如果应用程序被强制停止,所有接收器都会被删除,所以这种方法对我不起作用。
我想知道自上次恢复出厂设置以来是否有办法获取 Android 设备的正常运行时间?
list :
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="@string/title_activity_main" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name=".TestReceiver"
android:enabled="true"
android:exported="true"
android:label="Test Receiver" >
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
</application>
收件人代码:
public class TestReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Log.i("bootreceiver", intent.toString());
}
}
最佳答案
对于到达这里实际上是在寻找标题问题的答案的任何人:
您可以尝试获取其中一个系统包的安装时间,例如:
long curTime = System.currentTimeMillis();
long installTime = getPackageManager().getPackageInfo("com.android.providers.applications", 0).firstInstallTime;
long timeDiff = curTime - installTime;
关于android - 自恢复出厂设置 android 以来的时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12243073/
我是一名优秀的程序员,十分优秀!