无法从GCM接收消息 [英] Unable to receive messages from GCM

查看:234
本文介绍了无法从GCM接收消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

正在开发一个使用GCM来发送和接收消息的Andr​​oid应用程序。
我能够RO注册我的应用程序GCM和接收GCM注册令牌。但我没有收到新邮件通知。(好像没有在我的 MyGcmListenerService 类hapenning。)

我只能在重装我聊天的用户界面看到我的新邮件(即点击后退按钮,然后再次单击我的聊天按钮。没有什么是发生在我的MyGcmListenerService.java !!!!)

下面是我的班和的Andr​​oidManifest.xml

的Andr​​oidManifest.xml

 <采用-SDK安卓的minSdkVersion =8机器人:targetSdkVersion =17/>
<使用许可权的android:NAME =android.permission.INTERNET对/>
<使用许可权的android:NAME =android.permission.WAKE_LOCK/>
<使用许可权的android:NAME =com.google.android.c2dm.permission.RECEIVE/><允许机器人:名字=com.me.myapp.permission.C2D_MESSAGE
    安卓的ProtectionLevel =签名/>
<使用许可权的android:NAME =com.me.myapp.permission.C2D_MESSAGE/>
<应用
    机器人:allowBackup =真
    机器人:图标=@的mipmap / ic_launcher
    机器人:标签=@字符串/ APP_NAME
    机器人:主题=@风格/ AppTheme
    机器人:名字=android.support.multidex.MultiDexApplication
    >    <接收
        机器人:名字=com.google.android.gms.gcm.GcmReceiver
        机器人:出口=真
        机器人:权限=com.google.android.c2dm.permission.SEND>
        &所述;意图滤光器>
            <作用机器人:名字=com.google.android.c2dm.intent.RECEIVE/>
            <类机器人:名字=com.me.myapp/>
        &所述; /意图滤光器>
    < /接收器>
    <服务
        机器人:名字=com.me.myapp.MyGcmListenerService
        机器人:出口=假>
        &所述;意图滤光器>
            <作用机器人:名字=com.google.android.c2dm.intent.RECEIVE/>
        &所述; /意图滤光器>
    < /服务>
    <服务
        机器人:名字=com.me.myapp.MyInstanceIDListenerService
        机器人:出口=假>
        &所述;意图滤光器>
            <作用机器人:名字=com.google.android.gms.iid.InstanceID/>
        &所述; /意图滤光器>
    < /服务>

