sinch推送通知错误

时间:2015-12-31 21:46:00

标签: android google-cloud-messaging sinch

推送通知存在问题,有时它从未收到过,有时收到但是太晚了,有时我必须发送另一条消息才能让接收方接收全部从未到过他的消息,它没有一个模式或原因(它发生在任何时候或有时当我不长时间使用我的应用程序时)。

我使用sinch managed push如下:

在我的服务中:

private void startSinchClient(String id, String userName) {
        mSinchClient = Sinch.getSinchClientBuilder().context(this).userId(id).
                applicationKey(APP_KEY).applicationSecret(APP_SECRET).environmentHost(ENVIRONMENT).build();

        mSinchClient.addSinchClientListener(this);

        mSinchClient.setSupportCalling(true);
        mSinchClient.setSupportMessaging(true);
        //mSinchClient.setSupportPushNotifications(true);
        mSinchClient.setSupportManagedPush(true);

        //mSinchClient.setSupportActiveConnectionInBackground(true);
        //mSinchClient.startListeningOnActiveConnection();
        //mSinchClient.stopListeningOnActiveConnection();

        mMessageClient = mSinchClient.getMessageClient();
        mMessageClient.addMessageClientListener(this);

        mCallClient = mSinchClient.getCallClient();
        mCallClient.addCallClientListener(this);

        mSinchClient.checkManifest();
        mSinchClient.start();
    }

    public void relayRemotePushNotificationPayload(Intent intent) {

                DatabaseHandler handler = new DatabaseHandler(SinchClientService.this);
                UserInfo info = handler.getUserDetails();

                if (mSinchClient == null) 
                    startSinchClient(String.valueOf(info.uid), info.name);

                NotificationResult result = mSinchClient.relayRemotePushNotificationPayload(intent);

                if(result.isCall() && result.getCallResult().isTimedOut())
                    return;

                if(result.isMessage() && result.isValid())
                    mSinchClient.startListeningOnActiveConnection();

                else if(result.isMessage() && !result.isValid())
                    return;
            }

GCM广播接收器:

public class GcmBroadcastReceiver extends WakefulBroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        ComponentName comp = new ComponentName(context.getPackageName(),
                GcmIntentService.class.getName());
        startWakefulService(context, (intent.setComponent(comp)));
        setResultCode(Activity.RESULT_OK);
    }
}

GCM意向服务:

public class GcmIntentService extends IntentService implements ServiceConnection {
    private Intent mIntent;
    //private ExecutorService mExecutorService;
    //private NotificationManager notificationManager;

    public GcmIntentService() {
        super("GcmIntentService");
    }

    @Override
    protected void onHandleIntent(Intent intent) {
        if (SinchHelpers.isSinchPushIntent(intent)) {
            mIntent = intent;
            connectToService();
        } else {
            GcmBroadcastReceiver.completeWakefulIntent(intent);
        }
    }

    private void connectToService() {
        getApplicationContext().bindService(new Intent(GcmIntentService.this, SinchClientService.class), GcmIntentService.this, Context.BIND_AUTO_CREATE);
    }

    @Override
    public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
       if (mIntent == null) {
            return;
        }

        if (SinchHelpers.isSinchPushIntent(mIntent)) {
            SinchClientService.MessageServiceInterface sinchService = (SinchClientService.MessageServiceInterface) iBinder;
            if (sinchService != null) {
                sinchService.relayRemotePushNotificationPayload(mIntent);

                // handle result, e.g. show a notification or similar
            }
        }

        GcmBroadcastReceiver.completeWakefulIntent(mIntent);
        mIntent = null;
    }

    @Override
    public void onServiceDisconnected(ComponentName componentName) {
    }
}

我需要知道这是否是GCM的错误(它会在一段时间后终止连接)或我在代码中做错了什么。

0 个答案:

没有答案