在这里,我需要获得电池的状态与services.Service每秒钟后获取电池的状态,当我断开设备它显示USB连接到设备多少时间?请建议解决方案...............使用服务获取电池电量
public class serviceclass extends Service{
@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
// Let it continue running until it is stopped.
Toast.makeText(this, "Service Started", Toast.LENGTH_LONG).show();
return START_STICKY;
}
@Override
public void onDestroy() {
super.onDestroy();
Toast.makeText(this, "Service Destroyed", Toast.LENGTH_LONG).show();
}
}
是的你上面粘贴的代码只是一个简单的服务示例代码。让我们知道你有什么进一步尝试。 –
当我添加USB设备时,它会启动服务,记下当前连接USB的时间,并记录每秒钟后的时间,当我移除USB时,它会显示连接的时间。 – Shobin