I'm try to create a cordova plugin for intercept outgoing call and get the number called.
But when i run the app it return me a error, it go in errorCallback function.
Java code:
public class OutgoingCall extends CordovaPlugin {
private Context context;
@Override
public boolean execute(String action, JSONArray args, CallbackContext
callbackContext) throws JSONException {
Context ctx = this.context;
String number = args.getString(0);
return true;
}
}
class OutgoingCallReceiver extends BroadcastReceiver {
private CallbackContext callbackContext;
public void setCallbackContext(CallbackContext callbackContext) {
this.callbackContext = callbackContext;
}
@Override
public void onReceive(Context context, Intent intent) {
String state = intent.getStringExtra(TelephonyManager.EXTRA_STATE);
if (state == null) {
String phoneNumber =intent.getStringExtra(Intent.EXTRA_PHONE_NUMBER);
Log.e("Number=", phoneNumber);
JSONObject jso = new JSONObject();
try {
jso.put("phoneNumber", phoneNumber);
} catch (JSONException e) {
phoneNumber = "Errore 2!";
}
PluginResult result = new PluginResult(PluginResult.Status.OK,phoneNumber);
result.setKeepCallback(true);
callbackContext.sendPluginResult(result);
}
}
}
JS code:
var OutgoingCall = {
onReceive: function(successCallback, errorCallback) {
errorCallback = errorCallback || this.errorCallback;
cordova.exec(successCallback, errorCallback, 'OutgoingCall','onReceive', []);
},
errorCallback: function() {
console.log("WARNING: OutgoingCall errorCallback not implemented");
}
};
module.exports = OutgoingCall;
I have added in plugin.xml
<config-file parent="/*" target="res/xml/config.xml">
<feature name="OutgoingCall">
<param name="android-package"value="org.outgoingcall.cool.OutgoingCall" />
</feature>
</config-file>
<config-file parent="/*" target="AndroidManifest.xml">
<uses-permissionandroid:name="android.permission.PROCESS_OUTGOING_CALLS"/>
<receiver android:name=".OutgoingCallReciver" >
<intent-filter>
<actionandroid:name="android.intent.action.NEW_OUTGOING_CALL" />
</intent-filter>
</receiver>
</config-file>
I use plugin in onDeviceReady function but the plugin go in errorCallback function.
Please help me, i'm desperate!
Best regards.