Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/345.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Cordova 3.x的插件开发_Java_Javascript_Android_Cordova - Fatal编程技术网

Java Cordova 3.x的插件开发

Java Cordova 3.x的插件开发,java,javascript,android,cordova,Java,Javascript,Android,Cordova,我正在尝试为Android开发一个iBeacon Cordova 3.x插件,但是它不起作用。我不断得到以下错误: Error adding plugin me.habel.plugins.IBeacon.IBeacon exec() call to unknown plugin: IBeacon Error: Class not found 我的目录结构如下: MyiBeaconsPlugin + src + android - IBeacon.java + www

我正在尝试为Android开发一个iBeacon Cordova 3.x插件,但是它不起作用。我不断得到以下错误:

 Error adding plugin me.habel.plugins.IBeacon.IBeacon
 exec() call to unknown plugin: IBeacon
 Error: Class not found
我的目录结构如下:

MyiBeaconsPlugin
 + src
  + android
   - IBeacon.java
 + www
  - ibeacon.js
 - plugin.xml
IBeacon.java文件的源代码是:

package me.habel.plugins.IBeacon;

import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;

import com.radiusnetworks.ibeacon.IBeaconConsumer;
import com.radiusnetworks.ibeacon.IBeaconManager;

import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaPlugin;
import org.json.JSONArray;
import org.json.JSONException;

public class IBeacon extends CordovaPlugin implements IBeaconConsumer {
    private static String DEBUG_TAG = "iBeacon :: DEBUG => ";
    public static final String ACTION_VERIFY_BT = "verifyBluetooth";
    private IBeaconManager iBeaconManager = IBeaconManager
            .getInstanceForApplication(this.cordova.getActivity().getApplicationContext());

    @Override
    public boolean execute(String action, JSONArray args, CallbackContext callbackContext)
            throws JSONException {
        try {
            if (action.equalsIgnoreCase(ACTION_VERIFY_BT)) {
                verifyBluetooth();
                callbackContext.success();
                return true;
            }
        } catch (Exception e) {
            System.out.println(DEBUG_TAG + e.getMessage());
            callbackContext.error(e.getMessage());
            return false;
        }
        return false;
    }

    private void verifyBluetooth() {

    }

    @Override
    public boolean bindService(Intent arg0, ServiceConnection arg1, int arg2) {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public Context getApplicationContext() {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    public void onIBeaconServiceConnect() {
        // TODO Auto-generated method stub

    }

    @Override
    public void unbindService(ServiceConnection arg0) {
        // TODO Auto-generated method stub

    }
}
ibeacon.js文件的源代码是:

var ibeacon = {
    verifyBluetooth: function (successCallback, errorCallback) {
        cordova.exec(
            successCallback,
            errorCallback,
            'IBeacon',
            'verifyBluetooth',
            [{

            }]
        );
    }
}
module.exports = ibeacon;
plugin.xml文件的源代码是:

<?xml version="1.0" encoding="UTF-8"?>
<plugin xmlns="http://www.phonegap.com/ns/plugins/1.0"
    xmlns:android="http://schemas.android.com/apk/res/android"
    id="me.habel.cordova.plugins.ibeacon"
    version="1.0.1">

    <name>IBeacon</name>
    <description>iBeacon</description>
    <license>MIT</license>

    <engines>
        <engine name="cordova" version=">=3.0.0" />
    </engines>

    <js-module src="www/ibeacon.js" name="ibeacon">
        <clobbers target="window.ibeacon" />
    </js-module>

    <!-- android -->
    <platform name="android">
        <source-file src="src/android/com/IBeacon.java" target-dir="src/me/habel/plugins/IBeacon" />
        <config-file target="res/xml/config.xml" parent="/*">
            <feature name="IBeacon">
                <param name="android-package" value="me.habel.plugins.IBeacon.IBeacon" />
            </feature>
        </config-file>
    </platform>
</plugin>
然后我得到上面提到的错误。我在谷歌上搜索并查看了github中的其他代码,但找不到错误


谢谢。

我假设以下两种导入导致了问题:

import com.radiusnetworks.ibeacon.IBeaconConsumer;
import com.radiusnetworks.ibeacon.IBeaconManager;

您能检查一下这些课程是否可用吗?

是的,它们可用。我通过以下方式添加这些类:在Eclipse中,我进入项目>属性>Android>库>添加并选择包含这些类的库。我在本地android应用程序中遵循了这个过程,效果非常好。对于Cordova插件,我是否需要以不同的方式执行此操作?
import com.radiusnetworks.ibeacon.IBeaconConsumer;
import com.radiusnetworks.ibeacon.IBeaconManager;