[英]get “success” without receiving any message with GCM
I've tried to send a notification from server to my app on my phone and I get "success" but my phone doesn't receive anything, I'm using Google Cloud Messaging 我尝试将服务器上的通知发送到手机上的应用程序,但收到“成功”消息,但手机却没有收到任何提示,我正在使用Google Cloud Messaging
public class GCMIntentService extends GcmListenerService{
private static final String TAG = "GCMIntentService";
@Override
public void onMessageReceived(String from, Bundle data) {
String message = data.getString("message");
Log.d(TAG, "from:" + from);
Log.d(TAG, "message:" + message);
sendNotification(message);
}
private void sendNotification(String message){
Intent intent = new Intent(this, MainActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
Uri defaultSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
if(Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP){
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.logo)
.setContentTitle("New Message")
.setContentText(message)
.setAutoCancel(true)
.setSound(defaultSound)
.setContentIntent(pendingIntent);
NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(0, notificationBuilder.build());
}
}
}
AndroidManifest AndroidManifest
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<permission android:name="com.example.abdul_majeed.alruthea.permission.C2D_MESSAGE"
android:protectionLevel="signature" /> android:protectionLevel =“ signature” />
<uses-permission android:name="com.example.abdul_majeed.alruthea.permission.C2D_MESSAGE" />
....
<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.example.abdul_majeed.alruthea" />
</intent-filter>
</receiver>
<service
android:name=".GCMIntentService"
android:exported="false">
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
</intent-filter>
</service>
================================================ ================================================
The problem “... doesn't receive anything …” may have caused by the code below: 问题“ ...什么都没有收到……”可能是由于以下代码引起的:
if(Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP){... ...
This means that if your device is lower than LOLLIPOP,then you can receive anything, and if your device is higher than LOLLIPOP,then you can't receive anything. 这意味着,如果您的设备低于LOLLIPOP,则您可以收到任何东西;如果您的设备高于LOLLIPOP,则您将不会收到任何东西。 Please check the Android version of the phone you are using.
请检查您使用的手机的Android版本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.