我收到通知时没有声音、振动或闪光灯。请问有人能告诉我错过了什么吗?
此外,我还有一些其他问题:
1.) 当应用程序打开时,我只会看到指定的图标。当应用程序关闭时,我会看到Android标志图标(我猜这是因为我还没有定义应用程序图标)。
2.) 当应用程序打开时才会显示跑马灯文本。
3.) 当应用程序打开时,我只能看到内容标题,而无法看到内容文本。
解决方案: 这是因为我使用了 com.google.android.gms:play-services-gcm:8.4.0
的版本而不是之前的版本。
请确保在服务器上发送一个通知数组,该数组只包含键/值对e=0,同时在数据数组中发送您的消息信息。
这个问题已经在这里得到了很好的回答:After updating Google play services to 8.4.0 push notifications displayed by themselves
这是我的来源:
public class MyGcmListenerService extends GcmListenerService {
private final static String TAG = "GCM_Listener";
@Override
public void onMessageReceived(String from, Bundle data) {
String message = data.getString("message");
Log.d(TAG, "From: " + from + " (" + message);
// Sets an ID for the notification
SharedPreferences sharedPreferences = getSharedPreferences(getString(R.string.sharedPreferenceStore_default), Context.MODE_PRIVATE);
int mNotificationId = sharedPreferences.getInt("id_notification", 0);
mNotificationId++;
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.all_picks_made_indicator)
.setAutoCancel(true)
.setContentTitle("Product - " + mNotificationId)
.setContentText(message)
.setTicker("Product Notification received");
// Because clicking the notification opens a new ("special") activity, there's no need to create an artificial back stack.
PendingIntent resultPendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, DetectLoginActivity.class), PendingIntent.FLAG_UPDATE_CURRENT);
mBuilder.setContentIntent(resultPendingIntent);
// Gets an instance of the NotificationManager service
NotificationManager mNotifyMgr = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
// Builds the notification and issues it.
Notification notification = mBuilder.build();
notification.defaults = Notification.DEFAULT_ALL;
mNotifyMgr.notify(mNotificationId, notification);
SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putInt("id_notification", mNotificationId);
editor.commit();
}
}