I have a Cordova plugin which runs a laser scanner on a device, whose Main.java looks like this:
package com.example.plugin;
import org.apache.cordova.*;
import org.json.JSONArray;
import org.json.JSONException;
import java.security.PublicKey;
import android.os.Bundle;
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.util.Log;
public class Hello extends CordovaPlugin {
public static final int REQUEST_CODE = 0x0ba7c0de;
@Override
public boolean execute(String action, JSONArray data, CallbackContext callbackContext) throws JSONException {
if (action.equals("scan")) {
scan();
return true;
} else {
return false;
}
}
public void scan() {
Intent intentService = new Intent("com.hyipc.core.service.barcode.BarcodeService2D");
intentService.putExtra("KEY_ACTION", "UP");
this.cordova.startActivityForResult((CordovaPlugin) this, intentService, REQUEST_CODE);
}
@Override
public void onActivityResult(int requestCode, int resultCode, Intent intent) {
Log.i("scan", "everything works fine");
}
}
When I run the plugin, I get this in the error log:
07-11 12:03:33.541: E/AndroidRuntime(5258): FATAL EXCEPTION: main
07-11 12:03:33.541: E/AndroidRuntime(5258): java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{com.ionicframework.curierapp266167/com.hyipc.core.service.barcode.BarcodeService2D}: java.lang.ClassNotFoundException: Didn't find class "com.hyipc.core.service.barcode.BarcodeService2D" on path: DexPathList[[zip file "/data/app/com.ionicframework.curierapp266167-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.ionicframework.curierapp266167-2, /vendor/lib, /system/lib]]
07-11 12:03:33.541: E/AndroidRuntime(5258): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2269)
07-11 12:03:33.541: E/AndroidRuntime(5258): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2395)
07-11 12:03:33.541: E/AndroidRuntime(5258): at android.app.ActivityThread.access$600(ActivityThread.java:162)
07-11 12:03:33.541: E/AndroidRuntime(5258): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1364)
07-11 12:03:33.541: E/AndroidRuntime(5258): at android.os.Handler.dispatchMessage(Handler.java:107)
07-11 12:03:33.541: E/AndroidRuntime(5258): at android.os.Looper.loop(Looper.java:194)
07-11 12:03:33.541: E/AndroidRuntime(5258): at android.app.ActivityThread.main(ActivityThread.java:5392)
07-11 12:03:33.541: E/AndroidRuntime(5258): at java.lang.reflect.Method.invokeNative(Native Method)
07-11 12:03:33.541: E/AndroidRuntime(5258): at java.lang.reflect.Method.invoke(Method.java:525)
07-11 12:03:33.541: E/AndroidRuntime(5258): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:833)
07-11 12:03:33.541: E/AndroidRuntime(5258): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:600)
07-11 12:03:33.541: E/AndroidRuntime(5258): at dalvik.system.NativeStart.main(Native Method)
07-11 12:03:33.541: E/AndroidRuntime(5258): Caused by: java.lang.ClassNotFoundException: Didn't find class "com.hyipc.core.service.barcode.BarcodeService2D" on path: DexPathList[[zip file "/data/app/com.ionicframework.curierapp266167-2.apk"],nativeLibraryDirectories=[/data/app-lib/com.ionicframework.curierapp266167-2, /vendor/lib, /system/lib]]
I have added this to my AndroidManifest.xml file, but I am pretty certain something's wrong with it.
<activity android:label="@string/share_name" android:name="com.hyipc.core.service.barcode.BarcodeService2D">
<intent-filter>
<action android:name="com.hyipc.core.service.barcode.BarcodeService2D" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
EDIT
If i edit my manifest file to this, I get No Activity found to handle Intent error.
<activity android:label="@string/share_name" android:name="com.hyipc.core.service.barcode.BarcodeService2D">
<intent-filter>
<action android:name="android.intent.action.LAUNCH" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
Also, if I try to start the activity like this:
cordova.getActivity().startService(intentService);
The scanner starts without error, but I don't know how to get its result.