Search code examples
javaandroidcordovacordova-plugins

Cordova Plugin CallLog cannot find symbol


I am trying to make a cordova plugin for get phone call history in Android. I have followed this tutorial in order to take the java code for the plugin: http://www.androidhub4you.com/2013/09/android-call-history-example-how-to-get.html?showComment=1402049673596#c4881780435926453105

My java file is:

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.");
    }
}
}

I always get the following error:

[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

I think i am missing some import because i run the same code in one native android app and it worked.

Thanks


Solution

  • I have found a solution!

    I had to add: this.cordova.getActivity() in order to create a new Cursor.

    Cursor managedCursor = this.cordova.getActivity().getContentResolver().query(CallLog.Calls.CONTENT_URI, null, null, null, null);