2012-12-24 1 views
5

Je veux dire à mon service quoi faire quand il a fini d'effectuer une action. Je veux envoyer le service un PendingIntent, il peut commencer (en utilisant PendingIntent.send())Comment envoyer PendingIntent à mon service à l'intérieur Intent

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); 

Maintenant, la question de savoir comment commencer à fixer le pendingIntent au pendingIntent?

J'ai essayé par exemple:

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

Mais il ne fonctionne pas.

Et dans le service:

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

"Mais il est ne fonctionne pas" est une description inutile de vos symptômes. – CommonsWare

+0

Merci, la prochaine fois je serai plus précis – Aminadav

Répondre

10

I succès!

voir ceci:

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); 

et au service:

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

+1 pour send(). Vous pouvez accepter votre réponse comme propre:) \ –

Questions connexes