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
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
60 additions
and
38 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,24 +314,10 @@ public class BirdService extends Service {
private
void
postLocationInfo
()
{
JSONObject
jsonBody
=
new
JSONObject
();
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();
new
Thread
(
new
Runnable
()
{
@Override
public
void
run
()
{
final
StringBuffer
strbuf
=
new
StringBuffer
();
strbuf
.
append
(
"longitude="
+
mLongitude
);
strbuf
.
append
(
"&latitude="
+
mLatitude
);
strbuf
.
append
(
"&time="
+
mStartTime
);
...
...
@@ -344,25 +330,49 @@ public class BirdService extends Service {
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
public
void
onSuccess
(
String
response
)
{
Log
.
d
(
TAG
,
"server response: "
+
response
);
mHasSendTheLocationInfo
=
true
;
JsonObject
resp
=
new
JsonParser
().
parse
(
response
).
getAsJsonObject
();
ret_code
=
resp
.
get
(
"ret_code"
).
getAsInt
();
URL
url
=
null
;
HttpURLConnection
httpURLConnection
=
null
;
OutputStream
os
=
null
;
try
{
url
=
new
URL
(
mPath
);
}
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
();
Log
.
d
(
TAG
,
"server response: "
+
sb
);
JSONObject
jsonObject
=
new
JSONObject
(
sb
.
toString
());
ret_code
=
jsonObject
.
getInt
(
"ret_code"
);
if
(
ret_code
==
1
){
ret_cfgv
=
resp
.
get
(
"cfgv"
).
getAsString
(
);
mPath
=
resp
.
get
(
"url"
).
getAsString
(
);
ret_cfgv
=
jsonObject
.
getString
(
"cfgv"
);
mPath
=
jsonObject
.
getString
(
"url"
);
Log
.
d
(
TAG
,
"new path: "
+
mPath
);
if
(!
mPath
.
equals
(
"0"
)){
DevicePreferences
.
getInstance
(
mContext
).
putString
(
"bird_location_upload_url"
,
mPath
);
}
int
timeSpanMinutes
=
resp
.
get
(
"time_span"
).
getAsInt
(
);
int
timeSpanMinutes
=
jsonObject
.
getInt
(
"time_span"
);
if
(
timeSpanMinutes
==
999999
){
DevicePreferences
.
getInstance
(
mContext
).
putLong
(
"bird_location_upload_interval"
,
0
);
}
else
if
(
timeSpanMinutes
==
0
){
...
...
@@ -379,6 +389,10 @@ public class BirdService extends Service {
Log
.
d
(
TAG
,
"upload failed"
);
}
}
else
if
(
responseCode
!=
200
)
{
Log
.
d
(
TAG
,
"request failed"
);
}
setAlarm
();
// close gps & network.
...
...
@@ -386,21 +400,29 @@ public class BirdService extends Service {
intent
.
addFlags
(
0x01000000
);
getApplicationContext
().
sendBroadcast
(
intent
);
}
@Override
public
void
onFailed
(
Exception
e
)
{
Log
.
d
(
TAG
,
"onFailed Exception:"
+
e
.
toString
());
}
catch
(
Exception
e
)
{
Log
.
d
(
TAG
,
"Exception:"
+
e
.
toString
());
setAlarm
();
/*
mErrorCount++;
mErrorCount
++;
if
(
mErrorCount
>
5
){
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
)
{
...
...
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