2017-04-21 162 views
0

我试图创建一个拦截传出呼叫的科尔多瓦插件并获得号码。科尔多瓦传出号码插件

但是,当我运行该应用程序它返回一个错误,它进入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

使用您的Android清单文件多了一个许可,我也看到,有语法错误在plugin.xml
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>

+0

然后我改变这个 <使用许可 机器人:名字=” android.permission.PROCESS_OUTGOING_CALLS“/> ? –