Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
石璀亮
/
agenew_a16_sos
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit 8e9f813c
authored
Apr 22, 2019
by
cuiliang.shi
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
超时时间 15秒
1 parent
76f67bbc
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
100 additions
and
78 deletions
app/src/main/java/com/agenew/location_server/application/BirdService.java
app/src/main/java/com/agenew/location_server/application/BirdService.java
View file @
8e9f813
...
@@ -314,93 +314,115 @@ public class BirdService extends Service {
...
@@ -314,93 +314,115 @@ public class BirdService extends Service {
private
void
postLocationInfo
()
{
private
void
postLocationInfo
()
{
JSONObject
jsonBody
=
new
JSONObject
();
new
Thread
(
new
Runnable
()
{
try
{
jsonBody
.
put
(
"longitude"
,
mLongitude
);
jsonBody
.
put
(
"latitude"
,
mLatitude
);
jsonBody
.
put
(
"time"
,
mStartTime
);
jsonBody
.
put
(
"meid"
,
mIMEIStr
);
jsonBody
.
put
(
"tel"
,
mMobile
);
jsonBody
.
put
(
"iccid"
,
mICCIDStr
);
jsonBody
.
put
(
"imsi"
,
mIMSIStr
);
jsonBody
.
put
(
"model"
,
mModel
);
jsonBody
.
put
(
"cfgv"
,
ret_cfgv
);
jsonBody
.
put
(
"gcs"
,
"GCJ02"
);
}
catch
(
JSONException
x
)
{
x
.
printStackTrace
();
}
Log
.
d
(
TAG
,
"url: "
+
mPath
+
", jsonBody: "
+
jsonBody
.
toString
());
/* StringBuilder strbuf = new StringBuilder();
strbuf.append("longitude=" + mLongitude);
strbuf.append("&latitude=" + mLatitude);
strbuf.append("&time=" + mStartTime);
strbuf.append("&meid=" + mIMEIStr);
strbuf.append("&tel=" + mMobile);
strbuf.append("&iccid=" + mICCIDStr);
strbuf.append("&imsi=" + mIMSIStr);
strbuf.append("&model=" + mModel);
strbuf.append("&cfgv=" + ret_cfgv);
strbuf.append("&gcs=" + "GCJ02");
Log.d(TAG, "REQUEST: URL: " + mPath + ", BODY:" + strbuf);
IotApi.get(mPath + "?" + strbuf.toString(), new IotNetApiCallback(){*/
IotApi
.
postLocationInfo
(
mPath
,
jsonBody
,
new
IotNetApiCallback
()
{
@Override
@Override
public
void
onSuccess
(
String
response
)
{
public
void
run
()
{
Log
.
d
(
TAG
,
"server response: "
+
response
);
final
StringBuffer
strbuf
=
new
StringBuffer
();
mHasSendTheLocationInfo
=
true
;
strbuf
.
append
(
"longitude="
+
mLongitude
);
JsonObject
resp
=
new
JsonParser
().
parse
(
response
).
getAsJsonObject
();
strbuf
.
append
(
"&latitude="
+
mLatitude
);
strbuf
.
append
(
"&time="
+
mStartTime
);
ret_code
=
resp
.
get
(
"ret_code"
).
getAsInt
();
strbuf
.
append
(
"&meid="
+
mIMEIStr
);
if
(
ret_code
==
1
){
strbuf
.
append
(
"&tel="
+
mMobile
);
ret_cfgv
=
resp
.
get
(
"cfgv"
).
getAsString
();
strbuf
.
append
(
"&iccid="
+
mICCIDStr
);
mPath
=
resp
.
get
(
"url"
).
getAsString
();
strbuf
.
append
(
"&imsi="
+
mIMSIStr
);
Log
.
d
(
TAG
,
"new path: "
+
mPath
);
strbuf
.
append
(
"&model="
+
mModel
);
strbuf
.
append
(
"&cfgv="
+
ret_cfgv
);
if
(!
mPath
.
equals
(
"0"
)){
strbuf
.
append
(
"&gcs="
+
"GCJ02"
);
DevicePreferences
.
getInstance
(
mContext
).
putString
(
"bird_location_upload_url"
,
mPath
);
}
Log
.
d
(
TAG
,
"REQUEST: URL: "
+
mPath
+
", BODY:"
+
strbuf
);
int
timeSpanMinutes
=
resp
.
get
(
"time_span"
).
getAsInt
();
if
(
timeSpanMinutes
==
999999
){
URL
url
=
null
;
DevicePreferences
.
getInstance
(
mContext
).
putLong
(
"bird_location_upload_interval"
,
0
);
HttpURLConnection
httpURLConnection
=
null
;
}
else
if
(
timeSpanMinutes
==
0
){
OutputStream
os
=
null
;
Log
.
d
(
TAG
,
"time span not change"
);
try
{
}
else
{
url
=
new
URL
(
mPath
);
DevicePreferences
.
getInstance
(
mContext
).
putLong
(
"bird_location_upload_interval"
,
timeSpanMinutes
);
}
catch
(
Exception
e
)
{
}
e
.
printStackTrace
();
}
try
{
httpURLConnection
=
(
HttpURLConnection
)
url
.
openConnection
();
httpURLConnection
.
setRequestMethod
(
"POST"
);
httpURLConnection
.
setReadTimeout
(
15000
);
httpURLConnection
.
setDoOutput
(
true
);
httpURLConnection
.
setRequestProperty
(
"Charset"
,
"UTF-8"
);
httpURLConnection
.
setRequestProperty
(
"Content-Length"
,
strbuf
.
toString
().
length
()
+
""
);
os
=
httpURLConnection
.
getOutputStream
();
os
.
write
(
strbuf
.
toString
().
getBytes
());
os
.
flush
();
int
responseCode
=
httpURLConnection
.
getResponseCode
();
Log
.
d
(
TAG
,
"responseCode--"
+
responseCode
);
if
(
responseCode
==
HttpURLConnection
.
HTTP_OK
)
{
InputStreamReader
is
=
new
InputStreamReader
(
httpURLConnection
.
getInputStream
());
StringBuffer
sb
=
new
StringBuffer
();
int
i
=
0
;
while
((
i
=
is
.
read
())
!=
-
1
)
{
sb
.
append
((
char
)
i
);
}
is
.
close
();
DevicePreferences
.
getInstance
(
mContext
).
putString
(
"bird_ret_cfgv"
,
ret_cfgv
);
Log
.
d
(
TAG
,
"server response: "
+
sb
);
}
else
if
(
ret_code
==
0
){
JSONObject
jsonObject
=
new
JSONObject
(
sb
.
toString
());
Log
.
d
(
TAG
,
"upload success"
);
ret_code
=
jsonObject
.
getInt
(
"ret_code"
);
}
else
{
if
(
ret_code
==
1
){
Log
.
d
(
TAG
,
"upload failed"
);
ret_cfgv
=
jsonObject
.
getString
(
"cfgv"
);
}
mPath
=
jsonObject
.
getString
(
"url"
);
Log
.
d
(
TAG
,
"new path: "
+
mPath
);
setAlarm
();
if
(!
mPath
.
equals
(
"0"
)){
DevicePreferences
.
getInstance
(
mContext
).
putString
(
"bird_location_upload_url"
,
mPath
);
}
int
timeSpanMinutes
=
jsonObject
.
getInt
(
"time_span"
);
if
(
timeSpanMinutes
==
999999
){
DevicePreferences
.
getInstance
(
mContext
).
putLong
(
"bird_location_upload_interval"
,
0
);
}
else
if
(
timeSpanMinutes
==
0
){
Log
.
d
(
TAG
,
"time span not change"
);
}
else
{
DevicePreferences
.
getInstance
(
mContext
).
putLong
(
"bird_location_upload_interval"
,
timeSpanMinutes
);
}
// close gps & network.
DevicePreferences
.
getInstance
(
mContext
).
putString
(
"bird_ret_cfgv"
,
ret_cfgv
);
Intent
intent
=
new
Intent
(
"com.bird.close_gps_switch"
);
intent
.
addFlags
(
0x01000000
);
getApplicationContext
().
sendBroadcast
(
intent
);
}
}
else
if
(
ret_code
==
0
){
Log
.
d
(
TAG
,
"upload success"
);
}
else
{
Log
.
d
(
TAG
,
"upload failed"
);
}
@Override
}
else
if
(
responseCode
!=
200
)
{
public
void
onFailed
(
Exception
e
)
{
Log
.
d
(
TAG
,
"request failed"
);
Log
.
d
(
TAG
,
"onFailed Exception:"
+
e
.
toString
());
}
setAlarm
();
/*mErrorCount++;
setAlarm
();
if (mErrorCount > 5){
// close gps & network.
Intent
intent
=
new
Intent
(
"com.bird.close_gps_switch"
);
intent
.
addFlags
(
0x01000000
);
getApplicationContext
().
sendBroadcast
(
intent
);
}
catch
(
Exception
e
)
{
Log
.
d
(
TAG
,
"Exception:"
+
e
.
toString
());
setAlarm
();
setAlarm
();
}else{
mErrorCount
++;
long temp = DevicePreferences.getInstance(mContext).getLong("bird_location_upload_interval", DEFAULTINTERVAL);
if
(
mErrorCount
>
5
){
mErrorHandler.sendEmptyMessageDelayed(0, temp);
setAlarm
();
}*/
}
else
{
long
temp
=
DevicePreferences
.
getInstance
(
mContext
).
getLong
(
"bird_location_upload_interval"
,
DEFAULTINTERVAL
);
mErrorHandler
.
sendEmptyMessageDelayed
(
0
,
temp
);
}
}
finally
{
httpURLConnection
.
disconnect
();
Log
.
d
(
TAG
,
"close connect"
);
if
(
os
!=
null
)
{
try
{
os
.
close
();
}
catch
(
IOException
e
)
{
e
.
printStackTrace
();
}
}
}
}
}
});
})
.
start
()
;
}
}
private
void
initLocation
(
Context
context
)
{
private
void
initLocation
(
Context
context
)
{
...
...
Write
Preview
Markdown
is supported
Attach a file
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to post a comment