2012-12-24 3 views
5

アクションを実行するために終了したら何をすべきかを私のサービスに伝えたいと思います。 は、だから私はサービス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

ありがとうございます、次回は具体的になります – 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 send()。自分の答えを受け入れることができます:)\ –

関連する問題