我制作移动丢失的gps跟踪应用程序,该代码将仅在活动中运行..
我的应用策略是。
1)如果找到http://192.168.43.164/imei_000000000000000.txt
文件,则查找
imei_000000000000000.txt
中的“track”或“find_mobile”字符串。
2)如果在imei_000000000000000.txt
文件中找到“track”或“find_mobile”字符串,则发布
“http://192.168.43.164/add.php?long_itude=22.00023&lat_itude=22.00023”。链路
ScheduledExecutorService scheduler = Executors.newSingleThreadScheduledExecutor();
scheduler.scheduleAtFixedRate(new Runnable() {
@Override
public void run() {
new Thread(new Runnable() {
@Override
public void run() {
final ArrayList<String> urls = new ArrayList<String>();
try{
URL url = new URL("http://192.168.43.164/imei_000000000000000.txt");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setConnectTimeout(60000);
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String str;
while ((str = in.readLine()) != null)
{
urls.add(str);
}
in.close();
} catch (Exception e){
e.printStackTrace();
}
runOnUiThread(new Runnable() {
@Override
public void run() {
li = urls.get(0);
if (li.equals("track") || li.equals("find_mobile")) {
try{
URL url = new URL("http://192.168.43.164/add.php?long_itude=22.00023&lat_itude=22.00023");
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setConnectTimeout(60000);
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String str;
while ((str = in.readLine()) != null)
{
urls.add(str);
}
in.close();
} catch (Exception e){
e.printStackTrace();
}
Toast.makeText(getBaseContext(), "hello", Toast.LENGTH_SHORT).show();
}
else{
Toast.makeText(getBaseContext(), "not found"+ li, Toast.LENGTH_SHORT).show();
}
}
} );
}
}).start();
}
},5,5, TimeUnit.SECONDS);
发布的代码可以正常工作,但它的代码仅适用于活动。
我想制作代码背景并在不关闭的情况下连续运行。
答案 0 :(得分:-1)
使用新线程=(线程)函数