Sinch 推送通知问题

Sinch push notification problems

嘿,我已经尝试了我可以在网上找到的所有教程,讨论允许 sinch sdk 使用

管理android 推送通知
     @Override
public int onStartCommand(Intent intent, int flags, int startId) {

        currentUserId = ParseUser.getCurrentUser().getObjectId();

    if (currentUserId != null && !isSinchClientStarted()) {
        startSinchClient(currentUserId);
        Log.d("pp", currentUserId);
    }

 //        make sure you have created a SinchClient
//        if (SinchHelpers.isSinchPushIntent(broadcastIntent)) {
//            NotificationResult result = sinchClient.relayRemotePushNotificationPayload(broadcastIntent);
//        }

    broadcaster = LocalBroadcastManager.getInstance(this);

    return super.onStartCommand(intent, flags, startId);
}

public void startSinchClient(String username) {
    sinchClient = Sinch.getSinchClientBuilder().context(this)
            .userId(username)
            .applicationKey(APP_KEY)
            .applicationSecret(APP_SECRET).environmentHost(ENVIRONMENT).build();

    sinchClient.addSinchClientListener(this);

    sinchClient.setSupportMessaging(true);
    sinchClient.setSupportManagedPush(true);
    sinchClient.setSupportActiveConnectionInBackground(true);

    sinchClient.checkManifest();

//        sinchClient.registerPushNotificationData("goodies-59e3".getBytes());

    sinchClient.start();
}

private boolean isSinchClientStarted() {
    return sinchClient != null && sinchClient.isStarted();
}

@Override
public void onClientFailed(SinchClient client, SinchError error) {
    broadcastIntent.putExtra("success", false);
    broadcaster.sendBroadcast(broadcastIntent);

    sinchClient = null;
}

但无济于事,当我尝试上述方法时,我没有得到任何结果,我什至不知道是否发生了什么,当我尝试向当前不在的人发送消息时,我没有收到任何通知应用程序。我已经解决这个问题好几个星期了,如果有任何解决方法,我将不胜感激

我会确保您的应用程序具有以下接收推送消息的权限(以及 WAKE_LOCK 在收到推送后继续执行的权限)。

<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/> <uses-permission android:name="android.permission.WAKE_LOCK"/> <permission android:name="YOUR.APP.PACKAGENAME.gcm.permission.C2D_MESSAGE" android:protectionLevel="signature"/> <uses-permission android:name="YOUR.APP.PACKAGENAME.gcm.permission.C2D_MESSAGE"/>

我还建议您查看此 link 以接收 GCM 推送通知:https://developers.google.com/cloud-messaging/#manifest

希望对您有所帮助!

请按照以下步骤操作:

1) 清单中的权限:

<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<permission android:name="com.sinch.messagingtutorial.app.permission.C2D_MESSAGE"
                android:protectionLevel="signature" />
<uses-permission android:name="com.sinch.messagingtutorial.app.permission.C2D_MESSAGE" />
<uses-permission
        android:name="com.google.android.c2dm.permission.RECEIVE" />

2) 将 Google 播放服务库添加到您的项目,并在 google 播放开发者控制台

上创建您的项目的项目 ID

3) 使用您的项目 ID,在 LoginActivity.java onCreate 中声明以下内容:

final GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(getApplicationContext());
    class RegisterGcmTask extends AsyncTask<Void, Void, String> {
        String msg = "";
        @Override
        protected String doInBackground(Void... voids) {
            try {
                msg = gcm.register("your-project-number");
            } catch (IOException ex) {
                msg = "Error :" + ex.getMessage();
            }
                return msg;
        }
        @Override
        protected void onPostExecute(String msg) {
            intent = new Intent(getApplicationContext(), ListUsersActivity.class);
            serviceIntent = new Intent(getApplicationContext(), MessageService.class);
            serviceIntent.putExtra("regId", msg);
            startActivity(intent);
            startService(serviceIntent);
        }
    }

详情请参考https://www.sinch.com/tutorials/send-push-notifications-android-messaging-app-using-gcm/ link

和演示参考 Github Link https://www.sinch.com/tutorials/send-push-notifications-android-messaging-app-using-gcm/