Das Symbol "GoogleCloudMessaging" GCM kann nicht aufgelöst werden
Ich versuche GCM
Arbeit in meiner app (um Benutzer zu Benachrichtigen, wenn unsere Stunden ändern, oder wenn wir irgendwelche promos geht), aber ich erhalte die Fehlermeldung Cannot resolve symbol 'GoogleCloudMessaging'
wenn man versucht, die Google Cloud Messaging API.
Ich bin mit die neu veröffentlichten Android studio IDE, um code.
Hier ist meine GcmBroadcastReciever.java code :
import android.R;
import android.app.Activity;
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.widget.Toast;
public class GcmBroadcastReceiver extends BroadcastReceiver
{
static final String TAG = "GCMDemo";
public static final int NOTIFICATION_ID = 1;
private NotificationManager mNotificationManager;
Context ctx;
GoogleCloudMessaging gcm; //I get the error here
@Override
public void onReceive(Context context, Intent intent) {
GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(context); //error
ctx = context;
String messageType = gcm.getMessageType(intent); //cannot resolve method here
if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) { //error
sendNotification("Send error: " + intent.getExtras().toString());
} else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) { //error
sendNotification("Deleted messages on server: " +
intent.getExtras().toString());
} else {
sendNotification("Received: " + intent.getExtras().toString());
}
setResultCode(Activity.RESULT_OK);
}
//Put the GCM message into a notification and post it.
private void sendNotification(String msg) {
mNotificationManager = (NotificationManager)
ctx.getSystemService(Context.NOTIFICATION_SERVICE);
PendingIntent contentIntent = PendingIntent.getActivity(ctx, 0,
new Intent(ctx, Activity.class), 0);
Toast.makeText(ctx, msg, Toast.LENGTH_SHORT).show();
}
}
InformationsquelleAutor der Frage dillonr | 2013-05-18
Du musst angemeldet sein, um einen Kommentar abzugeben.
Hast du einrichten des Google Play Services SDK?
Müssen Sie :
<android-sdk>/extras/google/google_play_services/libproject/google-play-services_lib/
- Bibliothek-Projekt in Ihrem Android-Projekt.InformationsquelleAutor der Antwort Eran
Wenn Sie mit Android Studio:
1), zum Download im Google Play SDK (mit dem SDK-Manager):
2) vergessen Sie nicht, klicken Sie auf die "Synch-Projekt mit Gradle-Dateien" - Taste
Dass hat den trick für mich.
InformationsquelleAutor der Antwort unify
Wenn Sie sich in Android Studio, stellen Sie sicher, dass in Ihrem
build.gradle
Sie haben:und führen Sie dann
build
.Dass für mich gearbeitet.
InformationsquelleAutor der Antwort hlopezvg
Stellen Sie sicher, dass Sie hinzufügen von Abhängigkeiten zu bauen.gradle > Sync - > Build - Clean-Projekt.
Arbeitete für mich 🙂
InformationsquelleAutor der Antwort rischan
Reinigen Sie Ihr Projekt. Arbeitete für mich.
InformationsquelleAutor der Antwort Wise Shepherd
Sind Sie wahrscheinlich mit einem alten tutorial, aber GCMRegistrar eine veraltete API-Klasse.
Bitte verwenden Sie die GoogleCloudMessaging API.
Überprüfen komplettes tutorial push notification über gcm
InformationsquelleAutor der Antwort kundan roy