2012-12-24 4 views
5

조치를 수행하기 위해 끝내면 내 서비스에 알려야합니다. 그래서 나는 서비스 및 A PendingIntent를 보내려면, 그래서Intent 내 서비스에 PendingIntent를 보내는 방법

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에 첨부하기 시작 (PendingIntent.send()를 사용하여)을 시작할 수 있나요?

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

을하지만 그것은 작동하지 않습니다

내가 예를 들어이 시도.

그리고 서비스

:

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

을 "하지만이 작동하지 않습니다는"증상의 쓸모없는 설명입니다. – CommonsWare

+0

감사합니다. 다음 번에는 send()에 대해 – Aminadav

답변

10

I 성공!

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을 사용합니다. 당신은 자신의 답을 받아 들일 수 있습니다 :) \ –

관련 문제