doWork() doesn't make what I want
I'm trying to make a background notification service, but anything I do on doWork doesn't work. I don't know that I do, I just put some logs for testing, but doesn't work too. I edit the MyService.java whitout IDE or whatever, could be that?
package com.red_folder.phonegap.plugin.backgroundservice.sample;
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 = "MILENA SERVICE";
private String mHelloTo = "Merda!!";
@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 = "QQQQQQQQQ - " + now;
result.put("Message", msg);
result.put("HUEHUE", msg);
Log.e("MilenaService", "QQQQQQQQQ - " + now);
Log.e("MilenaService", "NAO VAI ESSA MERDA DE APP");
Log.e("MilenaService", "Service");
Log.e("MilenaService", msg);
} catch (JSONException e) {
Log.e("MilenaService", e.getMessage());
}
return result;
}
@Override
protected JSONObject getConfig() {
JSONObject result = new JSONObject();
try {
result.put("HelloTo", this.mHelloTo);
result.put("HUEHUE", "QQQQQQQQQ -");
} 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
}
}
I assume you have built this out from bgp-sample? Was it working before you changed it?
It will be very difficult to provide any advice without an actual problem.
Yes, I used bgp-sample. Still working, but on the console it shows what you had in the bg-simple example instead of what I did
08-18 12:18:54.415 17240-17303/com.phonegap.helloworld D/MyService: Hello World - its currently 18/08/2017 12:18:54
08-18 12:19:54.415 17240-17303/com.phonegap.helloworld D/MyService: Hello World - its currently 18/08/2017 12:19:54
08-18 12:20:54.415 17240-17303/com.phonegap.helloworld D/MyService: Hello World - its currently 18/08/2017 12:20:54
08-18 12:21:54.415 17240-17303/com.phonegap.helloworld D/MyService: Hello World - its currently 18/08/2017 12:21:54
08-18 12:22:54.415 17240-17303/com.phonegap.helloworld D/MyService: Hello World - its currently 18/08/2017 12:22:54
08-18 12:23:54.415 17240-17303/com.phonegap.helloworld D/MyService: Hello World - its currently 18/08/2017 12:23:54
I'm sorry I don't understand
What is the question?
I changed doWork e execute apk on celphone, but it's still work like original bg-simple. I need to compile or something else for it execute the new doWork? Sorry, my english it's not very good.
Yes you will need to recompile to get any changes into your apk. You will also need to install that new apk to your cellphone to see the change there.
I suggest spending some time understanding the Android development process - otherwise you are likely to struggle.