package edu.berkeley.eecs.emission.cordova.launchnative;

import org.apache.cordova.*;
import org.json.JSONArray;
import org.json.JSONException;
import android.content.Intent;

public class LaunchNative extends CordovaPlugin {

    @Override
    public boolean execute(String action, JSONArray data, CallbackContext callbackContext) throws JSONException {
        if (action.equals("launch")) {
            java.lang.Package pkg = cordova.getClass().getPackage();
            System.out.println("cordova has package name "+pkg);
            String activityName = data.getString(0);
            String fqcn = pkg.getName()+"."+activityName;
            System.out.println("FQCN = "+pkg.getName() + fqcn);
            try {
                Class fqClass = Class.forName(fqcn);
                Intent startIntent = new Intent(cordova.getActivity(), fqClass);
                cordova.getActivity().startActivity(startIntent);
                callbackContext.success("Launched activity " + activityName);
            } catch (ClassNotFoundException e) {
                callbackContext.error("Class "+fqcn+" not found, unable to launch");
            }
            return true;
        } else {
            return false;
        }
    }
}

@@ -404,29 +404,22 @@
     
-java.lang.Package pkg
+String pkgName
  = c
@@ -428,21 +428,24 @@
 dova.get
-Class
+Activity
 ().getPa
@@ -449,16 +449,20 @@
 tPackage
+Name
 ();%0A    
@@ -519,16 +519,20 @@
 me %22+pkg
+Name
 );%0A     
@@ -608,26 +608,20 @@
 cn = pkg
-.get
 Name
-()
 +%22.%22+act
@@ -676,23 +676,8 @@
 = %22+
-pkg.getName() +
  fqc
@@ -1021,24 +1021,61 @@
 eption e) %7B%0A
+                e.printStackTrace();%0A
             

Read the correct package name