2012-06-14 8 views

Respuesta

4

me dieron esto desde http://justanapplication.wordpress.com/tag/pendingintent-getbroadcast:

Si el argumento no es nulo onFinished continuación, se realiza una emisión ordenada.

Por lo tanto, puede intentar llamar al PendingIntent.send con el conjunto de argumentos onFinished.

Sin embargo, me encontré con el problema que tuve que enviar un OrderedBroadcast de una notificación. Funcioné creando un BroadcastReceiver que simplemente reenvía el Intento como un Broadcast Ordenado. Realmente no sé si esta es una buena solución.

así que empecé a cabo mediante la creación de un Intento que tiene el nombre de la acción que transmita a como extra:

// the name of the action of our OrderedBroadcast forwarder 
Intent intent = new Intent("com.youapp.FORWARD_AS_ORDERED_BROADCAST"); 
// the name of the action to send the OrderedBroadcast to 
intent.putExtra(OrderedBroadcastForwarder.ACTION_NAME, "com.youapp.SOME_ACTION"); 
intent.putExtra("some_extra", "123"); 
// etc. 

En mi caso pasé el PendingIntent a una Notificación:

PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, intent, 0); 
Notification notification = new NotificationCompat.Builder(context) 
     .setContentTitle("Notification title") 
     .setContentText("Notification content") 
     .setSmallIcon(R.drawable.notification_icon) 
     .setContentIntent(pendingIntent) 
     .build(); 
NotificationManager notificationManager = (NotificationManager)context 
    .getSystemService(Context.NOTIFICATION_SERVICE); 
notificationManager.notify((int)System.nanoTime(), notification); 

Entonces definieron los siguientes receptores en mi Manifiesto:

<receiver 
    android:name="com.youapp.OrderedBroadcastForwarder" 
    android:exported="false"> 
    <intent-filter> 
     <action android:name="com.youapp.FORWARD_AS_ORDERED_BROADCAST" /> 
    </intent-filter> 
</receiver> 
<receiver 
    android:name="com.youapp.PushNotificationClickReceiver" 
    android:exported="false"> 
    <intent-filter android:priority="1"> 
     <action android:name="com.youapp.SOME_ACTION" /> 
    </intent-filter> 
</receiver> 

Entonces el OrderedBro adcastForwarder se ve de la siguiente manera:

public class OrderedBroadcastForwarder extends BroadcastReceiver 
{ 
    public static final String ACTION_NAME = "action"; 

    @Override 
    public void onReceive(Context context, Intent intent) 
    { 
     Intent forwardIntent = new Intent(intent.getStringExtra(ACTION_NAME)); 
     forwardIntent.putExtras(intent); 
     forwardIntent.removeExtra(ACTION_NAME); 

     context.sendOrderedBroadcast(forwardIntent, null); 
    } 
} 
Cuestiones relacionadas