Google cloud messaging 使用google云消息为android和php脚本推送通知

Google cloud messaging 使用google云消息为android和php脚本推送通知,google-cloud-messaging,Google Cloud Messaging,我已经完成了google开发者页面上提到的所有说明,但我是推送通知的新手,因此我无法理解需要为函数sendregistrationtoserver()输入什么代码。我还想知道获取注册ID和发送推送消息所需的相应php脚本。 先谢谢你 package com.babajideal.babajideal; import android.app.IntentService; import android.content.Intent; import android.content.SharedPre

我已经完成了google开发者页面上提到的所有说明,但我是推送通知的新手,因此我无法理解需要为函数sendregistrationtoserver()输入什么代码。我还想知道获取注册ID和发送推送消息所需的相应php脚本。 先谢谢你

package com.babajideal.babajideal;

import android.app.IntentService;
import android.content.Intent;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;
import android.support.v4.content.LocalBroadcastManager;

import com.google.android.gms.gcm.GcmPubSub;
import com.google.android.gms.gcm.GoogleCloudMessaging;
import com.google.android.gms.iid.InstanceID;

import java.io.IOException;

public class RegisterationIntentService extends IntentService {

    private static final String TAG = "RegIntentService";
    private static final String[] TOPICS = {"global"};

    public RegisterationIntentService() {
        super(TAG);
    }

    @Override
    protected void onHandleIntent(Intent intent) {
        SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
        InstanceID instanceID = InstanceID.getInstance(this);
        try {
            String token = instanceID.getToken(getResources().getString(R.string.gcm_senderId), GoogleCloudMessaging.INSTANCE_ID_SCOPE,null);
            sendRegistrationToServer(token);
            subscribeTopics(token);
            sharedPreferences.edit().putBoolean(QuickstartPreferences.SENT_TOKEN_TO_SERVER, true).apply();
        } catch (IOException e) {
            e.printStackTrace();
            sharedPreferences.edit().putBoolean(QuickstartPreferences.SENT_TOKEN_TO_SERVER, false).apply();
        }
        Intent registrationComplete = new Intent(QuickstartPreferences.REGISTRATION_COMPLETE);
        LocalBroadcastManager.getInstance(this).sendBroadcast(registrationComplete);
    }
    private void subscribeTopics(String token) throws IOException {
        GcmPubSub pubSub = GcmPubSub.getInstance(this);
        for (String topic : TOPICS) {
            pubSub.subscribe(token, "/topics/" + topic, null);
        }
    }
    private void sendRegistrationToServer(String token) {
        // Add custom implementation, as needed.
    }
}

你有没有尝试过这个简单的PHP脚本来展示如何发送Android推送通知?是的,我完成了,谢谢