mirror of
https://github.com/purplecabbage/phonegap-plugins.git
synced 2026-01-14 08:57:53 -05:00
new file: Android/BackgroundService/2.0.0/README.md new file: Android/BackgroundService/2.0.0/backgroundService-2.0.0.js new file: Android/BackgroundService/2.0.0/backgroundserviceplugin-2.0.0.jar new file: Android/BackgroundService/2.0.0/index-2.0.0.html new file: Android/BackgroundService/2.0.0/myService-2.0.0.js modified: Android/BackgroundService/README.md
79 lines
1.5 KiB
Java
79 lines
1.5 KiB
Java
package com.yournamespace.yourappname;
|
|
|
|
import java.text.SimpleDateFormat;
|
|
import java.util.Date;
|
|
|
|
import org.json.JSONException;
|
|
import org.json.JSONObject;
|
|
|
|
import android.util.Log;
|
|
|
|
import com.red_folder.phonegap.plugin.backgroundservice.BackgroundService;
|
|
|
|
public class MyService extends BackgroundService {
|
|
|
|
private final static String TAG = MyService.class.getSimpleName();
|
|
|
|
private String mHelloTo = "World";
|
|
|
|
@Override
|
|
protected JSONObject doWork() {
|
|
JSONObject result = new JSONObject();
|
|
|
|
try {
|
|
SimpleDateFormat df = new SimpleDateFormat("dd/MM/yyyy HH:mm:ss");
|
|
String now = df.format(new Date(System.currentTimeMillis()));
|
|
|
|
String msg = "Hello " + this.mHelloTo + " - its currently " + now;
|
|
result.put("Message", msg);
|
|
|
|
Log.d(TAG, msg);
|
|
} catch (JSONException e) {
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
@Override
|
|
protected JSONObject getConfig() {
|
|
JSONObject result = new JSONObject();
|
|
|
|
try {
|
|
result.put("HelloTo", this.mHelloTo);
|
|
} catch (JSONException e) {
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
@Override
|
|
protected void setConfig(JSONObject config) {
|
|
try {
|
|
if (config.has("HelloTo"))
|
|
this.mHelloTo = config.getString("HelloTo");
|
|
} catch (JSONException e) {
|
|
}
|
|
|
|
}
|
|
|
|
@Override
|
|
protected JSONObject initialiseLatestResult() {
|
|
// TODO Auto-generated method stub
|
|
return null;
|
|
}
|
|
|
|
@Override
|
|
protected void onTimerEnabled() {
|
|
// TODO Auto-generated method stub
|
|
|
|
}
|
|
|
|
@Override
|
|
protected void onTimerDisabled() {
|
|
// TODO Auto-generated method stub
|
|
|
|
}
|
|
|
|
|
|
}
|