bgs-core icon indicating copy to clipboard operation
bgs-core copied to clipboard

doWork() doesn't make what I want

Open milenacarolinelt opened this issue 8 years ago • 5 comments

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
		
	}


}

milenacarolinelt avatar Aug 18 '17 11:08 milenacarolinelt

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.

Red-Folder avatar Aug 18 '17 12:08 Red-Folder

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

milenacarolinelt avatar Aug 18 '17 15:08 milenacarolinelt

I'm sorry I don't understand

What is the question?

Red-Folder avatar Aug 18 '17 15:08 Red-Folder

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.

milenacarolinelt avatar Aug 18 '17 17:08 milenacarolinelt

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.

Red-Folder avatar Aug 22 '17 14:08 Red-Folder