MyGcmListenerService.java

 公共类MyGcmListenerService扩展GcmListenerService {私有静态最后弦乐TAG =MyGcmListenerService;公共静态最后弦乐AC_GCM_MESSAGE_ACTION =com.me.myapp.MyGcmListenerService.OrderedBroadcast;
公共静态最后弦乐截获=拦截;/ **
 *收到消息时调用。
 *
 *从发送的SenderID @参数。
 *包含的信息数据作为键/值对@参数数据包的数据。
 *对于SET键使用data.keySet()。
 * /
// [START RECEIVE_MESSAGE]
@覆盖
公共无效onMessageReceived(String一个,捆绑数据){
    D(关于接收称为);
    最终字符串消息= data.getString(信息);
    最后弦乐SENDERNAME = data.getString(发件人);
    最后弦乐senderId = data.getString(senderId);
    最后弦乐dateCreated会= data.getString(dateCreated会);
    Log.d(TAG,发件人:+的);
    Log.d(TAG消息:+消息);    D(+从从收到的消息);    意向意图=新意图(AC_GCM_MESSAGE_ACTION);
    intent.putExtra(消息,消息);
    intent.putExtra(SENDERNAME,发出者);
    intent.putExtra(senderId,senderId);
    intent.putExtra(dateCreated会的话,dateCreated);
    //创建日期
    intent.putExtra(拦截,FALSE);    sendOrderedBroadcast(意向,空,新MyBroadcastReceiver(){
        @覆盖
        公共无效的onReceive(上下文的背景下,意图意图){
            捆绑的结果= getResultExtras(真);
            D(进入的onReceive);
            布尔截获= results.getBoolean(拦截);
            如果(!拦截){
                sendNotification时(消息,SENDERNAME,senderId);
            }
        }
    },空,Activity.RESULT_OK,NULL,NULL);
}
// [END RECEIVE_MESSAGE]/ **
 *创建并显示包含接收到的GCM消息的简单的通知。
 *
 * @参数消息GCM消息接收。
 * /
私人无效sendNotification时(字符串消息,SENDERNAME字符串,字符串senderId){
    意向意图=新意图(这一点,ChatActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.putExtra(senderId,senderId);
    的PendingIntent的PendingIntent = PendingIntent.getActivity(这一点,0 / *请求code * /,意图,
            PendingIntent.FLAG_ONE_SHOT);    乌里defaultSoundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder =新NotificationCompat.Builder(本)
            .setSmallIcon(R.drawable.ic_stat_name)
            .setContentTitle(SENDERNAME)
            .setContentText(消息)
            .setAutoCancel(真)
            .setSound(defaultSoundUri)
            .setContentIntent(的PendingIntent);    NotificationManager notificationManager =
            (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);    notificationManager.notify(0 / *标识的通知* /,notificationBuilder.build());
}私人无效D(String s)将{
    Log.d(MyGcmListenerService,S);
}

}

我的RegistrationIntentService.java

 私有静态最后弦乐TAG =RegIntentService;
公共RegistrationIntentService(){
    超(TAG);
}@覆盖
保护无效onHandleIntent(意向意图){
    D(onHandleIntent);    共享preferences共享preferences = preferenceManager.getDefaultShared preferences(本);    尝试{
        //在同时出现多个刷新操作(不太可能)的事件,
        //确保它们被顺序地处理。
        同步(TAG){
            // [START register_for_gcm]
            //最初这个调用出去的网络检索令牌,后续调用
            //是本地的。
            // [START的get_token]
            实例id =实例ID InstanceID.getInstance(本);
            字符串标记= instanceID.getToken(的getString(R.string.gcm_defaultSenderId)
                    GoogleCloudMessaging.INSTANCE_ID_SCOPE,NULL);
            // [结束的get_token]
            D(GCM注​​册令牌:+令牌);            sendRegistrationToServer(标记);            //你要存储一个布尔值,表示生成的令牌是否已经
            //发送到服务器。如果布尔是假的,送令牌服务器,
            //否则你的服务器应该已经收到了令牌。
            共享preferences.edit()putBoolean(AlphaCash preferences.SENT_TOKEN_TO_SERVER,真实)。适用()。
            // [END register_for_gcm]
            D(注册成功);
        }
    }赶上(例外五){
        D(无法完成令牌刷新,E);
        //如果在获取新的令牌或更新我们的注册数据发生异常
        //第三方的服务器上,这保证了我们将在以后的时间尝试更新。
        共享preferences.edit()putBoolean(AlphaCash preferences.SENT_TOKEN_TO_SERVER,假)。适用()。
    }
    //通知登记已完成的UI,所以进度指示器可以隐藏。
    意图registrationComplete =新意图(AlphaCash preferences.REGISTRATION_COMPLETE);
    D(regestration意图广播);
    LocalBroadcastManager.getInstance(本).sendBroadcast(registrationComplete);
}/ **
 *坚持登记第三方服务器。
 *
 *修改此方法将用户的注册GCM令牌任何服务器端帐户关联
 *您的应用程序维护。
 *
 * @参数令牌新的令牌。
 * /
私人无效sendRegistrationToServer(字符串标记){
    D(发送注册令牌服务器);
    //添加自定义的实现,根据需要。
    上下文C = getApplication();
    SaveRegistrationIdRequest REQ =新SaveRegistrationIdRequest();
    req.setCredentials(Installation.createCredentials(C));
    req.setRegId(标记);
    安装安装= Installation.getInstance(C);
    SendGcmRegistrationIdTask任务=新SendGcmRegistrationIdTask(新ApiTask.ResultListener(){
        @覆盖
        公共无效successHook(对象o){
            //将GCM ID注册后TODO
        }
    },安装,REQ);    task.execute();
    D(successflly发送);
}私人无效D(String s)将{
    Log.d(RegIntentService,S);
}私人无效D(字符串s例外五){
    Log.d(RegIntentService,S,E);
}

}

如何我可以解决我的问题,并能即​​时接收消息没有来回?

调试后我的申请,这都是警告AM充分利用LogCat中

  com.me.myapp W / dalvikvm:VFY:无法解析虚方法247:Landroid /应用/
通知$生成器; .setLocalOnly(Z)Landroid /应用/通知$生成器;
10-05 16:18:11.594 32178-32178 / com.me.myapp W / dalvikvm:VFY:无法解析实例字段18
10-05 16:18:11.603 32178-32178 / com.me.myapp W / dalvikvm:VFY:无法解析虚方法1507:Landroid / OS /的UserManager; .getApplicationRestrictions(Ljava /朗/字符串;)Landroid / OS /束;
10-05 16:18:11.605 32178-32178 / com.me.myapp E / dalvikvm:找不到类的android.app.AppOpsManager,从法com.google.android.gms.common.GooglePlayServicesUtil.zzb引用


解决方案

我终于解决了我的问题,这是因为发生在我没有得到它从GCM服务器到我的应用程序服务器后发送GCM注册ID。

但它发送到我的应用程序服务器后,我的客户端应用程序能够在收到新邮件接收通知。

任何一个谁遇到同样的问题。这是您的应用程序无法从GCM收到通知或消息(或两者)请确保您有(编程)发送GCM注册令牌你的应用服务器

像这样

 公共类RegistrationIntentService扩展IntentService {
 公共静态最后弦乐GCM_SENDER_ID =你的专案编号; //你的项目编号
 私有静态最后弦乐TAG =RegIntentService;
 公共静态最后弦乐SENT_TOKEN_TO_SERVER =sentTokenToServer;
 公共静态最后弦乐REGISTRATION_COMPLETE =registrationComplete;
 公共静态最后长GCM_TIME_TO_LIVE = 60L * 60L * 24L * 7L * 4L; // 4周私有静态最后弦乐TAG =RegIntentService;公共RegistrationIntentService(){
    超(TAG);}
串REGID;
@覆盖
保护无效onHandleIntent(意向意图){
    共享preferences共享preferences = preferenceManager.getDefaultShared preferences(本);    尝试{
        // [START register_for_gcm]
        //最初这个调用出去的网络检索令牌,后续调用
        //是本地的。
        // [START的get_token]
        实例id =实例ID InstanceID.getInstance(本);
        字符串标记= instanceID.getToken(的getString(R.string.gcm_defaultSenderId)
                GoogleCloudMessaging.INSTANCE_ID_SCOPE,NULL);
        REGID =记号。
        // [结束的get_token]
        Log.i(TAGGCM注​​册令牌:+令牌);        // TODO:实施此方法的任何注册发送到您的应用程序的服务器。
        sendRegistrationToServer(标记);
        //你要存储一个布尔值,表示生成的令牌是否已经
        //发送到服务器。如果布尔是假的,送令牌服务器,
        //否则你的服务器应该已经收到了令牌。
        。共享preferences.edit()putBoolean(SENT_TOKEN_TO_SERVER,真)。适用();
        // [END register_for_gcm]
    }赶上(例外五){
        Log.d(TAG,无法完成令牌刷新,E);
        //如果在获取新的令牌或更新我们的注册数据发生异常
        //第三方的服务器上,这保证了我们将在以后的时间尝试更新。
        共享preferences.edit()putBoolean(SENT_TOKEN_TO_SERVER,假)。适用()。
    }
    //通知登记已完成的UI,所以进度指示器可以隐藏。
    意图registrationComplete =新意图(REGISTRATION_COMPLETE);
    LocalBroadcastManager.getInstance(本).sendBroadcast(registrationComplete);
}
/ **
 *通过上行发送的注册ID到第三方服务器
 * GCM消息。理想情况下,这将通过HTTP来完成,以保证成功或失败
 *立即,但它需要一个HTTP端点。
 * /私人无效sendRegistrationToServer(字符串标记){字符串名称=令牌
新的AsyncTask<弦乐,太虚,字符串>()
{
    @覆盖
    保护字符串doInBackground(字符串... PARAMS)
    {
    弦乐味精=;
    尝试
    {
        捆绑数据=新包();
        data.putString(名,则params [0]);
        data.putString(行动,com.antoinecampbell.gcmdemo.REGISTER);
        串ID = Integer.toString(msgId.incrementAndGet());
        gcm.send(GCM_SENDER_ID +@ gcm.googleapis.com,ID,GCM_TIME_TO_LIVE,数据);
        味精=已发送注册;
    }
    赶上(IOException异常前)
    {
        味精=错误:+ ex.getMessage();
    }
    返回味精;
    }    @覆盖
    保护无效onPostExecute(弦乐味精)
    {
    Toast.makeText(背景下,味精,Toast.LENGTH_SHORT).show();
    }
 } .execute(名);
 }
}

试试看!

am developing an android app that uses GCM to send and receive messages. am able ro register my app with GCM and receive GCM Registration Token. but am not being notified upon receiving new messages.(seems like nothing is hapenning in my MyGcmListenerService class.)

i can only see my new messages upon reloading my chat user Interface(that is clicking the back button and then clicking again my chat button. nothing is taking place in my MyGcmListenerService.java !!!!)

below are my classes and AndroidManifest.xml

AndroidManifest.xml

 <uses-sdk android:minSdkVersion="8" android:targetSdkVersion="17"/>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

<permission android:name="com.me.myapp.permission.C2D_MESSAGE"
    android:protectionLevel="signature" />
<uses-permission android:name="com.me.myapp.permission.C2D_MESSAGE" />
<application
    android:allowBackup="true"
    android:icon="@mipmap/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme"
    android:name="android.support.multidex.MultiDexApplication"
    >

    <receiver
        android:name="com.google.android.gms.gcm.GcmReceiver"
        android:exported="true"
        android:permission="com.google.android.c2dm.permission.SEND" >
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            <category android:name="com.me.myapp" />
        </intent-filter>
    </receiver>
    <service
        android:name="com.me.myapp.MyGcmListenerService"
        android:exported="false" >
        <intent-filter>
            <action android:name="com.google.android.c2dm.intent.RECEIVE" />
        </intent-filter>
    </service>
    <service
        android:name="com.me.myapp.MyInstanceIDListenerService"
        android:exported="false">
        <intent-filter>
            <action android:name="com.google.android.gms.iid.InstanceID"/>
        </intent-filter>
    </service>

MyGcmListenerService.java

public class MyGcmListenerService extends GcmListenerService {

private static final String TAG = "MyGcmListenerService";

public static final String AC_GCM_MESSAGE_ACTION = "com.me.myapp.MyGcmListenerService.OrderedBroadcast";
public static final String INTERCEPTED = "intercepted";



/**
 * Called when message is received.
 *
 * @param from SenderID of the sender.
 * @param data Data bundle containing message data as key/value pairs.
 *             For Set of keys use data.keySet().
 */
// [START receive_message]
@Override
public void onMessageReceived(String from, Bundle data) {
    d("on receive called");
    final String message = data.getString("message");
    final String senderName = data.getString("sender");
    final String senderId = data.getString("senderId");
    final String dateCreated = data.getString("dateCreated");
    Log.d(TAG, "From: " + from);
    Log.d(TAG, "Message: " + message);

    d("Message received from "+ from);

    Intent intent = new Intent(AC_GCM_MESSAGE_ACTION);
    intent.putExtra("message", message);
    intent.putExtra("senderName", senderName);
    intent.putExtra("senderId", senderId);
    intent.putExtra("dateCreated", dateCreated);
    //dateCreated
    intent.putExtra(INTERCEPTED, false);

    sendOrderedBroadcast(intent, null, new MyBroadcastReceiver() {
        @Override
        public void onReceive(Context context, Intent intent) {
            Bundle results = getResultExtras(true);
            d("entered onreceive");
            boolean intercepted = results.getBoolean(INTERCEPTED);
            if (!intercepted) {
                sendNotification(message, senderName, senderId);
            }
        }
    }, null, Activity.RESULT_OK, null, null);
}
// [END receive_message]

/**
 * Create and show a simple notification containing the received GCM message.
 *
 * @param message GCM message received.
 */
private void sendNotification(String message, String senderName, String senderId) {
    Intent intent = new Intent(this, ChatActivity.class);
    intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.putExtra("senderId", senderId);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0 /* Request code */, intent,
            PendingIntent.FLAG_ONE_SHOT);

    Uri defaultSoundUri= RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.drawable.ic_stat_name)
            .setContentTitle(senderName)
            .setContentText(message)
            .setAutoCancel(true)
            .setSound(defaultSoundUri)
            .setContentIntent(pendingIntent);

    NotificationManager notificationManager =
            (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);

    notificationManager.notify(0 /* ID of notification */, notificationBuilder.build());
}

private void d(String s){
    Log.d("MyGcmListenerService", s);
}

}

My RegistrationIntentService.java

 private static final String TAG = "RegIntentService";
public RegistrationIntentService() {
    super(TAG);
}

@Override
protected void onHandleIntent(Intent intent) {
    d("onHandleIntent");

    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);

    try {
        // In the (unlikely) event that multiple refresh operations occur simultaneously,
        // ensure that they are processed sequentially.
        synchronized (TAG) {
            // [START register_for_gcm]
            // Initially this call goes out to the network to retrieve the token, subsequent calls
            // are local.
            // [START get_token]
            InstanceID instanceID = InstanceID.getInstance(this);
            String token = instanceID.getToken(getString(R.string.gcm_defaultSenderId),
                    GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);
            // [END get_token]
            d("GCM Registration Token: " + token);

            sendRegistrationToServer(token);

            // You should store a boolean that indicates whether the generated token has been
            // sent to your server. If the boolean is false, send the token to your server,
            // otherwise your server should have already received the token.
            sharedPreferences.edit().putBoolean(AlphaCashPreferences.SENT_TOKEN_TO_SERVER, true).apply();
            // [END register_for_gcm]
            d("registration succeeded");
        }
    } catch (Exception e) {
        d("Failed to complete token refresh", e);
        // If an exception happens while fetching the new token or updating our registration data
        // on a third-party server, this ensures that we'll attempt the update at a later time.
        sharedPreferences.edit().putBoolean(AlphaCashPreferences.SENT_TOKEN_TO_SERVER, false).apply();
    }
    // Notify UI that registration has completed, so the progress indicator can be hidden.
    Intent registrationComplete = new Intent(AlphaCashPreferences.REGISTRATION_COMPLETE);
    d("regestration intent broadcasted");
    LocalBroadcastManager.getInstance(this).sendBroadcast(registrationComplete);
}

/**
 * Persist registration to third-party servers.
 *
 * Modify this method to associate the user's GCM registration token with any server-side account
 * maintained by your application.
 *
 * @param token The new token.
 */
private void sendRegistrationToServer(String token) {
    d("Send registration token to server");
    // Add custom implementation, as needed.
    Context c = getApplication();
    SaveRegistrationIdRequest req = new SaveRegistrationIdRequest();
    req.setCredentials(Installation.createCredentials(c));
    req.setRegId(token);
    Installation installation = Installation.getInstance(c);
    SendGcmRegistrationIdTask task = new SendGcmRegistrationIdTask(new ApiTask.ResultListener() {
        @Override
        public void successHook(Object o) {
            //TODO After registration of the gcm id
        }
    }, installation, req);

    task.execute();
    d("successflly sent");
}

private void d(String s){
    Log.d("RegIntentService", s);
}

private void d(String s, Exception e){
    Log.d("RegIntentService", s, e);
}

}

QUESTION

How can i solve my problem and be able to receive messages instantly without going back and forth ?

AFTER DEBUGGING MY APPLICATION, THIS ARE THE WARNINGS AM GETTING FROM THE LOGCAT

com.me.myapp W/dalvikvm﹕ VFY: unable to resolve virtual method 247: Landroid/app/
Notification$Builder;.setLocalOnly (Z)Landroid/app/Notification$Builder;
10-05 16:18:11.594  32178-32178/com.me.myapp W/dalvikvm﹕ VFY: unable to resolve instance field 18
10-05 16:18:11.603  32178-32178/com.me.myapp W/dalvikvm﹕ VFY: unable to resolve virtual method 1507: Landroid/os/UserManager;.getApplicationRestrictions (Ljava/lang/String;)Landroid/os/Bundle;
10-05 16:18:11.605  32178-32178/com.me.myapp E/dalvikvm﹕ Could not find class 'android.app.AppOpsManager', referenced from method com.google.android.gms.common.GooglePlayServicesUtil.zzb

解决方案

I finally solved my problem which was occurring because i wasn't sending GCM registration ID after getting it from GCM server to my app server.

But after sending it to my app server, my client app was able to receive notifications upon receiving a new message.

any one who is experiencing same problem. that is Your app isn't receiving notifications or messages(or both)from GCM please make sure you have (programmatically) sent GCM registration token to your app server

Something like this

public class RegistrationIntentService extends IntentService {
 public static final String GCM_SENDER_ID = "Your ProjectID";//your project id
 private static final String TAG = "RegIntentService";
 public static final String SENT_TOKEN_TO_SERVER = "sentTokenToServer";
 public static final String REGISTRATION_COMPLETE = "registrationComplete";
 public static final long GCM_TIME_TO_LIVE = 60L * 60L * 24L * 7L * 4L; // 4 Weeks

private static final String TAG = "RegIntentService";

public RegistrationIntentService() {
    super(TAG);

}
String regId;
@Override
protected void onHandleIntent(Intent intent) {
    SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);

    try {
        // [START register_for_gcm]
        // Initially this call goes out to the network to retrieve the token, subsequent calls
        // are local.
        // [START get_token]
        InstanceID instanceID = InstanceID.getInstance(this);
        String token = instanceID.getToken(getString(R.string.gcm_defaultSenderId),
                GoogleCloudMessaging.INSTANCE_ID_SCOPE, null);
        regId = token;
        // [END get_token]
        Log.i(TAG, "GCM Registration Token: " + token);

        // TODO: Implement this method to send any registration to your app's servers.
        sendRegistrationToServer(token);


        // You should store a boolean that indicates whether the generated token has been
        // sent to your server. If the boolean is false, send the token to your server,
        // otherwise your server should have already received the token.
        sharedPreferences.edit().putBoolean(SENT_TOKEN_TO_SERVER, true).apply();
        // [END register_for_gcm]
    } catch (Exception e) {
        Log.d(TAG, "Failed to complete token refresh", e);
        // If an exception happens while fetching the new token or updating our registration data
        // on a third-party server, this ensures that we'll attempt the update at a later time.
        sharedPreferences.edit().putBoolean(SENT_TOKEN_TO_SERVER, false).apply();
    }
    // Notify UI that registration has completed, so the progress indicator can be hidden.
    Intent registrationComplete = new Intent(REGISTRATION_COMPLETE);
    LocalBroadcastManager.getInstance(this).sendBroadcast(registrationComplete);
}


/**
 * Sends the registration ID to the 3rd party server via an upstream 
 * GCM message. Ideally this would be done via HTTP to guarantee success or failure 
 * immediately, but it would require an HTTP endpoint.
 */

private void sendRegistrationToServer(String token) {

String name = token
new AsyncTask<String, Void, String>()
{
    @Override
    protected String doInBackground(String... params)
    {
    String msg = "";
    try
    {
        Bundle data = new Bundle();
        data.putString("name", params[0]);
        data.putString("action", "com.antoinecampbell.gcmdemo.REGISTER");
        String id = Integer.toString(msgId.incrementAndGet());
        gcm.send(GCM_SENDER_ID + "@gcm.googleapis.com", id,GCM_TIME_TO_LIVE, data);
        msg = "Sent registration";
    }
    catch (IOException ex)
    {
        msg = "Error :" + ex.getMessage();
    }
    return msg;
    }

    @Override
    protected void onPostExecute(String msg)
    {
    Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
    }
 }.execute(name);
 }
}

Give it a try!!

这篇关于无法从GCM接收消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