2012-12-24 13 views
5

के अंदर मेरी सेवा में लंबित इंंटेंट कैसे भेजें I अपनी सेवा बताना चाहता हूं कि यह कार्रवाई करने के बाद क्या करना है। तो मैं सेवा एक PendingIntent भेजना चाहते हैं, तो यह इसे शुरू कर सकते हैं (PendingIntent.send() का उपयोग करके)इरादे

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

अब सवाल यह है कि pendingIntentpendingIntent को संलग्न करने के लिए शुरू करने के लिए?

मैं उदाहरण के लिए इस की कोशिश की:

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

लेकिन यह काम नहीं करता।

और सेवा में:

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

"लेकिन यह काम नहीं करता है" अपने लक्षणों की एक बेकार वर्णन है। – CommonsWare

+0

धन्यवाद, अगली बार मैं भेजने के लिए अधिक विशिष्ट – Aminadav

उत्तर

10

मैं सफलता!

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

और सेवा में:

यह देखने

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

+1 होगा()। आप अपना उत्तर स्वयं के रूप में स्वीकार कर सकते हैं:) \ –

संबंधित मुद्दे