广播接收者没有被twilio解雇

时间:2016-12-29 13:32:18

标签: android broadcastreceiver twilio android-pendingintent

为调用实现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);
有人有个主意吗? TKS

Manifest,hummm ....似乎缺少那里的东西?

<?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>

1 个答案:

答案 0 :(得分:2)

您的清单中需要BroadcastReceiver

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

否则,Twilio应用程序无法向其发送PendingIntent<intent-filter>您不需要<receiver>,因为您提供了明确的Intent来触发它。