Custom Push Notification coming twice using Parse.com and Android

Usman Khan

I am working in custom push notification using parse.com android. Push is successfully integrated in my application, but the problem is I am getting two notifications at a time.

One from my custom Receiver with image and other one default notification from OS without any image and that notification is not even removing from notification bar, if I am removing it, it is coming again and again on notification tray. I will paste my code snippet and images below as well.

// My Custom Receiver Class

public class CustomPushReceiver extends ParsePushBroadcastReceiver {
    private final String TAG = CustomPushReceiver.class.getSimpleName();

    private NotificationUtils notificationUtils;

    private Intent parseIntent;

    public CustomPushReceiver() {
        super();
    }

    @Override
     public void onReceive(Context context, Intent intent) {
        super.onPushReceive(context, intent);

        if (intent == null)
            return;
            parseIntent = intent;
        try {
            String action = intent.getAction();
            JSONObject json = new JSONObject(intent.getExtras().getString("com.parse.Data"));
            if (action.equalsIgnoreCase("com.parse.push.intent.RECEIVE")) {
//                NOTIFICATION_ID++;
                String title = "DW";
                if (json.has("alert"))
                {
                    String text = json.getString("alert");
                    generateNotification(context, title, json, text,parseIntent);
                }
            }
        } catch (JSONException e) {
        }
 }

    @Override
    protected void onPushDismiss(Context context, Intent intent) {
        super.onPushDismiss(context, intent);
    }

    @Override
    protected void onPushOpen(Context context, Intent intent) {
        super.onPushOpen(context, intent);
    }

   private void generateNotification(Context context, String title, JSONObject json, String text, Intent intent) {
//        Intent intent = new Intent(context, home.class);
        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
        PendingIntent contentIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_ONE_SHOT);

        NotificationManager mNotifM = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);

        android.support.v4.app.NotificationCompat.Builder mBuilder =
                new NotificationCompat.Builder(context)
                        .setSmallIcon(R.drawable.log_pic_small)
                        .setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.log_pic))
                        .setAutoCancel(true)
                        .setContentTitle(title)
                        .setContentText(text)
                        .setStyle(new NotificationCompat.BigTextStyle().bigText(text))
                        .setTicker(text)
                        .setLights(Color.GREEN, 500, 500);
        mNotifM.cancel(0);
        mBuilder.setContentIntent(contentIntent);
        mNotifM.notify(110, mBuilder.build());
    }
}

Manifest file

<service android:name="com.parse.PushService" />

        <receiver
            android:name="com.restaurant.services.CustomPushReceiver"
            android:exported="false">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
                <action android:name="android.intent.action.USER_PRESENT" />
                <action android:name="com.parse.push.intent.RECEIVE" />
                <action android:name="com.parse.push.intent.DELETE" />
                <action android:name="com.parse.push.intent.OPEN" />
            </intent-filter>
        </receiver>
        <receiver
            android:name="com.parse.GcmBroadcastReceiver"
            android:permission="com.google.android.c2dm.permission.SEND">
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                <action android:name="com.google.android.c2dm.intent.REGISTRATION" />

                <!-- IMPORTANT: Change "info.androidhive.parsenotifications" to match your app's package name. -->
                <category android:name="com.dw" />
            </intent-filter>
        </receiver>

enter image description here

danypata

I think your problem is generated by the method super.onPushReceive(context, intent); in your public void onReceive(Context context, Intent intent).

I think you should override protected void onPushReceive(Context context,Intent intent) and handle the push notification there. NOTE: DO NOT CALL super if you override onPushReceive because it will display again the push.

As per Parse documentation:

Called when the push notification is received. By default, a broadcast intent will be sent if an "action" is present in the data and a notification will be show if "alert" and "title" are present in the data.

EDIT

public class CustomPushReceiver extends ParsePushBroadcastReceiver { ..... init code here from your exaple....

@Override
public void onReceive(Context context, Intent intent) {
  super.onReceive(Context context, Intent intent);
}
@Override
public void onPushReceive(Context context, Intent intent) {
    //NO SUPER CALL
  ....exact code from your onReceive.....
}
... rest of the code from your example...

}

I think you can handle it from here.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Custom Push Notification coming twice using Parse.com and Android

From Dev

Android, Push notification using parse.com, launches the app automatically

From Dev

Error ~ parse.com push notification android?

From Dev

Not receiving push notification on android with parse.com

From Dev

android Implement chatting through push notification using parse.com api

From Dev

error setting up push notification using parse.com and android studio

From Dev

I want to send push notification from one android device to another using my application by Parse.com.

From Dev

RuntimeException on android app with parse.com push notification

From Dev

Parse.com disable push notification notification

From Dev

sending push notification to multiple users using Parse in android

From Dev

sending push notification to multiple users using Parse in android

From Dev

Push notification with relational query with Parse.com

From Dev

Parse.com Push Notification To Friends

From Dev

Android - Show Custom Notification without default notification- Parse.com

From Dev

Android - Show Custom Notification without default notification- Parse.com

From Dev

Parse Open push notification in different Activity Android

From Dev

How to change Parse push notification icon in android?

From Dev

Parse Push notification not sending from Android to Channel

From Dev

Parse Open push notification in different Activity Android

From Dev

android push notification with parse doesen't work

From Dev

Android Parse Push Notification not working - "Outdated device"

From Dev

Push notification in Production mode is not coming But in development it is coming

From Dev

how to send push notification using phonegap and parse

From Dev

Push notification through Parse using TestFlight

From Dev

using PARSE Push notification without app id

From Dev

Send push notification to specific user using Parse

From Dev

Push notification from app using Parse Sdk

From Dev

Parse.com for sending push notification from .NET framework and receiving on iOS, Android and web page

From Dev

How to send a collapsible push notification using Parse.com's cloud code

Related Related

  1. 1

    Custom Push Notification coming twice using Parse.com and Android

  2. 2

    Android, Push notification using parse.com, launches the app automatically

  3. 3

    Error ~ parse.com push notification android?

  4. 4

    Not receiving push notification on android with parse.com

  5. 5

    android Implement chatting through push notification using parse.com api

  6. 6

    error setting up push notification using parse.com and android studio

  7. 7

    I want to send push notification from one android device to another using my application by Parse.com.

  8. 8

    RuntimeException on android app with parse.com push notification

  9. 9

    Parse.com disable push notification notification

  10. 10

    sending push notification to multiple users using Parse in android

  11. 11

    sending push notification to multiple users using Parse in android

  12. 12

    Push notification with relational query with Parse.com

  13. 13

    Parse.com Push Notification To Friends

  14. 14

    Android - Show Custom Notification without default notification- Parse.com

  15. 15

    Android - Show Custom Notification without default notification- Parse.com

  16. 16

    Parse Open push notification in different Activity Android

  17. 17

    How to change Parse push notification icon in android?

  18. 18

    Parse Push notification not sending from Android to Channel

  19. 19

    Parse Open push notification in different Activity Android

  20. 20

    android push notification with parse doesen't work

  21. 21

    Android Parse Push Notification not working - "Outdated device"

  22. 22

    Push notification in Production mode is not coming But in development it is coming

  23. 23

    how to send push notification using phonegap and parse

  24. 24

    Push notification through Parse using TestFlight

  25. 25

    using PARSE Push notification without app id

  26. 26

    Send push notification to specific user using Parse

  27. 27

    Push notification from app using Parse Sdk

  28. 28

    Parse.com for sending push notification from .NET framework and receiving on iOS, Android and web page

  29. 29

    How to send a collapsible push notification using Parse.com's cloud code

HotTag

Archive