fix bug of location to upload socket server
This commit is contained in:
@@ -57,10 +57,12 @@ dependencies {
|
||||
implementation 'com.zhidao.carmanager:common:1.0.25@aar'
|
||||
|
||||
if (Boolean.valueOf(RELEASE)) {
|
||||
implementation "com.mogo.cloud:location:${MOGO_LOCATION_VERSION}"
|
||||
implementation "com.mogo.cloud:tanlu:${MOGO_TANLU_VERSION}"
|
||||
implementation "com.mogo.cloud:realtime:${MOGO_REALTIME_VERSION}"
|
||||
implementation "com.mogo.cloud:trafficlive:${MOGO_TRAFFICLIVE_VERSION}"
|
||||
} else {
|
||||
implementation project(":foudations:mogo-location")
|
||||
implementation project(":modules:mogo-tanlu")
|
||||
implementation project(":modules:mogo-realtime")
|
||||
implementation project(":modules:mogo-trafficlive")
|
||||
|
||||
@@ -60,19 +60,23 @@
|
||||
android:name=".RealTimeActivity"
|
||||
android:label="实时数据测试"
|
||||
android:launchMode="singleTask" />
|
||||
<activity
|
||||
android:name=".LocationActivity"
|
||||
android:label="定位数据上报测试"
|
||||
android:launchMode="singleTask" />
|
||||
<activity
|
||||
android:name=".RoadConditionActivity"
|
||||
android:label="路况服务"
|
||||
android:launchMode="singleTask" />
|
||||
|
||||
<!-- <receiver android:name=".wifi.WifiBroadCastReceiver">
|
||||
<intent-filter>
|
||||
<action android:name="android.net.wifi.RSSI_CHANGED" />
|
||||
<action android:name="android.net.wifi.STATE_CHANGE" />
|
||||
<action android:name="android.net.wifi.WIFI_STATE_CHANGED" />
|
||||
</intent-filter>
|
||||
<!-- <receiver android:name=".wifi.WifiBroadCastReceiver">
|
||||
<intent-filter>
|
||||
<action android:name="android.net.wifi.RSSI_CHANGED" />
|
||||
<action android:name="android.net.wifi.STATE_CHANGE" />
|
||||
<action android:name="android.net.wifi.WIFI_STATE_CHANGED" />
|
||||
</intent-filter>
|
||||
|
||||
</receiver>-->
|
||||
</receiver>-->
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
69
app/src/main/java/com/mogo/cloud/LocationActivity.java
Normal file
69
app/src/main/java/com/mogo/cloud/LocationActivity.java
Normal file
@@ -0,0 +1,69 @@
|
||||
package com.mogo.cloud;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.widget.Button;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import com.mogo.cloud.location.LocationManager;
|
||||
import com.mogo.cloud.location.MogoLocationInfoServices;
|
||||
import com.mogo.cloud.passport.MoGoAiCloudClientConfig;
|
||||
import com.mogo.cloud.tanlu.bean.location.MogoLocation;
|
||||
import com.mogo.realtime.socket.SocketHandler;
|
||||
|
||||
/**
|
||||
* @author arrow
|
||||
* @description 描述
|
||||
* @since: 2021/1/21
|
||||
*/
|
||||
public class LocationActivity extends AppCompatActivity {
|
||||
|
||||
private static final String TAG = "LocationActivity";
|
||||
|
||||
private Button snapshotLocStart;
|
||||
private Button snapshotLocStop;
|
||||
|
||||
@Override
|
||||
protected void onCreate(@Nullable Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_location);
|
||||
MogoLocationInfoServices.getInstance().init(this);
|
||||
SocketHandler.getInstance().initSocket(this, MoGoAiCloudClientConfig.getInstance().getServiceAppId());
|
||||
|
||||
MogoLocation mogoLocation = new MogoLocation();
|
||||
mogoLocation.setAccuracy(0.0f);
|
||||
mogoLocation.setAdCode("110113");
|
||||
mogoLocation.setCityCode("010");
|
||||
mogoLocation.setAddress("北京测试");
|
||||
mogoLocation.setAltitude(20);
|
||||
mogoLocation.setSpeed(20.0f);
|
||||
mogoLocation.setLocationDetail("北京东城环球贸易中心");
|
||||
mogoLocation.setBearing(185.8831f);
|
||||
mogoLocation.setAltitude(0.0);
|
||||
mogoLocation.setLatitude(40.201138738452414);
|
||||
mogoLocation.setLongitude(116.74181952698365);
|
||||
mogoLocation.setLocType(0);
|
||||
mogoLocation.setGpsAccuracyStatus(0);
|
||||
mogoLocation.setProvider("AGPS");
|
||||
|
||||
snapshotLocStart = findViewById(R.id.snapshotLocStart);
|
||||
snapshotLocStart.setOnClickListener(view -> {
|
||||
MogoLocationInfoServices.getInstance().start();
|
||||
MogoLocationInfoServices.getInstance().provideLocation(mogoLocation);
|
||||
});
|
||||
|
||||
snapshotLocStop = findViewById(R.id.snapshotLocStop);
|
||||
snapshotLocStop.setOnClickListener(view -> {
|
||||
SocketHandler.getInstance().stop();
|
||||
MogoLocationInfoServices.getInstance().stop();
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
SocketHandler.getInstance().stop();
|
||||
MogoLocationInfoServices.getInstance().stop();
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
private Button btnJumpConfigInfo;
|
||||
private Button btnJumpNetWorkPort;
|
||||
private Button btnJumpRealTime;
|
||||
private Button btnJumpLocation;
|
||||
private Button btnJumpRoadCondition;
|
||||
private Button btnJumpLivePlayAndPush;
|
||||
private Button btnJumpLivePush;
|
||||
@@ -65,6 +66,12 @@ public class MainActivity extends AppCompatActivity {
|
||||
startActivity(intent);
|
||||
});
|
||||
|
||||
btnJumpLocation = findViewById(R.id.btnJumpLocation);
|
||||
btnJumpLocation.setOnClickListener(v -> {
|
||||
Intent intent = new Intent(MainActivity.this, LocationActivity.class);
|
||||
startActivity(intent);
|
||||
});
|
||||
|
||||
btnJumpRoadCondition = findViewById(R.id.btnJumpRoadcondition);
|
||||
btnJumpRoadCondition.setOnClickListener(v -> {
|
||||
Intent intent = new Intent(MainActivity.this, RoadConditionActivity.class);
|
||||
|
||||
@@ -76,6 +76,7 @@ public class MoGoApplication extends MultiDexApplication {
|
||||
}
|
||||
});
|
||||
|
||||
clientConfig.setUseOriginSocket(true);
|
||||
// 初始化SDK,可以设置状态回调来监听
|
||||
MoGoAiCloudClient.getInstance().init(this, clientConfig);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
package com.mogo.cloud.location;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.annotation.Keep;
|
||||
|
||||
import com.mogo.cloud.tanlu.bean.location.MogoLocation;
|
||||
import com.mogo.cloud.utils.logger.Logger;
|
||||
|
||||
@Keep
|
||||
public class MogoLocationInfoServices {
|
||||
|
||||
private static final String TAG = "MogoLocationInfoServices-sdk";
|
||||
|
||||
private static volatile MogoLocationInfoServices sInstance;
|
||||
private MogoLocation mLocation;
|
||||
|
||||
private MogoLocationInfoServices() {
|
||||
}
|
||||
|
||||
@Keep
|
||||
public static MogoLocationInfoServices getInstance() {
|
||||
if (sInstance == null) {
|
||||
synchronized (MogoLocationInfoServices.class) {
|
||||
if (sInstance == null) {
|
||||
sInstance = new MogoLocationInfoServices();
|
||||
}
|
||||
}
|
||||
}
|
||||
return sInstance;
|
||||
}
|
||||
|
||||
public synchronized void release() {
|
||||
sInstance = null;
|
||||
}
|
||||
|
||||
public void provideLocation(MogoLocation location) {
|
||||
mLocation = location;
|
||||
}
|
||||
|
||||
public MogoLocation getLocation() {
|
||||
return mLocation;
|
||||
}
|
||||
|
||||
public void start() {
|
||||
LocationManager.getInstance().start();
|
||||
Logger.d(TAG, "sdk - start");
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
LocationManager.getInstance().stop();
|
||||
Logger.d(TAG, "sdk - stop");
|
||||
}
|
||||
|
||||
public void init(Context context) {
|
||||
LocationManager.getInstance().init(context);
|
||||
Logger.d(TAG, "sdk - init");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,126 @@
|
||||
package com.mogo.cloud.location;
|
||||
|
||||
import com.elegant.spi.annotations.Service;
|
||||
import com.mogo.cloud.location.third.core.LocationServiceProvider;
|
||||
|
||||
@Service(value = LocationServiceProvider.class)
|
||||
public class MogoLocationSource extends LocationServiceProvider {
|
||||
|
||||
@Override
|
||||
public float getBearing() {
|
||||
if (MogoLocationInfoServices.getInstance().getLocation() != null) {
|
||||
return MogoLocationInfoServices.getInstance().getLocation().getBearing();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getAccuracy() {
|
||||
if (MogoLocationInfoServices.getInstance().getLocation() != null) {
|
||||
return MogoLocationInfoServices.getInstance().getLocation().getAccuracy();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getProvider() {
|
||||
if (MogoLocationInfoServices.getInstance().getLocation() != null) {
|
||||
return MogoLocationInfoServices.getInstance().getLocation().getProvider();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getSpeed() {
|
||||
if (MogoLocationInfoServices.getInstance().getLocation() != null) {
|
||||
return MogoLocationInfoServices.getInstance().getLocation().getSpeed();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getAltitude() {
|
||||
if (MogoLocationInfoServices.getInstance().getLocation() != null) {
|
||||
return MogoLocationInfoServices.getInstance().getLocation().getAltitude();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAdCode() {
|
||||
if (MogoLocationInfoServices.getInstance().getLocation() != null) {
|
||||
return MogoLocationInfoServices.getInstance().getLocation().getAdCode();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getLocType() {
|
||||
if (MogoLocationInfoServices.getInstance().getLocation() != null) {
|
||||
return MogoLocationInfoServices.getInstance().getLocation().getLocType();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getLatitude() {
|
||||
if (MogoLocationInfoServices.getInstance().getLocation() != null) {
|
||||
return MogoLocationInfoServices.getInstance().getLocation().getLatitude();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getLongitude() {
|
||||
if (MogoLocationInfoServices.getInstance().getLocation() != null) {
|
||||
return MogoLocationInfoServices.getInstance().getLocation().getLongitude();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getTime() {
|
||||
if (MogoLocationInfoServices.getInstance().getLocation() != null) {
|
||||
return MogoLocationInfoServices.getInstance().getLocation().getTime();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCityCode() {
|
||||
if (MogoLocationInfoServices.getInstance().getLocation() != null) {
|
||||
return MogoLocationInfoServices.getInstance().getLocation().getCityCode();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCityName() {
|
||||
if (MogoLocationInfoServices.getInstance().getLocation() != null) {
|
||||
return MogoLocationInfoServices.getInstance().getLocation().getCityName();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getGpsAccuracyStatus() {
|
||||
if (MogoLocationInfoServices.getInstance().getLocation() != null) {
|
||||
return MogoLocationInfoServices.getInstance().getLocation().getGpsAccuracyStatus();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getSatellites() {
|
||||
if (MogoLocationInfoServices.getInstance().getLocation() != null) {
|
||||
return MogoLocationInfoServices.getInstance().getLocation().getSatellite();
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCarStatus() {
|
||||
// 常开状态
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
23
app/src/main/res/layout/activity_location.xml
Normal file
23
app/src/main/res/layout/activity_location.xml
Normal file
@@ -0,0 +1,23 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:orientation="vertical"
|
||||
tools:context=".LocationActivity">
|
||||
|
||||
<Button
|
||||
android:id="@+id/snapshotLocStart"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="20dp"
|
||||
android:text="开启定位上传" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/snapshotLocStop"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="20dp"
|
||||
android:text="结束定位上传" />
|
||||
|
||||
</LinearLayout>
|
||||
@@ -66,6 +66,12 @@
|
||||
android:layout_height="match_parent"
|
||||
android:text="实时数据测试" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnJumpLocation"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:text="每5秒上报" />
|
||||
|
||||
<Button
|
||||
android:id="@+id/btnJumpRoadcondition"
|
||||
android:layout_width="match_parent"
|
||||
|
||||
Reference in New Issue
Block a user