mirror of
http://gitea.winboll.cc/Studio/WinBoLL.git
synced 2026-06-29 20:12:23 +08:00
修复GPS订阅数据流断裂,打通MainService→广播→ChildService完整链路
- GpsSubscribeResult 增加 latitude/longitude/locationTime 字段及序列化
- GpsSubscribeReceiverService 重写 onCreate/onDestroy 动态注册广播接收器,onStartCommand 读取 SID 并绑定
- GpsSubscribeControlView 启动服务时传递 EXTRA_SUBSCRIBE_SID
- MainService 步长判断通过后调用 sendSubscribeResult();initManager() 补调 initContext(this)
- GpsReceiverChildService{1,2,3} 补调 super.onStartCommand
- AndroidManifest.xml 修正广播 Action 为 cc.winboll.studio.GPS_SUBSCRIBE_CALLBACK
- GpsSubscribeManager/GpsSubscribeObserverReceiver 广播 Extra 键名改用常量
- GpsSubscribeConst 新增 EXTRA_SUBSCRIBE_SID/EXTRA_SUBSCRIBE_RESULT/EXTRA_LOCATION_POINT
This commit is contained in:
@@ -17,7 +17,7 @@
|
||||
|
||||
<intent-filter>
|
||||
|
||||
<action android:name=".receiver.GpsSubscribeObserverReceiver"/>
|
||||
<action android:name="cc.winboll.studio.GPS_SUBSCRIBE_CALLBACK"/>
|
||||
|
||||
</intent-filter>
|
||||
|
||||
|
||||
@@ -59,7 +59,7 @@ public final class GpsSubscribeManager {
|
||||
return;
|
||||
}
|
||||
Intent intent = new Intent(GpsSubscribeConst.ACTION_SUBSCRIBE_CALLBACK);
|
||||
intent.putExtra("data",result);
|
||||
intent.putExtra(GpsSubscribeConst.EXTRA_SUBSCRIBE_RESULT, result);
|
||||
appContext.sendBroadcast(intent);
|
||||
}
|
||||
|
||||
|
||||
@@ -37,6 +37,11 @@ public final class GpsSubscribeConst {
|
||||
public static final String ACTION_SUBSCRIBE_REQUEST = "cc.winboll.studio.GPS_SUBSCRIBE_REQUEST";
|
||||
public static final String ACTION_SUBSCRIBE_CALLBACK = "cc.winboll.studio.GPS_SUBSCRIBE_CALLBACK";
|
||||
|
||||
//Intent Extra 键名
|
||||
public static final String EXTRA_SUBSCRIBE_SID = "extra_subscribe_sid";
|
||||
public static final String EXTRA_SUBSCRIBE_RESULT = "extra_subscribe_result";
|
||||
public static final String EXTRA_LOCATION_POINT = "extra_location_point";
|
||||
|
||||
//超时毫秒
|
||||
public static final long SUBSCRIBE_TIME_OUT = 5000;
|
||||
|
||||
|
||||
@@ -17,19 +17,28 @@ public final class GpsSubscribeResult implements Parcelable {
|
||||
private final int gpsRunningState;
|
||||
private final long realEffectiveInterval;
|
||||
private final long currentTimeStamp;
|
||||
private final double latitude;
|
||||
private final double longitude;
|
||||
private final long locationTime;
|
||||
|
||||
public GpsSubscribeResult(String subscribeUniqueId,
|
||||
int resultCode,
|
||||
String resultDesc,
|
||||
int gpsRunningState,
|
||||
long realEffectiveInterval,
|
||||
long currentTimeStamp) {
|
||||
long currentTimeStamp,
|
||||
double latitude,
|
||||
double longitude,
|
||||
long locationTime) {
|
||||
this.subscribeUniqueId = subscribeUniqueId;
|
||||
this.resultCode = resultCode;
|
||||
this.resultDesc = resultDesc;
|
||||
this.gpsRunningState = gpsRunningState;
|
||||
this.realEffectiveInterval = realEffectiveInterval;
|
||||
this.currentTimeStamp = currentTimeStamp;
|
||||
this.latitude = latitude;
|
||||
this.longitude = longitude;
|
||||
this.locationTime = locationTime;
|
||||
}
|
||||
|
||||
public String getSubscribeUniqueId() {
|
||||
@@ -56,6 +65,18 @@ public final class GpsSubscribeResult implements Parcelable {
|
||||
return currentTimeStamp;
|
||||
}
|
||||
|
||||
public double getLatitude() {
|
||||
return latitude;
|
||||
}
|
||||
|
||||
public double getLongitude() {
|
||||
return longitude;
|
||||
}
|
||||
|
||||
public long getLocationTime() {
|
||||
return locationTime;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int describeContents() {
|
||||
return 0;
|
||||
@@ -69,6 +90,9 @@ public final class GpsSubscribeResult implements Parcelable {
|
||||
dest.writeInt(gpsRunningState);
|
||||
dest.writeLong(realEffectiveInterval);
|
||||
dest.writeLong(currentTimeStamp);
|
||||
dest.writeDouble(latitude);
|
||||
dest.writeDouble(longitude);
|
||||
dest.writeLong(locationTime);
|
||||
}
|
||||
|
||||
public static final Creator<GpsSubscribeResult> CREATOR = new Creator<GpsSubscribeResult>() {
|
||||
@@ -80,6 +104,9 @@ public final class GpsSubscribeResult implements Parcelable {
|
||||
in.readString(),
|
||||
in.readInt(),
|
||||
in.readLong(),
|
||||
in.readLong(),
|
||||
in.readDouble(),
|
||||
in.readDouble(),
|
||||
in.readLong()
|
||||
);
|
||||
}
|
||||
@@ -98,6 +125,9 @@ public final class GpsSubscribeResult implements Parcelable {
|
||||
bundle.putInt("gpsState", gpsRunningState);
|
||||
bundle.putLong("realInterval", realEffectiveInterval);
|
||||
bundle.putLong("time", currentTimeStamp);
|
||||
bundle.putDouble("lat", latitude);
|
||||
bundle.putDouble("lng", longitude);
|
||||
bundle.putLong("locTime", locationTime);
|
||||
return bundle;
|
||||
}
|
||||
|
||||
@@ -108,7 +138,10 @@ public final class GpsSubscribeResult implements Parcelable {
|
||||
bundle.getString("desc"),
|
||||
bundle.getInt("gpsState"),
|
||||
bundle.getLong("realInterval"),
|
||||
bundle.getLong("time")
|
||||
bundle.getLong("time"),
|
||||
bundle.getDouble("lat"),
|
||||
bundle.getDouble("lng"),
|
||||
bundle.getLong("locTime")
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ public final class GpsSubscribeObserverReceiver extends BroadcastReceiver {
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
if(GpsSubscribeConst.ACTION_SUBSCRIBE_CALLBACK.equals(action)){
|
||||
GpsSubscribeResult result = intent.getParcelableExtra("data");
|
||||
GpsSubscribeResult result = intent.getParcelableExtra(GpsSubscribeConst.EXTRA_SUBSCRIBE_RESULT);
|
||||
if(listener != null && result != null){
|
||||
listener.onResultBack(result);
|
||||
}
|
||||
|
||||
@@ -1,11 +1,17 @@
|
||||
package cc.winboll.studio.libgitsion.service;
|
||||
|
||||
import android.app.Service;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.os.IBinder;
|
||||
|
||||
import cc.winboll.studio.libappbase.LogUtils;
|
||||
import cc.winboll.studio.libgitsion.manager.SubscribeLocationManager;
|
||||
import cc.winboll.studio.libgitsion.model.GpsSubscribeConst;
|
||||
import cc.winboll.studio.libgitsion.model.GpsSubscribeMsg;
|
||||
import cc.winboll.studio.libgitsion.model.GpsSubscribeResult;
|
||||
import cc.winboll.studio.libgitsion.model.LocationPoint;
|
||||
|
||||
/**
|
||||
@@ -19,10 +25,59 @@ public abstract class GpsSubscribeReceiverService extends Service {
|
||||
//当前绑定的视图订阅SID
|
||||
protected String bindViewSid;
|
||||
|
||||
private BroadcastReceiver mCallbackReceiver;
|
||||
|
||||
public void bindControlSid(String sid){
|
||||
this.bindViewSid = sid;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
LogUtils.d(TAG_PARENT, "Service onCreate, 注册广播接收器");
|
||||
mCallbackReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
if (GpsSubscribeConst.ACTION_SUBSCRIBE_CALLBACK.equals(intent.getAction())) {
|
||||
GpsSubscribeResult result = intent.getParcelableExtra(GpsSubscribeConst.EXTRA_SUBSCRIBE_RESULT);
|
||||
if (result != null && bindViewSid != null
|
||||
&& bindViewSid.equals(result.getSubscribeUniqueId())) {
|
||||
LocationPoint point = new LocationPoint(
|
||||
result.getLatitude(),
|
||||
result.getLongitude(),
|
||||
result.getLocationTime()
|
||||
);
|
||||
GpsSubscribeMsg config = SubscribeLocationManager.getInstance()
|
||||
.getSubscribeConfig(bindViewSid);
|
||||
LogUtils.d(TAG_PARENT, "收到GPS推送,转发至 onReceiveGpsData,SID:" + bindViewSid);
|
||||
onReceiveGpsData(point, config);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
registerReceiver(mCallbackReceiver, new IntentFilter(GpsSubscribeConst.ACTION_SUBSCRIBE_CALLBACK));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||
if (intent != null && intent.hasExtra(GpsSubscribeConst.EXTRA_SUBSCRIBE_SID)) {
|
||||
String sid = intent.getStringExtra(GpsSubscribeConst.EXTRA_SUBSCRIBE_SID);
|
||||
bindControlSid(sid);
|
||||
LogUtils.d(TAG_PARENT, "绑定SID:" + sid);
|
||||
}
|
||||
return START_NOT_STICKY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
if (mCallbackReceiver != null) {
|
||||
unregisterReceiver(mCallbackReceiver);
|
||||
mCallbackReceiver = null;
|
||||
LogUtils.d(TAG_PARENT, "广播接收器已注销");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 统一接收GPS推送入口
|
||||
*/
|
||||
|
||||
@@ -139,9 +139,10 @@ public final class GpsSubscribeControlView extends LinearLayout {
|
||||
mLocationManager.putSubscribeConfig(currentSubscribeSid, subscribeMsg);
|
||||
mLocationManager.clearPushCount(currentSubscribeSid);
|
||||
|
||||
//开启订阅自动启动专属接收服务
|
||||
//开启订阅自动启动专属接收服务(携带SID)
|
||||
if(mBindReceiverServiceClazz != null){
|
||||
Intent startServiceIntent = new Intent(getContext(), mBindReceiverServiceClazz);
|
||||
startServiceIntent.putExtra(GpsSubscribeConst.EXTRA_SUBSCRIBE_SID, currentSubscribeSid);
|
||||
getContext().startService(startServiceIntent);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user