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"
- Notificación push de C2DM sin MQTT, UA en android api level <8
- GCM Cloud Connection Server - cómo empezar a usarlo?
- Animación en la barra de notificaciones Vista personalizada
- Las notificaciones de inserción de Parse.com no funcionan de forma consistente recibiendo el error "GCM -MISMATCH SENDER ID"
- Problema de registro del dispositivo Gcm en android
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.
- Cómo utilizar con eficacia XMPP persistente con android
- Implementación de GCM con PHP siempre enfrentando error no autorizado 401
- ¿Es gratuito Firebase Cloud Messaging?
- ¿Podemos usar VectorDrawable o VectorXML como iconos para notificaciones push en android?
- Mensajes de Android - Desarrollo vs distribución
- No recibe la notificación de push de GCM de Amazon SNS
- Cómo recuperar ID de registro y enviar un mensaje a una aplicación de terceros en android c2dm0 +
- Notificaciones de usuarios - ¿Cómo recuperar un notification_id perdido de GCM?
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 …
- ¿Cómo puedo bloquear el diseño de mi programa Android a una orientación
- Actualizaciones de datos de Android ListView ArrayAdapter Mejores prácticas