2012-12-24 12 views
5

Voglio dire al mio servizio cosa fare quando termina l'esecuzione di un'azione. Così Voglio inviare il servizio un PendingIntent, in modo che possa avviarlo (utilizzando PendingIntent.send())Come inviare PendingIntent al mio servizio in Intento

PendingIntent pendingIntent; 
Intent newInt; 
newInt = new Intent(Intent.ACTION_SENDTO); 
newInt.setData(Uri.parse("sms:052373")); 
newInt.putExtra("sms_body", "The SMS text"); 
pendingIntent = PendingIntent.getActivity(this, 0, newInt, 0); 

Ora la domanda su come iniziare a fissare il pendingIntent al pendingIntent?

Ho provato questo per esempio:

NewIntent.putExtra("pendingIntent",pendingIntent); 
startService(NewIntent); 

Ma non funziona.

e nel servizio:

PendingIntent pendingIntent = (PendingIntent) intent.getParcelableExtra("pendingIntent"); 
pendingIntent.send(); 
+1

"ma è non funziona" è una descrizione dei sintomi inutile. – CommonsWare

+0

Grazie, la prossima volta sarò più specifico – Aminadav

risposta

10

ho successo!

vedono questo:

PendingIntent pendingIntent; 
Intent newInt; 

newInt = new Intent(Intent.ACTION_SENDTO); 
newInt.setData(Uri.parse("sms:0523737233")); 
newInt.putExtra("sms_body", "The SMS text"); 
android.util.Log.e("abc","7"); 
pendingIntent=PendingIntent.getActivity(this, 0, newInt, Intent.FLAG_ACTIVITY_NEW_TASK); 
android.util.Log.e("abc","9"); 

NewIntent.putExtra("pendingIntent",pendingIntent); 
NewIntent.putExtra("uriIntent",newInt.toUri(0)); 
startService(NewIntent); 

e nel servizio:

PendingIntent pendingIntent=(PendingIntent) intent.getParcelableExtra("pendingIntent"); 
pendingIntent.send(); 
+0

+1 per send(). Puoi accettare la tua risposta come propria:) \ –

Problemi correlati