实现通话的twilio,我尝试使用广播接收器代替twilio逻辑的活动。我的广播接收器应该通过onReceive()捕捉意图,但实际上却没有。
听到来电!但无法赶上活动并继续进行我的活动

我的广播接收器(TwilioBroadCastReceiver)包含:

@Override
public void onReceive(Context context, Intent intent) {
        if (intent != null) {
        /*
         * Determine if the receiving Intent has an extra for the incoming connection. If so,
         * remove it from the Intent to prevent handling it again next time the Activity is resumed
         */
        Device device = intent.getParcelableExtra(Device.EXTRA_DEVICE);
        Connection incomingConnection = intent.getParcelableExtra(Device.EXTRA_CONNECTION);

        if (incomingConnection == null && device == null) {
            return;
        }
        intent.removeExtra(Device.EXTRA_DEVICE);
        intent.removeExtra(Device.EXTRA_CONNECTION);

        pendingConnection = incomingConnection;
        pendingConnection.setConnectionListener(this);
        showIncomingDialog();
    }
}




private void createDevice(String capabilityToken) {
    try {
        if (clientDevice == null) {
            clientDevice = Twilio.createDevice(capabilityToken, this);
            Intent intent = new Intent(mActivity, TwilioBroadcastReceiver.class);
            PendingIntent pendingIntent = PendingIntent.getBroadcast(mActivity, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
            clientDevice.setIncomingIntent(pendingIntent);
        } else {
            clientDevice.updateCapabilityToken(capabilityToken);
        }

    } catch (Exception e) {
        Log.e(TAG, "An error has occured updating or creating a Device: \n" + e.toString());
        Toast.makeText(mActivity, "Device error", Toast.LENGTH_SHORT).show();
    }
}


在我的活动中:

mReceiver = new TwilioBroadcastReceiver(this, clientProfile);


有人有主意吗? ks

清单,哼...。

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="client.twilio.com.quickstart">

<!-- needed for monitoring network availability -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>

<!-- needed for processing on the network -->
<uses-permission android:name="android.permission.INTERNET"/>

<!-- needed to enable/disable the speakerphone -->
<uses-permission android:name="android.permission.MODIFY_AUDIO_SETTINGS"/>

<!-- needed to receive audio from microphone during a call -->
<uses-permission android:name="android.permission.RECORD_AUDIO"/>

<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:supportsRtl="true"
    android:theme="@style/AppTheme">
    <activity android:name=".ClientActivity"
        android:screenOrientation="portrait"
        android:launchMode="singleTop">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>

    <service android:name="com.twilio.client.TwilioClientService" android:exported="false" android:stopWithTask="true"/>
</application>


</manifest>

最佳答案

您需要在清单中包含BroadcastReceiver

<receiver android:name=".TwilioBroadcastReceiver"/>


否则,Twilio应用程序无法将PendingIntent传递给它。
<intent-filter>不需要任何<receiver>,因为您提供了明确的Intent来触发它。

关于android - 没有使用twilio触发广播接收器,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41380792/

10-11 22:21
查看更多