2

I am building an app using pjsua2 library. The sample app coming with the library is working fine. But in my app, when I try to make a call using the below code,

    if (currentCall != null) {return;}
    String buddy_uri = "sip:" + number + "@" + domain;
    MyCall call = new MyCall(account, -1);
    CallOpParam prm = new CallOpParam(true);
    try {
        call.makeCall(buddy_uri, prm);
    } catch (Exception e) {
        call.delete();
        return;
    }
    currentCall = call;

I'm getting the exception below,

java.lang.Exception: Title:       pjsua_call_make_call(acc.getId(),
&pj_dst_uri, param.p_opt, this, param.p_msg_data, &id)
Code:        420003
Description: Audio subsystem not initialized (PJMEDIA_EAUD_INIT)
Location:    ../src/pjsua2/call.cpp:490

This error comes only in Marshmallow, in Kitkat device, its working fine. Can somebody throw some light into this issue?

Rounak
  • 301
  • 3
  • 11

5 Answers5

4

In Android from Marshmallow we need to get permissions.

I used the below code to check and get permissions from user.

private static final int REQUEST_PERMISSIONS = 100;
  private static final String PERMISSIONS_REQUIRED[] = new String[]{

            Manifest.permission.READ_CONTACTS,Manifest.permission.RECORD_AUDIO

    };

    private boolean checkPermission(String permissions[]) {
        for (String permission : permissions) {
            if (ContextCompat.checkSelfPermission(getApplicationContext(), permission) != PackageManager.PERMISSION_GRANTED) {
                return false;
            }
        }
        return true;
    }

    private void checkPermissions() {
        boolean permissionsGranted = checkPermission(PERMISSIONS_REQUIRED);
        if (permissionsGranted) {
            Toast.makeText(this, "You've granted all required permissions!", Toast.LENGTH_SHORT).show();
        } else {
            boolean showRationale = true;
            for (String permission : PERMISSIONS_REQUIRED) {
                showRationale = ActivityCompat.shouldShowRequestPermissionRationale(this, permission);
                if (!showRationale) {
                    break;
                }
            }

            String dialogMsg = showRationale ? "We need some permissions to run this APP!" : "You've declined the required permissions, please grant them from your phone settings";

            new AlertDialog.Builder(this)
                    .setTitle("Permissions Required")
                    .setMessage(dialogMsg)
                    .setCancelable(false)
                    .setPositiveButton("OK", new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                            ActivityCompat.requestPermissions(mActivity, PERMISSIONS_REQUIRED, REQUEST_PERMISSIONS);
                        }
                    }).create().show();
        }
    }
2

It's possible to define for what Android SDK target you build PJSIP. You should specify APP_ABI as :=ALL in your Application.mk file. Other things you want to check before are NDK and armeabi. Read carefully those things here before you build PJSUA2.

0

When I made my targetSdkVersion to 19 from 25, the call started working in both Kitkat and Marshmallow. I don't know the exact reason. Anybody who knows, please post the answer.

Rounak
  • 301
  • 3
  • 11
0

I had the very same problem because I did not request the RECORD_AUDIO permission at runtime.

Check the documentation regarding permissions.

piwi
  • 5,136
  • 2
  • 24
  • 48
0

in Android Manifest file declare Audio permission and then ask record audio permission from the user.