2017-04-21 231 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「/> ? –