7

アクションの実行が終了したときに何をすべきかをサービスに指示したいと考えています。だから私はサービスを送信したい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);

ここで、 を にどのように取り付け始めるかという問題がpendingIntentあります。pendingIntent

たとえば、これを試しました:

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

しかし、うまくいきません。

そしてサービスで:

PendingIntent pendingIntent = (PendingIntent) intent.getParcelableExtra("pendingIntent");
pendingIntent.send();
4

1 に答える 1

15

私は成功しました!

これを参照してください:

PendingIntent pendingIntent;
Intent ownIntent;

ownIntent = new Intent(Intent.ACTION_SENDTO);
ownIntent.setData(Uri.parse("sms:0523737233"));
ownIntent.putExtra("sms_body", "The SMS text");
Log.e("abc", "7");
pendingIntent = PendingIntent.getActivity(this, 0, ownIntent, Intent.FLAG_ACTIVITY_NEW_TASK);
Log.e("abc", "9");

ownIntent.putExtra("pendingIntent", pendingIntent);
ownIntent.putExtra("uriIntent", ownIntent.toUri(0));
startService(ownIntent);

とサービスで:

PendingIntent pendingIntent = (PendingIntent) intent.getParcelableExtra("pendingIntent");
pendingIntent.send();
于 2012-12-24T22:07:55.360 に答える