Commit c8b0a846 by cuiliang.shi

第4章短信下发指令

由于通过接口通讯,数据的获取并不及时,也可能用户关闭了定位上送服务,在紧急情况下需要了解老人的定位信息,这时通过短信发送特定短信,老人机通过解析指令并上送定位信息,或者更改定位的配置信息。短信可在解析后删除,无需向用户展示。
短信内容:【微尚信息】颐关爱下发指令:#2*开始时间*结束时间*频率#
1 parent ac9838be
......@@ -6,8 +6,8 @@ android {
applicationId "com.toscl.location.hengfeng"
minSdkVersion 23
targetSdkVersion 28
versionCode 1
versionName "0.1"
versionCode 3
versionName "0.3"
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
}
buildTypes {
......@@ -20,7 +20,8 @@ android {
android.applicationVariants.all { variant ->
variant.outputs.all {
outputFileName = "LocationServer_${defaultConfig.versionName}.apk"
// _${defaultConfig.versionName}
outputFileName = "LocationService.apk"
}
}
compileOptions {
......
......@@ -74,6 +74,8 @@ public class LocationService extends Service {
public int onStartCommand(Intent intent, int flags, int startId) {
Log.d(TAG, "onStartCommand");
isStartFromSms(intent);
handleForegroundService();
/*
......@@ -109,6 +111,42 @@ public class LocationService extends Service {
return super.onStartCommand(intent, flags, startId);
}
private void isStartFromSms(Intent intent) {
String begin = intent.getStringExtra("begin");
if (begin != null){
String end = intent.getStringExtra("end");
String frequency = intent.getStringExtra("frequency");
PreferencesUtil.getInstance(getApplicationContext())
.putInt(PreferencesUtil.HENG_FENG_BEGIN, Integer.parseInt(begin));
PreferencesUtil.getInstance(getApplicationContext())
.putInt(PreferencesUtil.HENG_FENG_END, Integer.parseInt(end));
PreferencesUtil.getInstance(getApplicationContext())
.putInt(PreferencesUtil.HENG_FENG_FREQUENCY, Integer.parseInt(frequency));
PreferencesUtil.getInstance(getApplicationContext())
.putBoolean(PreferencesUtil.HENG_FENG_IS_OEPN, true);
cancelPreviousAlarmService();
}
}
private void cancelPreviousAlarmService() {
AlarmManager manger = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
Intent alarmReceiverIntent = new Intent(getApplicationContext(), AlarmReceiver.class);
PendingIntent alarmReceiverPendingIntent =
PendingIntent.getBroadcast(getApplicationContext(), 0, alarmReceiverIntent, 0);
try {
manger.cancel(alarmReceiverPendingIntent);
Log.d(TAG, "alarm is canceled.");
} catch (Exception e) {
e.printStackTrace();
Log.d(TAG, "alarm cancel exception: " + e.toString());
}
}
private void readyToReqLocation() {
resetTheCounts();
sendOpenGpsBroadcast();
......@@ -219,7 +257,7 @@ public class LocationService extends Service {
}
}
if (mRequestLocationCount > 10) {
if (mRequestLocationCount > 15) {
if (mWifiLatitude != 0 && mWifiLongitude != 0
&& mGpsLatitude != 0 && mGpsLongitude != 0) {
LatLng wifiLatLng = new LatLng(mWifiLatitude, mWifiLongitude);
......
......@@ -6,7 +6,6 @@ import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.telephony.SubscriptionInfo;
import android.telephony.SubscriptionManager;
import android.util.Log;
import android.view.View;
......
......@@ -108,6 +108,11 @@ public class ServiceSettingActivity extends Activity implements View.OnClickList
int endIndex = mSpinnerForEndDate.getSelectedItemPosition();
int frequency = Integer.parseInt(mEtFrequency.getText().toString());
if (frequency<7){
Toast.makeText(this, getString(R.string.setting_frequency_error), Toast.LENGTH_SHORT).show();
return;
}
String begin = startIndex + ":00";
String end = endIndex + ":00";
......
......@@ -272,7 +272,7 @@ public class PhoneUtils {
e.printStackTrace();
}
Log.d(TAG, "hengdaServiceAvailable : runFlag: " + runFlag);
Log.d(TAG, "ServiceAvailable : runFlag: " + runFlag);
return runFlag;
}
......
package com.toscl.location.hengfeng.util;
import android.annotation.TargetApi;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.Build;
import android.util.Log;
import com.toscl.location.hengfeng.api.IotApi;
......@@ -113,7 +111,6 @@ public class PreferencesUtil {
mEditor.commit();
}
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public void putStringSet(final String key, final Set<String> values) {
mEditor.putStringSet(key, values);
mEditor.commit();
......
......@@ -43,4 +43,5 @@
<string name="setting_tips_success" translatable="false">设置成功</string>
<string name="location_server_unavailable" translatable="false">定位失败,当前服务不在有效期内</string>
<string name="stop_service_tips">已停止服务</string>
<string name="setting_frequency_error">上传频率不得小于7分钟</string>
</resources>
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!