2012-12-24 19 views
5

Tôi muốn thông báo cho dịch vụ của mình những việc cần làm khi hoàn thành để thực hiện một hành động. Vì vậy, tôi muốn gửi dịch vụ một PendingIntent, vì vậy nó có thể bắt đầu nó (bằng cách sử dụng PendingIntent.send())Cách gửi PendingIntent đến dịch vụ của tôi bên trong 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); 

Bây giờ câu hỏi làm thế nào để bắt đầu để gắn pendingIntent đến pendingIntent?

Tôi cố gắng này ví dụ:

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

Nhưng nó không hoạt động.

Và trong dịch vụ:

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

"Nhưng đó là không làm việc" là một mô tả vô dụng của các triệu chứng của bạn. – CommonsWare

+0

Cảm ơn bạn, lần sau tôi sẽ cụ thể hơn – Aminadav

Trả lời

10

tôi thành công!

thấy điều này:

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

và trong dịch vụ:

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

+1 cho gửi(). Bạn có thể chấp nhận câu trả lời của riêng bạn:) \ –

Các vấn đề liên quan