java-Cordova插件CallLog找不到符号

我正在尝试制作一个cordova插件来获取Android中的电话历史记录.
我已按照本教程进行操作,以获取插件的Java代码:
http://www.androidhub4you.com/2013/09/android-call-history-example-how-to-get.html?showComment=1402049673596#c4881780435926453105

我的Java文件是:

import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.CallbackContext;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.Date;
import android.app.Activity; 
import android.database.Cursor; 
import android.os.Bundle; 
import android.provider.CallLog; 
import android.content.ContentResolver;
public class CallLogList extends CordovaPlugin {

@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
    if (action.equals("callLog")) {
        String message = args.getString(0);
        this.getCallDetails(message, callbackContext);
        return true;
    }
    return false;
}
private void getCallDetails(String message, CallbackContext callbackContext) {
    if (message != null && message.length() > 0) {

        StringBuffer sb = new StringBuffer(); 

        Cursor managedCursor = getContentResolver().query(CallLog.Calls.CONTENT_URI, null, null, null, null); 
        managedCursor.close(); 
    }
    else {
        callbackContext.error("Expected one non-empty string argument.");
    }
}
}

我总是收到以下错误:

[javac] Compiling 4 source files to /Users/xxx/Projects/cordova/platforms/android/ant-build/classes
[javac] /Users/xxx/Projects/cordova/platforms/android/src/it/prova/calllog/CallLogList.java:41: cannot find symbol
[javac] symbol  : method getContentResolver()
[javac] location: class it.prova.calllog.CallLogList
[javac]             Cursor managedCursor = getContentResolver().query(CallLog.Calls.CONTENT_URI, null, null, null, null);
[javac]                                    ^
[javac] 1 error

我想我缺少一些导入,因为我在一个本机android应用程序中运行了相同的代码,并且它起作用了.

谢谢

解决方法:

我找到了解决方案!

我必须添加:this.cordova.getActivity()才能创建一个新的Cursor.

Cursor managedCursor = this.cordova.getActivity().getContentResolver().query(CallLog.Calls.CONTENT_URI, null, null, null, null); 
上一篇:java-与PhoneGap的GWT集成


下一篇:android-LeafletJS-具有本地文件系统的缓存切片