|
@@ -112,8 +112,8 @@ public class StepService extends Service implements SensorEventListener {
|
|
|
updateNotification("今日步数:" + com.xzjmyk.pm.basepedo.service.StepDcretor.CURRENT_SETP + " 步");
|
|
updateNotification("今日步数:" + com.xzjmyk.pm.basepedo.service.StepDcretor.CURRENT_SETP + " 步");
|
|
|
flags = START_STICKY;
|
|
flags = START_STICKY;
|
|
|
Log.i("StepService", "onStartCommand");
|
|
Log.i("StepService", "onStartCommand");
|
|
|
- return super.onStartCommand(intent,flags,startId);
|
|
|
|
|
-
|
|
|
|
|
|
|
+// return super.onStartCommand(intent,flags,startId);
|
|
|
|
|
+ return START_REDELIVER_INTENT;
|
|
|
}
|
|
}
|
|
|
private String getTodayDate() {
|
|
private String getTodayDate() {
|
|
|
Date date = new Date(System.currentTimeMillis());
|
|
Date date = new Date(System.currentTimeMillis());
|
|
@@ -204,21 +204,27 @@ public class StepService extends Service implements SensorEventListener {
|
|
|
PendingIntent contentIntent = PendingIntent.getActivity(this, 100,
|
|
PendingIntent contentIntent = PendingIntent.getActivity(this, 100,
|
|
|
new Intent(this, MyPedometerActivity.class), 0);
|
|
new Intent(this, MyPedometerActivity.class), 0);
|
|
|
builder.setContentIntent(contentIntent);
|
|
builder.setContentIntent(contentIntent);
|
|
|
|
|
+// builder.setDeleteIntent(contentIntent);
|
|
|
builder.setSmallIcon(R.drawable.uuu);
|
|
builder.setSmallIcon(R.drawable.uuu);
|
|
|
builder.setTicker("UU运动");
|
|
builder.setTicker("UU运动");
|
|
|
builder.setContentTitle("UU运动");
|
|
builder.setContentTitle("UU运动");
|
|
|
- //设置不可清除
|
|
|
|
|
-// builder.setOngoing(true);
|
|
|
|
|
|
|
+// builder.setOngoing(true); //设置不可清除
|
|
|
builder.setContentText(content);
|
|
builder.setContentText(content);
|
|
|
Notification notification = builder.build();
|
|
Notification notification = builder.build();
|
|
|
-
|
|
|
|
|
startForeground(0, notification);
|
|
startForeground(0, notification);
|
|
|
|
|
+
|
|
|
nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
|
|
nm = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
|
|
|
- if (PreferenceUtils.getInt(this,MyPedometerActivity.UU_STEP_NOTICE) == 1){
|
|
|
|
|
|
|
+// if (PreferenceUtils.getInt(this,MyPedometerActivity.UU_STEP_NOTICE) == 1){
|
|
|
nm.notify(R.string.app_name, notification);
|
|
nm.notify(R.string.app_name, notification);
|
|
|
- }else if(PreferenceUtils.getInt(this,MyPedometerActivity.UU_STEP_NOTICE) == 0){
|
|
|
|
|
- nm.cancelAll();
|
|
|
|
|
|
|
+// }else if(PreferenceUtils.getInt(this,MyPedometerActivity.UU_STEP_NOTICE) == 0){
|
|
|
|
|
+// nm.cancelAll();
|
|
|
|
|
+// }
|
|
|
|
|
+ try {
|
|
|
|
|
+ unlock();
|
|
|
|
|
+ }catch (SecurityException s){
|
|
|
|
|
+ s.printStackTrace();
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
@@ -236,12 +242,12 @@ public class StepService extends Service implements SensorEventListener {
|
|
|
.getSystemService(SENSOR_SERVICE);
|
|
.getSystemService(SENSOR_SERVICE);
|
|
|
getLock(this);
|
|
getLock(this);
|
|
|
// android4.4以后可以使用计步传感器
|
|
// android4.4以后可以使用计步传感器
|
|
|
- int VERSION_CODES = Build.VERSION.SDK_INT;
|
|
|
|
|
- if (VERSION_CODES >= 19) {
|
|
|
|
|
- addCountStepListener();
|
|
|
|
|
- } else {
|
|
|
|
|
- addBasePedoListener();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+// int VERSION_CODES = Build.VERSION.SDK_INT;
|
|
|
|
|
+// if (VERSION_CODES >= 19) {
|
|
|
|
|
+// addCountStepListener();
|
|
|
|
|
+// } else {
|
|
|
|
|
+// addBasePedoListener();
|
|
|
|
|
+// }
|
|
|
|
|
|
|
|
addBasePedoListener();
|
|
addBasePedoListener();
|
|
|
addCountStepListener();
|
|
addCountStepListener();
|
|
@@ -274,7 +280,6 @@ public class StepService extends Service implements SensorEventListener {
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
public void onChange() {
|
|
public void onChange() {
|
|
|
-// updateNotification("今日步数:" + StepDcretor.CURRENT_SETP + "," + i + " 步");
|
|
|
|
|
updateNotification("今日步数:" + StepDcretor.CURRENT_SETP + " 步");
|
|
updateNotification("今日步数:" + StepDcretor.CURRENT_SETP + " 步");
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
@@ -330,6 +335,7 @@ public class StepService extends Service implements SensorEventListener {
|
|
|
public void onDestroy() {
|
|
public void onDestroy() {
|
|
|
//取消前台进程
|
|
//取消前台进程
|
|
|
stopForeground(true);
|
|
stopForeground(true);
|
|
|
|
|
+ stopForeground(false);
|
|
|
DbUtils.closeDb();
|
|
DbUtils.closeDb();
|
|
|
unregisterReceiver(mBatInfoReceiver);
|
|
unregisterReceiver(mBatInfoReceiver);
|
|
|
if (! isServiceRunning(uustep_service_name) && PreferenceUtils.getInt(MyApplication.getInstance(), MainActivity.UU_STEP)==1){
|
|
if (! isServiceRunning(uustep_service_name) && PreferenceUtils.getInt(MyApplication.getInstance(), MainActivity.UU_STEP)==1){
|
|
@@ -347,14 +353,14 @@ public class StepService extends Service implements SensorEventListener {
|
|
|
return super.onUnbind(intent);
|
|
return super.onUnbind(intent);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-// private void unlock(){
|
|
|
|
|
-// setLockPatternEnabled(android.provider.Settings.Secure.LOCK_PATTERN_ENABLED,false);
|
|
|
|
|
-// }
|
|
|
|
|
-//
|
|
|
|
|
-// private void setLockPatternEnabled(String systemSettingKey, boolean enabled) {
|
|
|
|
|
-// //推荐使用
|
|
|
|
|
-// android.provider.Settings.Secure.putInt(getContentResolver(), systemSettingKey,enabled ? 1 : 0);
|
|
|
|
|
-// }
|
|
|
|
|
|
|
+ private void unlock(){
|
|
|
|
|
+ setLockPatternEnabled(android.provider.Settings.Secure.LOCK_PATTERN_ENABLED,false);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ private void setLockPatternEnabled(String systemSettingKey, boolean enabled) {
|
|
|
|
|
+ //推荐使用
|
|
|
|
|
+ android.provider.Settings.Secure.putInt(getContentResolver(), systemSettingKey,enabled ? 1 : 0);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
synchronized private WakeLock getLock(Context context) {
|
|
synchronized private WakeLock getLock(Context context) {
|
|
|
if (mWakeLock != null) {
|
|
if (mWakeLock != null) {
|