Cómo anular onPushReceive () de ParsePushBroadcastReceiver?

Estoy utilizando el servicio de notificación push de Parse.com. Según el doc :

Anula onPushReceive para activar una operación de fondo para empujes "silenciosos"

He encontrado el código fuente de onPushOpen () aquí , pero ahora tengo que sobrescribir onPushReceive () para personalizar el comportamiento del sonido y la vibración. No sé qué debo hacer en onPushReceive (), ¿hay algún código de ejemplo que me ayude a averiguar la lógica dentro onPushReceive ()? Gracias.

Crear una nueva clase que extiende ParsePushBroadcastReceiver:

public class MyPushBroadcastReceiver extends ParsePushBroadcastReceiver { public static final String PARSE_DATA_KEY = "com.parse.Data"; @Override protected Notification getNotification(Context context, Intent intent) { // deactivate standard notification return null; } @Override protected void onPushOpen(Context context, Intent intent) { // Implement } @Override protected void onPushReceive(Context context, Intent intent) { JSONObject data = getDataFromIntent(intent); // Do something with the data. To create a notification do: NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); NotificationCompat.Builder builder = new NotificationCompat.Builder(context); builder.setContentTitle("Title"); builder.setContentText("Text"); builder.setSmallIcon(R.drawable.ic_notification); builder.setAutoCancel(true); // OPTIONAL create soundUri and set sound: builder.setSound(soundUri); notificationManager.notify("MyTag", 0, builder.build()); } private JSONObject getDataFromIntent(Intent intent) { JSONObject data = null; try { data = new JSONObject(intent.getExtras().getString(PARSE_DATA_KEY)); } catch (JSONException e) { // Json was not readable... } return data; } } 

Añadir esto en su Manifiesto:

  <receiver android:name=".MyPushBroadcastReceiver" android:exported="false"> <intent-filter> <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> 

Más información: http://www.androidhive.info/2015/06/android-push-notifications-using-parse-com/

Puede usar el parámetro extra "acción" para llamar a su intención de manejar lo que quiera.

Original onPushReceive fuente:

 protected void onPushReceive(Context context, Intent intent) { JSONObject pushData = null; try { pushData = new JSONObject(intent.getStringExtra("com.parse.Data")); } catch (JSONException var7) { Parse.logE("com.parse.ParsePushReceiver", "Unexpected JSONException when receiving push data: ", var7); } String action = null; if(pushData != null) { action = pushData.optString("action", (String)null); } if(action != null) { Bundle notification = intent.getExtras(); Intent broadcastIntent = new Intent(); broadcastIntent.putExtras(notification); broadcastIntent.setAction(action); broadcastIntent.setPackage(context.getPackageName()); context.sendBroadcast(broadcastIntent); } Notification notification1 = this.getNotification(context, intent); if(notification1 != null) { ParseNotificationManager.getInstance().showNotification(context, notification1); } } 

Y no hay notificación si no hay "alerta" o "título" extra en la intención.

Así que no necesitas extender ninguna clase en absoluto para las actualizaciones de empuje silenciosas …

  • Notificaciones push / C2DM para Kindle Fire?
  • El servicio de Intención de GCM OnRegistered no se recibe
  • Cómo enviar notificación push en dos segmentos en momentos diferentes en un día en analizar
  • La notificación del constructor está obsoleta
  • No se puede resolver el símbolo 'GoogleCloudMessaging' GCM
  • Cómo evitar el retraso en los mensajes de GCM de Android / cambio de latidos del corazón
  • Instalar jar con dependencias para el repositorio maven (Android gcm-server push library)
  • ¿Hay algún servicio de notificación push en Android como Apple Push Notification Service?
  • ¿Cómo mostrar la imagen en notificación push (Gcm) android?
  • Error de GCM - googleCloudMessaging.register
  • Ningún receptor de intenciones estableció AirShip Urbano
  • FlipAndroid es un fan de Google para Android, Todo sobre Android Phones, Android Wear, Android Dev y Aplicaciones para Android Aplicaciones.