Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SetConfig issue #3

Closed
amitashkenazi opened this issue Feb 14, 2014 · 9 comments
Closed

SetConfig issue #3

amitashkenazi opened this issue Feb 14, 2014 · 9 comments
Labels

Comments

@amitashkenazi
Copy link

I try to call the setConfiguration method.
I receive the following error when

console.log("Error: " + data.ErrorMessage)

02-14 12:31:21.519: I/chromium(19014): [INFO:CONSOLE(50)] "Error: undefined", source: file:///android_asset/www/js/service.js (50)
02-14 12:31:21.529: I/chromium(19014): [INFO:CONSOLE(51)] "

console.log(JSON.stringify(data));

{"TimerMilliseconds":60000,"LatestResult":{},"Configuration":{},"ErrorCode":-99,"Success":false,"RegisteredForBootStart":false,"TimerEnabled":false,"ServiceRunning":true}", source: file:///android_asset/www/js/service.js (51)

Can you tell me what is the reason for the error?

@Red-Folder
Copy link
Owner

Is there anything else within the logcat? I would expect to see further information in the logcat or within the data (which seems to be missing).

Within the logcat, look for either:

"Processing config JSON from background service failed"
or
"setConfiguration failed"

@amitashkenazi
Copy link
Author

Thank you for the quick response!
On the last failure I get the following:

02-14 16:17:00.279: D/ServiceDetails(19062): setConfiguration failed
02-14 16:17:00.279: D/ServiceDetails(19062): android.os.RemoteException
02-14 16:17:00.279: D/ServiceDetails(19062): at com.red_folder.phonegap.plugin.backgroundservice.BackgroundService$1.setConfiguration(BackgroundService.java:278)
02-14 16:17:00.279: D/ServiceDetails(19062): at com.red_folder.phonegap.plugin.backgroundservice.BackgroundServicePluginLogic$ServiceDetails.setConfiguration(BackgroundServicePluginLogic.java:400)
02-14 16:17:00.279: D/ServiceDetails(19062): at com.red_folder.phonegap.plugin.backgroundservice.BackgroundServicePluginLogic.execute(BackgroundServicePluginLogic.java:160)
02-14 16:17:00.279: D/ServiceDetails(19062): at com.red_folder.phonegap.plugin.backgroundservice.BackgroundServicePlugin$1.run(BackgroundServicePlugin.java:48)
02-14 16:17:00.279: D/ServiceDetails(19062): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
02-14 16:17:00.279: D/ServiceDetails(19062): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
02-14 16:17:00.279: D/ServiceDetails(19062): at java.lang.Thread.run(Thread.java:841)
02-14 16:17:00.449: I/chromium(19062): [INFO:CONSOLE(53)] "Error set config", source: file:///android_asset/www/js/service.js (53)
02-14 16:17:00.449: I/chromium(19062): [INFO:CONSOLE(54)] "Error: undefined", source: file:///android_asset/www/js/service.js (54)
02-14 16:17:00.449: I/chromium(19062): [INFO:CONSOLE(55)] "{"TimerMilliseconds":60000,"LatestResult":{},"Configuration":{},"ErrorCode":-99,"Success":false,"RegisteredForBootStart":false,"TimerEnabled":false,"ServiceRunning":true}", source: file:///android_asset/www/js/service.js (55)

@Red-Folder
Copy link
Owner

Could you provide the contents of the setConfig() from your service class (equivalent of MyService.java)?

I suspect it is throwing an error while processing your config which is not being handled locally (with setConfig) thus is being returned to the plugin as a RemoteException.

@amitashkenazi
Copy link
Author

