Red-Folder / Cordova-Plugin-BackgroundService

BackroundService plugin for use with Cordova (PhoneGap)
144 stars 85 forks source link

"Class not found" error #27

Closed fsantoso closed 10 years ago

fsantoso commented 10 years ago

Hi Mark, as advised, here is the sample app that generates the "class not found" error. Greatly appreciate your help.

AndroidManifest

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.test_service" android:versionCode="1" android:versionName="1.0" >

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.test_service.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <service android:name="com.example.test_service.MyService">
    <intent-filter>         
        <action android:name="com.example.test_service.MyService"/> 
    </intent-filter>     
    </service>

    <receiver android:name="com.red_folder.phonegap.plugin.backgroundservice.BootReceiver">
    <intent-filter>     
        <action android:name="android.intent.action.BOOT_COMPLETED"></action>   
    </intent-filter> 
    </receiver>
</application>

Config

config

Index

<!DOCTYPE HTML>

MyService V3.1.0 ```

MyService V3.1.0

Service
Timer
Boot
Listen
Configuration
Hello To
Latest Result
```

MyService

package com.example.test_service;

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

}

}

Red-Folder commented 10 years ago

Did you amend myService-3.1.0.js to reflect the new namespace?

You'll need to amend to this:

cordova.define( 'cordova/plugin/myService', function(require, exports, module) {
CreateBackgroundService('com.example.test_service.MyService', require, exports, module); });

fsantoso commented 10 years ago

I have made such change and actually re-did the entire apps to follow your instructions exactly, but unfortunately the result remains the same. My LogCat doesn't show any of the BackgroundService actions.

log cat

I am using Cordova 3.2, would that affect anything at all?

Thanks a lot for your help.

Red-Folder commented 10 years ago

Take a look at your config.xml

You should have something similar to:

<feature name="BackgroundServicePlugin">
      <param name="android-package" value="com.red_folder.phonegap.plugin.backgroundservice.BackgroundServicePlugin"/>
</feature>

Your config.xml above doesn't look like the 3.x.x style - have you upgraded from a older version? Review the Cordova docs for the format.

Someone has used 3.1 with Cordova 3.2 before (I haven't personally). I doubt there will be problems.

fsantoso commented 10 years ago

It works now, thanks for pointing that out for me! Greatly appreciated.