我正在尝试创建一个用于拦截拨出电话的cordova插件,并获取该号码。
但是当我运行应用程序时它会返回一个错误,它会进入errorCallback函数。
Java代码:
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代码:
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;
我在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>
我在onDeviceReady函数中使用插件,但插件进入了errorCallback函数。
请帮助我,我很绝望!
最好的问候。
答案 0 :(得分:0)
在Android Manifest文件中再使用一个权限,我也看到,你的plugin.xml中存在语法错误
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>