java side:
protected void setConfig(JSONObject config) {
fifo = new LinkedList();
boolean pubnubFlag = false;
try {
if (config.has("pubnub")){
if(config.getString("pubnub").equals("active")) {
pubnubFlag = true;
String notifyMessage = "";
//notifyUserBigView(notifyMessage);

            } else {
                pubnubFlag = false;
            }
            if(config.getString("pubnub").equals("on")) {
                notifyUserService();
            }

        }

    } catch (JSONException e) {
    }
    if(pubnubFlag) {
        subscribe();            
    }else{
        pubnub.unsubscribe("hello");    
    }

    Log.d(TAG, "get config");

}     

@Red-Folder
Copy link
Owner

I'd suspect that your getting an exception in there. First I'd comment out the entire contents of the setConfig to confirm it is causing the exception.

Assuming it is;

Add a Log.d on the JSONException block. Also add try/ catch round your subscribe/ unsubscribe. Basically saturate the method with Log.d to narrow down what is throwing the exception

@amitashkenazi
Copy link
Author

OK.
I tried to take it step by step.
The first thing that I added to the setConfig function which cause the Error was the "notifyUserService();" function
This function trigger a notification as followed:

private void notifyUserService() {

    Intent i = new Intent();
    i.setAction("com....");
    i.putExtra("id", Integer.toString(NOTIFICATION_ID));
    PendingIntent resultPendingIntent = PendingIntent.getBroadcast(this, 0, i,PendingIntent.FLAG_CANCEL_CURRENT );
    Uri uri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this).
            setSmallIcon(R.drawable.logo2).
            setContentTitle("....").
            setContentText(".....");
    mBuilder.setContentIntent(resultPendingIntent);
    final Notification notification = mBuilder.build();
    startForeground(NOTIFICATION_ID, notification);
    notification.notify();

}

This caused the error:

02-15 00:03:59.209: D/ServiceDetails(12580): setConfiguration failed
02-15 00:03:59.209: D/ServiceDetails(12580): android.os.RemoteException
02-15 00:03:59.209: D/ServiceDetails(12580): at com.red_folder.phonegap.plugin.backgroundservice.BackgroundService$1.setConfiguration(BackgroundService.java:278)
02-15 00:03:59.209: D/ServiceDetails(12580): at com.red_folder.phonegap.plugin.backgroundservice.BackgroundServicePluginLogic$ServiceDetails.setConfiguration(BackgroundServicePluginLogic.java:400)
02-15 00:03:59.209: D/ServiceDetails(12580): at com.red_folder.phonegap.plugin.backgroundservice.BackgroundServicePluginLogic.execute(BackgroundServicePluginLogic.java:160)
02-15 00:03:59.209: D/ServiceDetails(12580): at com.red_folder.phonegap.plugin.backgroundservice.BackgroundServicePlugin$1.run(BackgroundServicePlugin.java:48)
02-15 00:03:59.209: D/ServiceDetails(12580): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
02-15 00:03:59.209: D/ServiceDetails(12580): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
02-15 00:03:59.209: D/ServiceDetails(12580): at java.lang.Thread.run(Thread.java:841)
02-15 00:03:59.249: I/chromium(12580): [INFO:CONSOLE(51)] "Error set config", source: file:///android_asset/www/js/service.js (51)
02-15 00:03:59.249: I/chromium(12580): [INFO:CONSOLE(52)] "Error: undefined", source: file:///android_asset/www/js/service.js (52)
02-15 00:03:59.249: I/chromium(12580): [INFO:CONSOLE(53)] "{"TimerMilliseconds":60000,"LatestResult":{},"Configuration":{},"ErrorCode":-99,"Success":false,"RegisteredForBootStart":false,"TimerEnabled":false,"ServiceRunning":true}", source: file:///android_asset/www/js/service.js (53)

@Red-Folder
Copy link
Owner

You could really do with getting the actual exception. If you wrap you notifications function with a try/ catch then log.d the exception message and stack trade that will help identify why your code is failing.

@amitashkenazi
Copy link
Author

I fixed it!
added synchronized before firing the notification,
synchronized(notification){
notification.notify();
}

@Red-Folder
Copy link
Owner

Good to here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants