Android Google Cloude消息错误

Android Google Cloude消息错误,android,Android,我正在使用GCM发送通知,我已经包括了 导入com.google.android.gms.gcm.GoogleCloudMessaging 但是我在eclipse中遇到了一个错误 无法解析导入com.google.android.gms.gcm.GoogleCloudMessaging 但是我已经包含了gcm.jar文件,gcm-server-1.0.2.jar和google-play-services_lib.jar,但是我仍然得到了相同的错误 我试过的代码是: package com.exa

我正在使用GCM发送通知,我已经包括了
导入com.google.android.gms.gcm.GoogleCloudMessaging

但是我在eclipse中遇到了一个错误

无法解析导入com.google.android.gms.gcm.GoogleCloudMessaging
但是我已经包含了gcm.jar文件,gcm-server-1.0.2.jar和google-play-services_lib.jar,但是我仍然得到了相同的错误

我试过的代码是:

package com.example.gcm;

import android.app.IntentService;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.os.SystemClock;
import android.support.v4.app.NotificationCompat;
import android.util.Log;

import com.google.android.gms.gcm.GoogleCloudMessaging;

public class GCMNotificationIntentService extends IntentService {

    public static final int NOTIFICATION_ID = 1;
    private NotificationManager mNotificationManager;
    NotificationCompat.Builder builder;

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

    public static final String TAG = "GCMNotificationIntentService";

    @Override
    protected void onHandleIntent(Intent intent) {
        Bundle extras = intent.getExtras();
        GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this);

        String messageType = gcm.getMessageType(intent);

        if (!extras.isEmpty()) {
            if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR
                    .equals(messageType)) {
                sendNotification("Send error: " + extras.toString());
            } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED
                    .equals(messageType)) {
                sendNotification("Deleted messages on server: "
                        + extras.toString());
            } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE
                    .equals(messageType)) {

                for (int i = 0; i < 3; i++) {
                    Log.i(TAG,
                            "Working... " + (i + 1) + "/5 @ "
                                    + SystemClock.elapsedRealtime());
                    try {
                        Thread.sleep(5000);
                    } catch (InterruptedException e) {
                    }

                }
                Log.i(TAG, "Completed work @ " + SystemClock.elapsedRealtime());

                sendNotification("Message Received from Google GCM Server: "
                        + extras.get(Config.MESSAGE_KEY));
                Log.i(TAG, "Received: " + extras.toString());
            }
        }
        GcmBroadcastReceiver.completeWakefulIntent(intent);
    }
package com.example.gcm;
导入android.app.IntentService;
导入android.app.NotificationManager;
导入android.app.pendingent;
导入android.content.Context;
导入android.content.Intent;
导入android.os.Bundle;
导入android.os.SystemClock;
导入android.support.v4.app.NotificationCompat;
导入android.util.Log;
导入com.google.android.gms.gcm.GoogleCloudMessaging;
公共类GCMNotificationEntService扩展了IntentService{
公共静态最终整数通知_ID=1;
私人通知经理通知经理;
通知建筑商;
公共GCMNotificationtentService(){
超级(“GCMinentService”);
}
公共静态最终字符串TAG=“gcmnotificationtentservice”;
@凌驾
受保护的手部内容无效(意图){
Bundle extras=intent.getExtras();
GoogleCloudMessaging gcm=GoogleCloudMessaging.getInstance(this);
字符串messageType=gcm.getMessageType(intent);
如果(!extras.isEmpty()){
如果(GoogleCloudMessaging.MESSAGE)\类型\发送\错误
.equals(messageType)){
sendNotification(“发送错误:+extras.toString());
}else if(GoogleCloudMessaging.MESSAGE\u TYPE\u已删除
.equals(messageType)){
sendNotification(“服务器上已删除的邮件:”
+附加的toString());
}else if(GoogleCloudMessaging.MESSAGE\u TYPE\u MESSAGE
.equals(messageType)){
对于(int i=0;i<3;i++){
Log.i(标签,
“工作…”+(i+1)+“/5@”
+SystemClock.elapsedRealtime());
试一试{
睡眠(5000);
}捕捉(中断异常e){
}
}
Log.i(标记“Completed work@”+SystemClock.elapsedRealtime());
sendNotification(“从Google GCM服务器收到的消息:”
+extras.get(Config.MESSAGE_KEY));
Log.i(标记“Received:+extras.toString());
}
}
GcmBroadcastReceiver.completeWakefulIntent(intent);
}
伙计们,你们能帮帮我吗


谢谢

只保留play service jar文件并删除其他jar文件,同时添加jar文件以在eclipse中构建路径。因为play service与GCM类捆绑在一起。我也这样做了,但我得到了error@Silvanswhat你收到错误了吗?请把错误或错误截图放在这里,导入com.google.android.gms.gcm.GoogleCloudMessaging无法解决@Silvans Solankire从play service jar中的类和导入类中删除该行,它将解决您的问题。