1

我已经使用 Android Api SipManager 实现了一个简单的 sip 调用。当我使用默认的 sip 端口 5060 时(因为我不需要在代码中明确提及它),它在 android 4.4 和 android 7 上都运行良好。但是当我使用其他 sip 端口(如(5090)时,我必须明确在代码中提到了它们。在那种情况下,我只能在 Android 4.4 (API 19) 上创建 sip 调用,但拒绝使用 (API 24) 在 Android 7 上注册 sip 调用。任何帮助将不胜感激。

/*: makeSipProfile * 描述:实例化用户的 SipProfile 并使应用程序能够* 接听电话。*/

private void makeSipProfile() {
    if (manager != null) {
        // Creates a SipProfile for the User
        try {
            SipProfile.Builder builder = new SipProfile.Builder(USERNAME, DOMAIN);
            builder.setPassword(PASSWORD);
            builder.setProtocol("UDP");    //explicitily mentioning sip port
            builder.setPort(5090);         // port 5090
            profile = builder.build();
            Log.e("$$", "SipProfile was built.");

            // Creates an intent to receive calls
            Intent intent = new Intent();
            intent.setAction("android.VOIPDEMO.INCOMING_CALL");
            PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, Intent.FILL_IN_DATA);
            manager.open(profile, pendingIntent, null);


            // Determines if the SipProfile successfully registered
            manager.setRegistrationListener(profile.getUriString(),
                new SipRegistrationListener() {

                    /**
                     * Name: onRegistering
                     * Description: Logs a status message indicating the
                     *              SipProfile is registering.
                     */
                    public void onRegistering(String localProfileUri) {
                        Log.e("$$", "Sip Profile <" + localProfileUri + " is registering");
                    }

                    /**
                     * Name: onRegistrationDone
                     * Description: Logs a status message indicating the
                     *              SipProfile successfully registered.
                     */
                    public void onRegistrationDone(String localProfileUri, long expiryTime) {
                        Log.e("$$", "Sip Profile <" + localProfileUri + "> successfully registered");
                        VoipActivity.setText(localProfileUri + " login successful");
                    }

                    /**
                     * Name: onRegistrationFailed
                     * Description: Logs a status message indicating the
                     *              SipProfile failed to register.
                     */
                    public void onRegistrationFailed(String localProfileUri, int errorCode, String errorMessage) {
                        Log.e("$$", "Sip Profile failed to register <" + localProfileUri + "> " +
                                " Error message: " + errorMessage);
                        VoipActivity.setText(localProfileUri + " login unsuccessful. Error message:" + errorMessage);
                    }
                });
        } catch (ParseException e) {
            Log.e("$$", "SipProfile was not built.");
            e.printStackTrace();
        } catch (SipException e) {
            e.printStackTrace();
        }
    }
}
4

0 回答 0