Alexandru Pufan Alexandru Pufan - 1 year ago 88
Android Question

Give activity permission in AndroidManifest

I have a Cordova plugin which runs a laser scanner on a device, whose looks like this:

package com.example.plugin;

import org.apache.cordova.*;
import org.json.JSONArray;
import org.json.JSONException;


import android.os.Bundle;
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;

public boolean execute(String action, JSONArray data, CallbackContext callbackContext) throws JSONException {

if (action.equals("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);

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
07-11 12:03:33.541: E/AndroidRuntime(5258): at
07-11 12:03:33.541: E/AndroidRuntime(5258): at$600(
07-11 12:03:33.541: E/AndroidRuntime(5258): at$H.handleMessage(
07-11 12:03:33.541: E/AndroidRuntime(5258): at android.os.Handler.dispatchMessage(
07-11 12:03:33.541: E/AndroidRuntime(5258): at android.os.Looper.loop(
07-11 12:03:33.541: E/AndroidRuntime(5258): at
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(
07-11 12:03:33.541: E/AndroidRuntime(5258): at$
07-11 12:03:33.541: E/AndroidRuntime(5258): at
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">
<action android:name="com.hyipc.core.service.barcode.BarcodeService2D" />
<category android:name="android.intent.category.DEFAULT" />


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">
<action android:name="android.intent.action.LAUNCH" />
<category android:name="android.intent.category.DEFAULT" />

Also, if I try to start the activity like this:


The scanner starts without error, but I don't know how to get its result.

Answer Source

From the discussion in the comment list we know that BarcodeService2D, is a Service, and you can start the component using startService successfully. Now the question becomes "How can I pass data from my service to an Activity instance" ? There're so many answers in StackOverflow, see this and this. Just google for it.

And for the question "So a service is different from an activity?", the answer is yes. An Activity usually represents a screen in an app. It holds a variety of View, Drawable and many other stuff and you can interact with it directly. A Service is normally used to do a long running task in the background without any UI. For the detail information, see the developer site