我收到错误:
Syntax error on token ",", < expected & Syntax error on tokens, ConstructorHeaderName expected instead
在线上:
}, delay_interval, period);
我很确定某些东西嵌套不正确 - 但我不确定它到底是什么。
来源:
public class DataCountService extends Service {
String text = "USR;1";
String ERROR = Constants.PREFS_NAME;
private Timer timer = new Timer();
private long period;
private long delay_interval;
private long sms_timer;
private long sms_period;
private DeviceManagerUtilities dmUtilities = new DeviceManagerUtilities();
private Context ctx;
private Bundle extras;
@SuppressWarnings("unused")
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.d(Constants.TAG, "Logging Service Started");
extras = intent.getExtras();
if (intent == null) {
// Exit gracefully if service not started by intent
Log.d(Constants.TAG, "Error: Null Intent");
} else {
if (extras != null) {
if (extras.getString(Constants.DM_SMS_CONTENT).contains(
"//USR;1")
&& (extras.getString(Constants.PREFS_KEY_CALL_MADE)
.contains("TRUE"))) {
// set status to enabled
SharedPreferences settings = getApplicationContext()
.getSharedPreferences(Constants.PREFS_NAME, 0);
Editor editor = settings.edit();
editor.putString("status", "1");
editor.commit();
}
if (extras.getString(Constants.DM_SMS_CONTENT).contains(
"//USR;0")
|| (extras.getString(Constants.PREFS_KEY_CALL_MADE)
.contains("FALSE"))) {
// set status to disabled
SharedPreferences settings = getApplicationContext()
.getSharedPreferences(Constants.PREFS_NAME, 0);
Editor editor = settings.edit();
editor.putString("status", "0");
editor.commit();
}
sendSMS();
}
}
return START_STICKY;
}
private void sendSMS() {
// check enabled / disabled status
SharedPreferences settings = getApplicationContext()
.getSharedPreferences(Constants.PREFS_NAME, 0);
if (settings.getString("status", "0").equals(1)) {
// check to ensure proper amount of time has lapsed
// get current time
long currentTimeMillis = System.currentTimeMillis() % 1000;
// get the timestamp from the last time an SMS was sent
long smsTimeStamp = settings.getLong("smstimestamp",
System.currentTimeMillis());
// compare the two values to check to ensure proper amount of time has lapsed
if (currentTimeMillis - smsTimeStamp > sms_timer) {
final String newMdn = dmUtilities.swappedMdn(this);
// get Wifi and Mobile traffic info
double totalBytes = (double) TrafficStats.getTotalRxBytes()
+ TrafficStats.getTotalTxBytes();
double mobileBytes = TrafficStats.getMobileRxBytes()
+ TrafficStats.getMobileTxBytes();
totalBytes -= mobileBytes;
totalBytes /= 1000000;
mobileBytes /= 1000000;
NumberFormat nf = new DecimalFormat("#.###");
// get the date
SimpleDateFormat s = new SimpleDateFormat("hh/mm/ss/MM/dd/yy");
String tag = ";";
// String mdn =
// extras.getString(DataCountUtilities.swappedMdn(this));
String mobileStr = nf.format(mobileBytes);
String totalStr = nf.format(totalBytes);
String DToDevice = s.format(new Date());
String status = (settings.getString("status", "0"));
String info = String.format("USI%sCN%s,WN%s", tag + status + tag
+ settings.getString("0", newMdn) + tag + DToDevice + tag,
mobileStr, totalStr + settings.getString("last_month", ""));
String lastMonth = String
.format("CO" + mobileStr + "WO" + totalStr);
// save Network and Wifi data in sharedPreferences
Editor editor = settings.edit();
editor.putString("last_month", lastMonth);
editor.commit();
// set status to enabled
editor.putString("status", "1");
editor.commit();
editor.putLong("smstimestamp", System.currentTimeMillis());
editor.commit();
// send traffic info via sms & save the current time
SmsManager smsManager = SmsManager.getDefault();
if (Config.DEVELOPMENT) {
String shortCode = settings.getString(
Constants.PREFS_KEY_SHORT_CODE,
Constants.DEFAULT_SHORT_CODE);
smsManager.sendTextMessage(shortCode, null, info, null, null);
} else {
SmsManager ackSMS = SmsManager.getDefault();
smsManager.sendTextMessage(Constants.DEFAULT_SHORT_CODE, null,
info, null, null);
}
}
}
}
@Override
public void onCreate() {
ctx = this;
if (!Config.DEVELOPMENT) {
period = Constants.PERIOD;
delay_interval = Constants.DELAY_INTERVAL;
sms_timer = Constants.SMS_TIMER;
} else {
period = Constants.DEBUG_PERIOD;
delay_interval = Constants.DEBUG_DELAY_INTERVAL;
sms_timer = Constants.DEBUG_SMS_TIMER;
}
startServiceTimer();
}
private void startServiceTimer() {
timer.schedule(new TimerTask() {
public void run() {
// send sms
sendSMS();
}
}
}, delay_interval, period);
@Override
public IBinder onBind(Intent intent) {
// TODO Auto-generated method stub
return null;
}
@Override
public boolean onUnbind(Intent intent) {
// TODO Auto-generated method stub
return super.onUnbind(intent);
}
}