我正在尝试制作一个cordova插件,以便在Android中获得电话通话历史。为了获取插件:http://www.androidhub4you.com/2013/09/android-call-history-example-how-to-get.html?showComment=1402049673596#c4881780435926453105的java代码,我遵循了本教程
我的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应用程序中运行了相同的代码,而且它成功了。
谢谢
发布于 2014-06-09 09:36:27
我找到了解决办法!
为了创建一个新的游标,我不得不添加:this.cordova.getActivity()。
Cursor managedCursor = this.cordova.getActivity().getContentResolver().query(CallLog.Calls.CONTENT_URI, null, null, null, null); https://stackoverflow.com/questions/24083582
复制相似问题