I have implemented Parse push notifications but there is an issue on the Android side for me. Whenever I send a notification from Parse, all Android devices receive two notifications, one with the text that I have sent and the other with empty text.
Please suggest what might be wrong here
Note : I have also added native Android notifications (GCM notifications) to my project. Is it possible that they are causing this issue?
Thanks.
The AndroidManifest is setup as follows:
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="com.android.vending.BILLING" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<application
android:name=".activityApplication"
android:label="@string/app_name"
android:icon="@drawable/icon">
<activity android:name=".activity"
android:label="@string/app_name"
android:screenOrientation="landscape"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen"
android:configChanges="orientation">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"/>
<!-- gcm -->
<receiver
android:name="com.company.activity.GCBroadcastReceiver"
android:exported="true"
android:process=":remote"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="com.company.activity" />
</intent-filter>
</receiver>
<service android:name=".GcmIntentService" />
<service android:name="com.parse.PushService" />
<receiver android:name="com.parse.ParseBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.USER_PRESENT" />
</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" />
<category android:name="com.company.activity" />
</intent-filter>
</receiver>
</application>
And this is my Broadcast Receiver :
public class GCBroadcastReceiver extends BroadcastReceiver
{
private static final String TAG = "GCBroadcastReceiver";
Context ctx;
@Override
public void onReceive(Context context, Intent intent)
{
ctx = context;
// Local notification.
Bundle bundle = intent.getExtras();
String message = bundle.getString("message");
String notificationID = bundle.getString("notificationID");
Log.v(TAG,"Notification message : " + message + "With ID : " + notificationID);
sendNotification(message, notificationID);
}
// Put the GCM message into a notification and post it.
private void sendNotification(final String message, final String notificationID)
{
Intent notificationIntent = new Intent(ctx, Activity.class);
PendingIntent intent = PendingIntent.getActivity(ctx, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(ctx);
mBuilder.setContentIntent(intent);
mBuilder.setStyle(new NotificationCompat.BigTextStyle().bigText(message));
mBuilder.setWhen(System.currentTimeMillis());
mBuilder.setSmallIcon(R.drawable.icon);
mBuilder.setContentTitle(ctx.getString(R.string.app_name));
mBuilder.setContentText(message);
mBuilder.setLights(Color.RED, 400, 400);
mBuilder.setAutoCancel(true);
//mBuilder.setSound(Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + ctx.getPackageName() + "/raw/" + sound));
mBuilder.setDefaults(Notification.DEFAULT_LIGHTS | Notification.DEFAULT_VIBRATE);
NotificationManager mNotificationManager = (NotificationManager) ctx
.getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(0, mBuilder.build());
}
}