Small changes and warning cleanup
Этот коммит содержится в:
+21
-12
@@ -1,22 +1,31 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
package="org.traccar.client"
|
package="org.traccar.client"
|
||||||
android:versionCode="6"
|
android:versionCode="6"
|
||||||
android:versionName="1.5">
|
android:versionName="1.5">
|
||||||
<application android:label="@string/app_name" android:icon="@drawable/ic_launcher">
|
|
||||||
<activity android:name="TraccarActivity"
|
<uses-sdk android:minSdkVersion="4" android:targetSdkVersion="17" />
|
||||||
android:label="@string/app_name"
|
|
||||||
android:windowSoftInputMode="stateHidden">
|
<uses-permission android:name="android.permission.READ_PHONE_STATE"></uses-permission>
|
||||||
|
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
|
||||||
|
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
|
||||||
|
|
||||||
|
<application android:label="@string/app_name" android:icon="@drawable/ic_launcher" android:allowBackup="true">
|
||||||
|
|
||||||
|
<activity
|
||||||
|
android:name="TraccarActivity"
|
||||||
|
android:label="@string/app_name"
|
||||||
|
android:windowSoftInputMode="stateHidden">
|
||||||
|
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
<category android:name="android.intent.category.LAUNCHER" />
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
|
|
||||||
</activity>
|
</activity>
|
||||||
|
|
||||||
<service android:name=".TraccarService" />
|
<service android:name=".TraccarService" />
|
||||||
|
|
||||||
</application>
|
</application>
|
||||||
<uses-sdk android:minSdkVersion="4"
|
|
||||||
android:targetSdkVersion="16" />
|
|
||||||
<uses-permission android:name="android.permission.READ_PHONE_STATE"></uses-permission>
|
|
||||||
<uses-permission android:name="android.permission.INTERNET"></uses-permission>
|
|
||||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"></uses-permission>
|
|
||||||
</manifest>
|
</manifest>
|
||||||
|
|||||||
@@ -11,4 +11,4 @@
|
|||||||
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
|
#proguard.config=${sdk.dir}/tools/proguard/proguard-android.txt:proguard-project.txt
|
||||||
|
|
||||||
# Project target.
|
# Project target.
|
||||||
target=android-16
|
target=Google Inc.:Google APIs:17
|
||||||
|
|||||||
@@ -15,12 +15,12 @@
|
|||||||
*/
|
*/
|
||||||
package org.traccar.client;
|
package org.traccar.client;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.OutputStream;
|
||||||
import java.net.*;
|
import java.net.Socket;
|
||||||
import java.util.*;
|
|
||||||
import android.os.Handler;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.os.Handler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Connection with autoreconnect
|
* Connection with autoreconnect
|
||||||
@@ -43,52 +43,52 @@ public class Connection {
|
|||||||
* Initialize connection parameters
|
* Initialize connection parameters
|
||||||
*/
|
*/
|
||||||
public Connection(String address, int port, String message) {
|
public Connection(String address, int port, String message) {
|
||||||
this.address = address;
|
this.address = address;
|
||||||
this.port = port;
|
this.port = port;
|
||||||
connectMessage = message;
|
connectMessage = message;
|
||||||
setStatus(Traccar.STATUS_DISCONNECTED);
|
setStatus(Traccar.STATUS_DISCONNECTED);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get address
|
* Get address
|
||||||
*/
|
*/
|
||||||
public String getAddress() {
|
public String getAddress() {
|
||||||
return address;
|
return address;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get port
|
* Get port
|
||||||
*/
|
*/
|
||||||
public int getPort() {
|
public int getPort() {
|
||||||
return port;
|
return port;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set context
|
* Set context
|
||||||
*/
|
*/
|
||||||
public void setContext(Context context) {
|
public void setContext(Context context) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set connection status
|
* Set connection status
|
||||||
*/
|
*/
|
||||||
private void setStatus(String status) {
|
private void setStatus(String status) {
|
||||||
if (!status.equals(this.status)) {
|
if (!status.equals(this.status)) {
|
||||||
this.status = status;
|
this.status = status;
|
||||||
if (context != null) {
|
if (context != null) {
|
||||||
Intent intent = new Intent(Traccar.MSG_CONNECTION_STATUS);
|
Intent intent = new Intent(Traccar.MSG_CONNECTION_STATUS);
|
||||||
intent.putExtra(Traccar.EXTRA_STATUS, status);
|
intent.putExtra(Traccar.EXTRA_STATUS, status);
|
||||||
context.sendBroadcast(intent);
|
context.sendBroadcast(intent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get connection status
|
* Get connection status
|
||||||
*/
|
*/
|
||||||
public String getStatus() {
|
public String getStatus() {
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -124,7 +124,7 @@ public class Connection {
|
|||||||
* Close connection
|
* Close connection
|
||||||
*/
|
*/
|
||||||
public void close() {
|
public void close() {
|
||||||
handler.removeCallbacks(task);
|
handler.removeCallbacks(task);
|
||||||
if (socket != null) {
|
if (socket != null) {
|
||||||
try {
|
try {
|
||||||
socket.close();
|
socket.close();
|
||||||
@@ -137,7 +137,7 @@ public class Connection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void reconnect() {
|
private void reconnect() {
|
||||||
close();
|
close();
|
||||||
handler.postDelayed(task, Traccar.RECONNECT_DELAY);
|
handler.postDelayed(task, Traccar.RECONNECT_DELAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,11 +17,12 @@ package org.traccar.client;
|
|||||||
|
|
||||||
import java.util.Formatter;
|
import java.util.Formatter;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
import android.location.Location;
|
import android.location.Location;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Protocol formatting
|
* Protocol formatting
|
||||||
*/
|
*/
|
||||||
public class Protocol {
|
public class Protocol {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -38,6 +39,7 @@ public class Protocol {
|
|||||||
checksum ^= b;
|
checksum ^= b;
|
||||||
}
|
}
|
||||||
f.format("*%02x\r\n", (int) checksum);
|
f.format("*%02x\r\n", (int) checksum);
|
||||||
|
f.close();
|
||||||
|
|
||||||
return s.toString();
|
return s.toString();
|
||||||
}
|
}
|
||||||
@@ -64,6 +66,7 @@ public class Protocol {
|
|||||||
checksum ^= b;
|
checksum ^= b;
|
||||||
}
|
}
|
||||||
f.format("*%02x\r\n", (int) checksum);
|
f.format("*%02x\r\n", (int) checksum);
|
||||||
|
f.close();
|
||||||
|
|
||||||
return s.toString();
|
return s.toString();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,23 +15,25 @@
|
|||||||
*/
|
*/
|
||||||
package org.traccar.client;
|
package org.traccar.client;
|
||||||
|
|
||||||
import java.io.*;
|
|
||||||
import java.net.*;
|
|
||||||
import java.util.*;
|
|
||||||
import android.app.Service;
|
import android.app.Service;
|
||||||
import android.content.*;
|
import android.content.BroadcastReceiver;
|
||||||
import android.location.*;
|
import android.content.Context;
|
||||||
import android.os.*;
|
import android.content.Intent;
|
||||||
|
import android.content.IntentFilter;
|
||||||
|
import android.location.Location;
|
||||||
|
import android.location.LocationListener;
|
||||||
|
import android.location.LocationManager;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.os.IBinder;
|
||||||
import android.telephony.TelephonyManager;
|
import android.telephony.TelephonyManager;
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Background service
|
* Background service
|
||||||
*/
|
*/
|
||||||
public class TraccarService extends Service implements LocationListener {
|
public class TraccarService extends Service implements LocationListener {
|
||||||
|
|
||||||
private int period;
|
private int period;
|
||||||
private String deviceId;
|
private String deviceId;
|
||||||
private Connection connection;
|
private Connection connection;
|
||||||
private LocationManager locationManager;
|
private LocationManager locationManager;
|
||||||
|
|
||||||
@@ -63,33 +65,34 @@ public class TraccarService extends Service implements LocationListener {
|
|||||||
private String status;
|
private String status;
|
||||||
|
|
||||||
private void setStatus(String status) {
|
private void setStatus(String status) {
|
||||||
if (!status.equals(this.status)) {
|
if (!status.equals(this.status)) {
|
||||||
this.status = status;
|
this.status = status;
|
||||||
Intent intent = new Intent(Traccar.MSG_SERVICE_STATUS);
|
Intent intent = new Intent(Traccar.MSG_SERVICE_STATUS);
|
||||||
intent.putExtra(Traccar.EXTRA_STATUS, status);
|
intent.putExtra(Traccar.EXTRA_STATUS, status);
|
||||||
sendBroadcast(intent);
|
sendBroadcast(intent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private BroadcastReceiver updateReceiver = new BroadcastReceiver() {
|
private BroadcastReceiver updateReceiver = new BroadcastReceiver() {
|
||||||
public void onReceive(Context context, Intent intent) {
|
@Override
|
||||||
// Send config
|
public void onReceive(Context context, Intent intent) {
|
||||||
intent = new Intent(Traccar.MSG_SERVICE_CONFIG);
|
// Send config
|
||||||
intent.putExtra(Traccar.EXTRA_ADDRESS, connection.getAddress());
|
intent = new Intent(Traccar.MSG_SERVICE_CONFIG);
|
||||||
intent.putExtra(Traccar.EXTRA_PORT, connection.getPort());
|
intent.putExtra(Traccar.EXTRA_ADDRESS, connection.getAddress());
|
||||||
intent.putExtra(Traccar.EXTRA_PERIOD, period);
|
intent.putExtra(Traccar.EXTRA_PORT, connection.getPort());
|
||||||
sendBroadcast(intent);
|
intent.putExtra(Traccar.EXTRA_PERIOD, period);
|
||||||
|
sendBroadcast(intent);
|
||||||
|
|
||||||
// Send service status
|
// Send service status
|
||||||
intent = new Intent(Traccar.MSG_SERVICE_STATUS);
|
intent = new Intent(Traccar.MSG_SERVICE_STATUS);
|
||||||
intent.putExtra(Traccar.EXTRA_STATUS, status);
|
intent.putExtra(Traccar.EXTRA_STATUS, status);
|
||||||
sendBroadcast(intent);
|
sendBroadcast(intent);
|
||||||
|
|
||||||
// Send connection status
|
// Send connection status
|
||||||
intent = new Intent(Traccar.MSG_CONNECTION_STATUS);
|
intent = new Intent(Traccar.MSG_CONNECTION_STATUS);
|
||||||
intent.putExtra(Traccar.EXTRA_STATUS, connection.getStatus());
|
intent.putExtra(Traccar.EXTRA_STATUS, connection.getStatus());
|
||||||
sendBroadcast(intent);
|
sendBroadcast(intent);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -98,20 +101,20 @@ public class TraccarService extends Service implements LocationListener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int onStartCommand(Intent intent, int flags, int startId) {
|
public int onStartCommand(Intent intent, int flags, int startId) {
|
||||||
// Read device id
|
// Read device id
|
||||||
TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
|
TelephonyManager telephonyManager = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
|
||||||
deviceId = telephonyManager.getDeviceId();
|
deviceId = telephonyManager.getDeviceId();
|
||||||
|
|
||||||
// Create connection
|
// Create connection
|
||||||
connection = new Connection(
|
connection = new Connection(
|
||||||
intent.getStringExtra(Traccar.EXTRA_ADDRESS),
|
intent.getStringExtra(Traccar.EXTRA_ADDRESS),
|
||||||
intent.getIntExtra(Traccar.EXTRA_PORT, 0),
|
intent.getIntExtra(Traccar.EXTRA_PORT, 0),
|
||||||
Protocol.createId(deviceId));
|
Protocol.createId(deviceId));
|
||||||
connection.setContext(this);
|
connection.setContext(this);
|
||||||
connection.connect();
|
connection.connect();
|
||||||
|
|
||||||
// Request location updates
|
// Request location updates
|
||||||
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
|
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
|
||||||
period = intent.getIntExtra(Traccar.EXTRA_PERIOD, 0);
|
period = intent.getIntExtra(Traccar.EXTRA_PERIOD, 0);
|
||||||
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, period * 1000, 0, this);
|
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, period * 1000, 0, this);
|
||||||
|
|
||||||
@@ -123,15 +126,15 @@ public class TraccarService extends Service implements LocationListener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDestroy() {
|
public void onDestroy() {
|
||||||
// Close connection
|
// Close connection
|
||||||
if (connection != null) {
|
if (connection != null) {
|
||||||
connection.close();
|
connection.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Stop location updates
|
// Stop location updates
|
||||||
if (locationManager != null) {
|
if (locationManager != null) {
|
||||||
locationManager.removeUpdates(this);
|
locationManager.removeUpdates(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Report status
|
// Report status
|
||||||
unregisterReceiver(updateReceiver);
|
unregisterReceiver(updateReceiver);
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user