PUSH通知与空内容重复

时间:2016-04-18 11:21:52

标签: android push-notification android-notifications

将测试推送到我的设备中。

当应用程序处于活动状态时,通常会发出声音,但是当应用程序最小化时,会有2次空推,没有声音。

即使onMessageReceived空了,仍会显示两个空的推送通知。

接收PUSH的班级:

    public class MyGcmListenerService extends GcmListenerService implements MyLocation, DownloadListner {

    @Override
    public void onMessageReceived(String from, Bundle data) {
    sendNotificationPushNewMessages();
    }

    private void sendNotificationPushNewMessages() {

    Intent intent = new Intent(this, MainInfoActivity.class);
    PendingIntent contentIntent = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

    NotificationCompat.Builder b = new NotificationCompat.Builder(this);
         b.setAutoCancel(true)
        .setDefaults(Notification.DEFAULT_ALL)
        .setWhen(System.currentTimeMillis())
        .setSmallIcon(R.mipmap.ic_launcher)
        .setTicker("Hearty365")
        .setContentTitle("Default notification")
        .setContentText("Lorem ipsum dolor sit amet, consectetur adipiscing elit.")
        .setDefaults(Notification.DEFAULT_LIGHTS| Notification.DEFAULT_SOUND)
        .setContentIntent(contentIntent)
        .setContentInfo("Info");

    NotificationManager notificationManager = (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(1, b.build());

}

Text PUSH:

    {"to":"cHj0nruQddQ:APA91bHZZ4i02rZA7s8qyEIWtBJE-5PUry-mhAUlUWE0z3XVa4kX4CTxwD9cwWLnp-FbAAwc9zBQMf9Hghwz5B7ym51NVSt_S-9ChHW09E2LfHQyT6mtCgjMkF1fNyvQIAKfguH63ze9","content_available":true,"priority":"high","data":{"type":"push_new_messages","text":"\u041f\u0440\u043e\u0432\u0435\u0440\u043a\u0430"}}

content availablepriority用于ios版本

可能是什么麻烦?当Activiti最小化时,班级能否收到一些东西?

1 个答案:

答案 0 :(得分:1)

class Person { public int age; public string haircolor; public string name; } class Program { static void skapaPerson(string name, string haircolor, int age) { Console.Write("Vad är personens namn? "); name = Console.ReadLine(); Console.Write("Hur gammal är personen?"); age = int.Parse(Console.ReadLine()); Console.Write("Vad är personens hårfärg? "); haircolor = Console.ReadLine(); } static void Main(string[] args) { Person Person1 = new Person(); skapaPerson(Person1.name, Person1.haircolor, Person1.age); Console.Write("{0} {1} {2}", Person1.name, Person1.haircolor, Person1.age); Console.ReadLine(); } 和api中的content available for ios版本是推送通知错误的来源。

我想为Android和ios设备使用相同的api,但是当我从api中删除那2个字符串时,它在android中变得很好。